braintrust 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dev/dist/index.js CHANGED
@@ -6677,6 +6677,8 @@ var evalBodySchema = _zod.z.object({
6677
6677
  name: _zod.z.string()
6678
6678
  })
6679
6679
  ).nullish(),
6680
+ experiment_name: _zod.z.string().nullish(),
6681
+ project_id: _zod.z.string().nullish(),
6680
6682
  parent: _typespecs.invokeParent.optional(),
6681
6683
  stream: _zod.z.boolean().optional()
6682
6684
  });
@@ -6759,7 +6761,16 @@ function runDevServer(evaluators, opts) {
6759
6761
  "/eval",
6760
6762
  checkAuthorized,
6761
6763
  asyncHandler(async (req, res) => {
6762
- const { name, parameters, parent, data, scores, stream } = evalBodySchema.parse(req.body);
6764
+ const {
6765
+ name,
6766
+ parameters,
6767
+ parent,
6768
+ experiment_name,
6769
+ project_id,
6770
+ data,
6771
+ scores,
6772
+ stream
6773
+ } = evalBodySchema.parse(req.body);
6763
6774
  const state = await cachedLogin({ apiKey: _optionalChain([req, 'access', _88 => _88.ctx, 'optionalAccess', _89 => _89.token]) });
6764
6775
  const evaluator = allEvaluators[name];
6765
6776
  if (!evaluator) {
@@ -6818,17 +6829,19 @@ function runDevServer(evaluators, opts) {
6818
6829
  )]), () => ( []))
6819
6830
  ),
6820
6831
  task,
6821
- state
6832
+ state,
6833
+ experimentName: _nullishCoalesce(experiment_name, () => ( void 0)),
6834
+ projectId: _nullishCoalesce(project_id, () => ( void 0))
6822
6835
  },
