@langfuse/client 4.1.0-alpha.0 → 4.1.0-alpha.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/dist/index.cjs CHANGED
@@ -39,7 +39,7 @@ __export(index_exports, {
39
39
  PromptManager: () => PromptManager,
40
40
  ScoreManager: () => ScoreManager,
41
41
  TextPromptClient: () => TextPromptClient,
42
- autoevalsToLangfuseEvaluator: () => autoevalsToLangfuseEvaluator
42
+ createEvaluatorFromAutoevals: () => createEvaluatorFromAutoevals
43
43
  });
44
44
  module.exports = __toCommonJS(index_exports);
45
45
 
@@ -302,19 +302,31 @@ var ExperimentManager = class {
302
302
  const itemResults = [];
303
303
  for (let i = 0; i < data.length; i += batchSize) {
304
304
  const batch = data.slice(i, i + batchSize);
305
- const promises = batch.map(
306
- async (item) => {
307
- return this.runItem({
308
- item,
309
- evaluators,
310
- task,
311
- experimentName: name,
312
- experimentDescription: description,
313
- experimentMetadata: metadata
314
- });
315
- }
305
+ const promises = batch.map(async (item) => {
306
+ return this.runItem({
307
+ item,
308
+ evaluators,
309
+ task,
310
+ experimentName: name,
311
+ experimentDescription: description,
312
+ experimentMetadata: metadata
313
+ });
314
+ });
315
+ const settledResults = await Promise.allSettled(promises);
316
+ const results = settledResults.reduce(
317
+ (acc, settledResult) => {
318
+ if (settledResult.status === "fulfilled") {
319
+ acc.push(settledResult.value);
320
+ } else {
321
+ const errorMessage = settledResult.reason instanceof Error ? settledResult.reason.message : String(settledResult.reason);
322
+ this.logger.error(
323
+ `Task failed with error: ${errorMessage}. Skipping item.`
324
+ );
325
+ }
326
+ return acc;
327
+ },
328
+ []
316
329
  );
317
- const results = await Promise.all(promises);
318
330
  itemResults.push(...results);
319
331
  }
320
332
  const datasetRunId = itemResults.length > 0 ? itemResults[0].datasetRunId : void 0;
@@ -355,6 +367,7 @@ var ExperimentManager = class {
355
367
  return {
356
368
  itemResults,
357
369
  datasetRunId,
370
+ datasetRunUrl,
358
371
  runEvaluations,
359
372
  prettyPrint: async (options) => {
360
373
  var _a;
@@ -365,7 +378,7 @@ var ExperimentManager = class {
365
378
  runEvaluations,
366
379
  name: config.name,
367
380
  description: config.description,
368
- includeItemResults: (_a = options == null ? void 0 : options.includeItemResults) != null ? _a : true
381
+ includeItemResults: (_a = options == null ? void 0 : options.includeItemResults) != null ? _a : false
369
382
  });
370
383
  }
371
384
  };
@@ -395,14 +408,24 @@ var ExperimentManager = class {
395
408
  * @internal
396
409
  */
397
410
  async runItem(params) {
398
- const { item, evaluators = [], task } = params;
411
+ const { item, evaluators = [], task, experimentMetadata = {} } = params;
399
412
  const { output, traceId } = await (0, import_tracing.startActiveObservation)(
400
413
  "experiment-item-run",
401
414
  async (span) => {
415
+ var _a;
402
416
  const output2 = await task(item);
403
417
  span.update({
404
418
  input: item.input,
405
- output: output2
419
+ output: output2,
420
+ metadata: {
421
+ experimentName: params.experimentName,
422
+ ...experimentMetadata,
423
+ ...(_a = item.metadata) != null ? _a : {},
424
+ ..."id" in item && "datasetId" in item ? {
425
+ dataset_id: item["datasetId"],
426
+ dataset_item_id: item["id"]
427
+ } : {}
428
+ }
406
429
  });
407
430
  return { output: output2, traceId: span.traceId };
408
431
  }
@@ -465,7 +488,8 @@ ${JSON.stringify(params2)}
465
488
  output,
466
489
  evaluations: evals,
467
490
  traceId,
468
- datasetRunId
491
+ datasetRunId,
492
+ item
469
493
  };
470
494
  }
471
495
  /**
@@ -486,7 +510,7 @@ ${JSON.stringify(params2)}
486
510
  * @param params.runEvaluations - Results from run-level evaluators
487
511
  * @param params.name - Name of the experiment
488
512
  * @param params.description - Optional description of the experiment
489
- * @param params.includeItemResults - Whether to include individual item details (default: true)
513
+ * @param params.includeItemResults - Whether to include individual item details (default: false)
490
514
  *
491
515
  * @returns Promise resolving to formatted string representation
492
516
  *
@@ -536,7 +560,7 @@ ${JSON.stringify(params2)}
536
560
  runEvaluations,
537
561
  name,
538
562
  description,
539
- includeItemResults = true
563
+ includeItemResults = false
540
564
  } = params;
541
565
  if (itemResults.length === 0) {
542
566
  return "No experiment results to display.";
@@ -1870,7 +1894,7 @@ var LangfuseClient = class {
1870
1894
  };
1871
1895
 
1872
1896
  // src/experiment/adapters.ts
1873
- function autoevalsToLangfuseEvaluator(autoevalEvaluator, params) {
1897
+ function createEvaluatorFromAutoevals(autoevalEvaluator, params) {
1874
1898
  const langfuseEvaluator = async (langfuseEvaluatorParams) => {
1875
1899
  var _a;
1876
1900
  const score = await autoevalEvaluator({
@@ -1898,6 +1922,6 @@ function autoevalsToLangfuseEvaluator(autoevalEvaluator, params) {
1898
1922
  PromptManager,
1899
1923
  ScoreManager,
1900
1924
  TextPromptClient,
1901
- autoevalsToLangfuseEvaluator
1925
+ createEvaluatorFromAutoevals
1902
1926
  });
1903
1927
  //# sourceMappingURL=index.cjs.map