6823
6836
  {
6824
6837
  // Avoid printing the bar to the console.
6825
6838
  progress: {
6826
- start: (name2, total) => {
6839
+ start: () => {
6827
6840
  },
6828
6841
  stop: () => {
6829
6842
  console.log("Finished running experiment");
6830
6843
  },
6831
- increment: (name2) => {
6844
+ increment: () => {
6832
6845
  }
6833
6846
  },
6834
6847
  stream: (data2) => {
@@ -6677,6 +6677,8 @@ var evalBodySchema = z6.object({
6677
6677
  name: z6.string()
6678
6678
  })
6679
6679
  ).nullish(),
6680
+ experiment_name: z6.string().nullish(),
6681
+ project_id: z6.string().nullish(),
6680
6682
  parent: invokeParent.optional(),
6681
6683
  stream: z6.boolean().optional()
6682
6684
  });
@@ -6759,7 +6761,16 @@ function runDevServer(evaluators, opts) {
6759
6761
  "/eval",
6760
6762
  checkAuthorized,
6761
6763
  asyncHandler(async (req, res) => {
6762
- const { name, parameters, parent, data, scores, stream } = evalBodySchema.parse(req.body);
6764
+ const {
6765
+ name,
6766
+ parameters,
6767
+ parent,
6768
+ experiment_name,
6769
+ project_id,
6770
+ data,
6771
+ scores,
6772
+ stream
6773
+ } = evalBodySchema.parse(req.body);
6763
6774
  const state = await cachedLogin({ apiKey: req.ctx?.token });
6764
6775
  const evaluator = allEvaluators[name];
6765
6776
  if (!evaluator) {
@@ -6818,17 +6829,19 @@ function runDevServer(evaluators, opts) {
6818
6829
  ) ?? []
6819
6830
  ),
6820
6831
  task,
6821
- state
6832
+ state,
6833
+ experimentName: experiment_name ?? void 0,
6834
+ projectId: project_id ?? void 0
6822
6835
  },
6823
6836
  {
6824
6837
  // Avoid printing the bar to the console.
6825
6838
  progress: {
6826
- start: (name2, total) => {
6839
+ start: () => {
6827
6840
  },
6828
6841
  stop: () => {
6829
6842
  console.log("Finished running experiment");
6830
6843
  },
6831
- increment: (name2) => {
6844
+ increment: () => {
6832
6845
  }
6833
6846
  },
6834
6847
  stream: (data2) => {
@@ -1155,6 +1155,29 @@ declare function logError(span: Span, error: unknown): void;
1155
1155
  * See {@link Span.traced} for full details.
1156
1156
  */
1157
1157
  declare function traced<IsAsyncFlush extends boolean = true, R = void>(callback: (span: Span) => R, args?: StartSpanArgs & SetCurrentArg & AsyncFlushArg<IsAsyncFlush> & OptionalStateArg): PromiseUnless<IsAsyncFlush, R>;
1158
+ /**
1159
+ * Check if a function is a sync generator function.
1160
+ *
1161
+ * Note: This uses Object.prototype.toString which is sufficient for environments that
1162
+ * support generator functions (ES6+). While our code is compiled to ES2022, consumers
1163
+ * may run it in various environments. However, if generators aren't supported in their
1164
+ * environment, the generator functions themselves won't work anyway, making detection moot.
1165
+ *
1166
+ * @param fn The function to check.
1167
+ * @returns True if the function is a sync generator function.
1168
+ */
1169
+ declare function isGeneratorFunction(fn: any): boolean;
1170
+ /**
1171
+ * Check if a function is an async generator function.
1172
+ *
1173
+ * Note: see isGeneratorFunction disclaimer
1174
+ * @param fn The function to check.
1175
+ * @returns True if the function is an async generator function.
1176
+ */
1177
+ declare function isAsyncGeneratorFunction(fn: any): boolean;
1178
+ type WrapTracedArgs = {
1179
+ noTraceIO?: boolean;
1180
+ };
1158
1181
  /**
1159
1182
  * Wrap a function with `traced`, using the arguments as `input` and return value as `output`.
1160
1183
  * Any functions wrapped this way will automatically be traced, similar to the `@traced` decorator
@@ -1180,7 +1203,7 @@ declare function traced<IsAsyncFlush extends boolean = true, R = void>(callback:
1180
1203
  * @param args Span-level arguments (e.g. a custom name or type) to pass to `traced`.
1181
1204
  * @returns The wrapped function.
1182
1205
  */
1183
- declare function wrapTraced<F extends (...args: any[]) => any, IsAsyncFlush extends boolean = true>(fn: F, args?: StartSpanArgs & SetCurrentArg & AsyncFlushArg<IsAsyncFlush>): IsAsyncFlush extends false ? (...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>> : F;
1206
+ declare function wrapTraced<F extends (...args: any[]) => any, IsAsyncFlush extends boolean = true>(fn: F, args?: StartSpanArgs & SetCurrentArg & AsyncFlushArg<IsAsyncFlush> & WrapTracedArgs): IsAsyncFlush extends false ? (...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>> : F;
1184
1207
  /**
1185
1208
  * A synonym for `wrapTraced`. If you're porting from systems that use `traceable`, you can use this to
1186
1209
  * make your codebase more consistent.
@@ -1690,6 +1713,7 @@ interface DatasetSummary {
1690
1713
  datasetUrl: string;
1691
1714
  dataSummary: DataSummary | undefined;
1692
1715
  }
1716
+ declare function setInitialTestState(): void;
1693
1717
  declare function simulateLoginForTests(): Promise<BraintrustState>;
1694
1718
  declare function simulateLogoutForTests(): BraintrustState;
1695
1719
  declare const _exportsForTestingOnly: {
@@ -1699,6 +1723,9 @@ declare const _exportsForTestingOnly: {
1699
1723
  clearTestBackgroundLogger: typeof clearTestBackgroundLogger;
1700
1724
  simulateLoginForTests: typeof simulateLoginForTests;
1701
1725
  simulateLogoutForTests: typeof simulateLogoutForTests;
1726
+ setInitialTestState: typeof setInitialTestState;
1727
+ isGeneratorFunction: typeof isGeneratorFunction;
1728
+ isAsyncGeneratorFunction: typeof isAsyncGeneratorFunction;
1702
1729
  };
1703
1730
 
1704
1731
  declare const braintrustStreamChunkSchema: z.ZodUnion<[z.ZodObject<{
@@ -2109,7 +2136,7 @@ declare global {
2109
2136
  * not configured, nothing will be traced. If this is not an `OpenAI` object, this function is
2110
2137
  * a no-op.
2111
2138
  *
2112
- * Currently, this only supports the `v4` API.
2139
+ * Currently, this supports both the `v4` and `v5` API.
2113
2140
  *
2114
2141
  * @param openai
2115
2142
  * @returns The wrapped `OpenAI` object.
package/dist/browser.d.ts CHANGED
@@ -1155,6 +1155,29 @@ declare function logError(span: Span, error: unknown): void;
1155
1155
  * See {@link Span.traced} for full details.
1156
1156
  */
1157
1157
  declare function traced<IsAsyncFlush extends boolean = true, R = void>(callback: (span: Span) => R, args?: StartSpanArgs & SetCurrentArg & AsyncFlushArg<IsAsyncFlush> & OptionalStateArg): PromiseUnless<IsAsyncFlush, R>;
1158
+ /**
1159
+ * Check if a function is a sync generator function.
1160
+ *
1161
+ * Note: This uses Object.prototype.toString which is sufficient for environments that
1162
+ * support generator functions (ES6+). While our code is compiled to ES2022, consumers
1163
+ * may run it in various environments. However, if generators aren't supported in their
1164
+ * environment, the generator functions themselves won't work anyway, making detection moot.
1165
+ *
1166
+ * @param fn The function to check.
1167
+ * @returns True if the function is a sync generator function.
1168
+ */
1169
+ declare function isGeneratorFunction(fn: any): boolean;
1170
+ /**
1171
+ * Check if a function is an async generator function.
1172
+ *
1173
+ * Note: see isGeneratorFunction disclaimer
1174
+ * @param fn The function to check.
1175
+ * @returns True if the function is an async generator function.
1176
+ */
1177
+ declare function isAsyncGeneratorFunction(fn: any): boolean;
1178
+ type WrapTracedArgs = {
1179
+ noTraceIO?: boolean;
1180
+ };
1158
1181
  /**
1159
1182
  * Wrap a function with `traced`, using the arguments as `input` and return value as `output`.
1160
1183
  * Any functions wrapped this way will automatically be traced, similar to the `@traced` decorator
@@ -1180,7 +1203,7 @@ declare function traced<IsAsyncFlush extends boolean = true, R = void>(callback:
1180
1203
  * @param args Span-level arguments (e.g. a custom name or type) to pass to `traced`.
1181
1204
  * @returns The wrapped function.
1182
1205
  */
1183
- declare function wrapTraced<F extends (...args: any[]) => any, IsAsyncFlush extends boolean = true>(fn: F, args?: StartSpanArgs & SetCurrentArg & AsyncFlushArg<IsAsyncFlush>): IsAsyncFlush extends false ? (...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>> : F;
1206
+ declare function wrapTraced<F extends (...args: any[]) => any, IsAsyncFlush extends boolean = true>(fn: F, args?: StartSpanArgs & SetCurrentArg & AsyncFlushArg<IsAsyncFlush> & WrapTracedArgs): IsAsyncFlush extends false ? (...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>> : F;
1184
1207
  /**
1185
1208
  * A synonym for `wrapTraced`. If you're porting from systems that use `traceable`, you can use this to
1186
1209
  * make your codebase more consistent.
@@ -1690,6 +1713,7 @@ interface DatasetSummary {
1690
1713
  datasetUrl: string;
1691
1714
  dataSummary: DataSummary | undefined;
1692
1715
  }
1716
+ declare function setInitialTestState(): void;
1693
1717
  declare function simulateLoginForTests(): Promise<BraintrustState>;
1694
1718
  declare function simulateLogoutForTests(): BraintrustState;
1695
1719
  declare const _exportsForTestingOnly: {
@@ -1699,6 +1723,9 @@ declare const _exportsForTestingOnly: {
1699
1723
  clearTestBackgroundLogger: typeof clearTestBackgroundLogger;
1700
1724
  simulateLoginForTests: typeof simulateLoginForTests;
1701
1725
  simulateLogoutForTests: typeof simulateLogoutForTests;
1726
+ setInitialTestState: typeof setInitialTestState;
1727
+ isGeneratorFunction: typeof isGeneratorFunction;
1728
+ isAsyncGeneratorFunction: typeof isAsyncGeneratorFunction;
1702
1729
  };
1703
1730
 
1704
1731
  declare const braintrustStreamChunkSchema: z.ZodUnion<[z.ZodObject<{
@@ -2109,7 +2136,7 @@ declare global {
2109
2136
  * not configured, nothing will be traced. If this is not an `OpenAI` object, this function is
2110
2137
  * a no-op.
2111
2138
  *
2112
- * Currently, this only supports the `v4` API.
2139
+ * Currently, this supports both the `v4` and `v5` API.
2113
2140
  *
2114
2141
  * @param openai
2115
2142
  * @returns The wrapped `OpenAI` object.