langsmith 0.4.11 → 0.5.0-rc.0
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/client.cjs +24 -26
- package/dist/client.d.ts +12 -4
- package/dist/client.js +10 -12
- package/dist/evaluation/evaluate_comparative.cjs +5 -0
- package/dist/evaluation/evaluate_comparative.js +5 -0
- package/dist/experimental/sandbox/client.cjs +639 -0
- package/dist/experimental/sandbox/client.d.ts +240 -0
- package/dist/experimental/sandbox/client.js +635 -0
- package/dist/experimental/sandbox/errors.cjs +306 -0
- package/dist/experimental/sandbox/errors.d.ts +134 -0
- package/dist/experimental/sandbox/errors.js +288 -0
- package/dist/experimental/sandbox/helpers.cjs +315 -0
- package/dist/experimental/sandbox/helpers.d.ts +90 -0
- package/dist/experimental/sandbox/helpers.js +303 -0
- package/dist/experimental/sandbox/index.cjs +56 -0
- package/dist/experimental/sandbox/index.d.ts +28 -0
- package/dist/experimental/sandbox/index.js +40 -0
- package/dist/experimental/sandbox/sandbox.cjs +233 -0
- package/dist/experimental/sandbox/sandbox.d.ts +113 -0
- package/dist/experimental/sandbox/sandbox.js +229 -0
- package/dist/experimental/sandbox/types.cjs +7 -0
- package/dist/experimental/sandbox/types.d.ts +230 -0
- package/dist/experimental/sandbox/types.js +6 -0
- package/dist/index.cjs +5 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/run_trees.cjs +7 -6
- package/dist/run_trees.js +8 -7
- package/dist/schemas.d.ts +1 -0
- package/dist/utils/_uuid.cjs +113 -0
- package/dist/utils/_uuid.d.ts +26 -0
- package/dist/utils/_uuid.js +112 -0
- package/dist/utils/{prompts_cache.cjs → prompt_cache/index.cjs} +52 -22
- package/dist/utils/{prompts_cache.d.ts → prompt_cache/index.d.ts} +19 -3
- package/dist/utils/{prompts_cache.js → prompt_cache/index.js} +47 -18
- package/dist/utils/xxhash/xxhash.cjs +331 -0
- package/dist/utils/xxhash/xxhash.d.ts +15 -0
- package/dist/utils/xxhash/xxhash.js +327 -0
- package/dist/wrappers/anthropic.cjs +17 -4
- package/dist/wrappers/anthropic.js +17 -4
- package/dist/wrappers/gemini.cjs +16 -5
- package/dist/wrappers/gemini.js +16 -5
- package/dist/wrappers/openai.cjs +27 -12
- package/dist/wrappers/openai.js +27 -12
- package/experimental/sandbox.cjs +1 -0
- package/experimental/sandbox.d.cts +1 -0
- package/experimental/sandbox.d.ts +1 -0
- package/experimental/sandbox.js +1 -0
- package/package.json +17 -3
- /package/dist/utils/{prompts_cache_fs.browser.cjs → prompt_cache/fs.browser.cjs} +0 -0
- /package/dist/utils/{prompts_cache_fs.browser.d.ts → prompt_cache/fs.browser.d.ts} +0 -0
- /package/dist/utils/{prompts_cache_fs.browser.js → prompt_cache/fs.browser.js} +0 -0
- /package/dist/utils/{prompts_cache_fs.cjs → prompt_cache/fs.cjs} +0 -0
- /package/dist/utils/{prompts_cache_fs.d.ts → prompt_cache/fs.d.ts} +0 -0
- /package/dist/utils/{prompts_cache_fs.js → prompt_cache/fs.js} +0 -0
package/dist/client.cjs
CHANGED
|
@@ -46,9 +46,9 @@ const _uuid_js_1 = require("./utils/_uuid.cjs");
|
|
|
46
46
|
const warn_js_1 = require("./utils/warn.cjs");
|
|
47
47
|
const prompts_js_1 = require("./utils/prompts.cjs");
|
|
48
48
|
const error_js_1 = require("./utils/error.cjs");
|
|
49
|
-
const
|
|
49
|
+
const index_js_2 = require("./utils/prompt_cache/index.cjs");
|
|
50
50
|
const fetch_js_1 = require("./singletons/fetch.cjs");
|
|
51
|
-
const
|
|
51
|
+
const index_js_3 = require("./utils/fast-safe-stringify/index.cjs");
|
|
52
52
|
function mergeRuntimeEnvIntoRun(run, cachedEnvVars, omitTracedRuntimeInfo) {
|
|
53
53
|
if (omitTracedRuntimeInfo) {
|
|
54
54
|
return run;
|
|
@@ -168,7 +168,7 @@ class AutoBatchQueue {
|
|
|
168
168
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise
|
|
169
169
|
itemPromiseResolve = resolve;
|
|
170
170
|
});
|
|
171
|
-
const size = (0,
|
|
171
|
+
const size = (0, index_js_3.serialize)(item.item, `Serializing run with id: ${item.item.id}`).length;
|
|
172
172
|
// Check if adding this item would exceed the size limit
|
|
173
173
|
// Allow the run if the queue is empty (to support large single traces)
|
|
174
174
|
if (this.sizeBytes + size > this.maxSizeBytes && this.items.length > 0) {
|
|
@@ -494,15 +494,10 @@ class Client {
|
|
|
494
494
|
}
|
|
495
495
|
// Cache metadata env vars once during construction to avoid repeatedly scanning process.env
|
|
496
496
|
this.cachedLSEnvVarsForMetadata = (0, env_js_1.getLangSmithEnvVarsMetadata)();
|
|
497
|
-
// Initialize cache
|
|
498
|
-
if (config.
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
else if (config.cache && typeof config.cache === "object") {
|
|
502
|
-
this._cache = config.cache;
|
|
503
|
-
}
|
|
504
|
-
else {
|
|
505
|
-
this._cache = undefined;
|
|
497
|
+
// Initialize prompt cache
|
|
498
|
+
if (!config.disablePromptCache) {
|
|
499
|
+
// Use the global singleton instance
|
|
500
|
+
this._cache = index_js_2.promptCacheSingleton;
|
|
506
501
|
}
|
|
507
502
|
}
|
|
508
503
|
static getDefaultClientConfig() {
|
|
@@ -1009,7 +1004,7 @@ class Client {
|
|
|
1009
1004
|
if (options?.workspaceId !== undefined) {
|
|
1010
1005
|
headers["x-tenant-id"] = options.workspaceId;
|
|
1011
1006
|
}
|
|
1012
|
-
const body = (0,
|
|
1007
|
+
const body = (0, index_js_3.serialize)(mergedRunCreateParam, `Creating run with id: ${mergedRunCreateParam.id}`);
|
|
1013
1008
|
await this.caller.call(async () => {
|
|
1014
1009
|
const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs`, {
|
|
1015
1010
|
method: "POST",
|
|
@@ -1081,7 +1076,7 @@ class Client {
|
|
|
1081
1076
|
.map((item) => item.id)
|
|
1082
1077
|
.concat(batchChunks.patch.map((item) => item.id))
|
|
1083
1078
|
.join(",");
|
|
1084
|
-
await this._postBatchIngestRuns((0,
|
|
1079
|
+
await this._postBatchIngestRuns((0, index_js_3.serialize)(batchChunks, `Ingesting runs with ids: ${runIds}`), options);
|
|
1085
1080
|
}
|
|
1086
1081
|
}
|
|
1087
1082
|
async _postBatchIngestRuns(body, options) {
|
|
@@ -1182,7 +1177,7 @@ class Client {
|
|
|
1182
1177
|
const { inputs, outputs, events, extra, error, serialized, attachments, ...payload } = originalPayload;
|
|
1183
1178
|
const fields = { inputs, outputs, events, extra, error, serialized };
|
|
1184
1179
|
// encode the main run payload
|
|
1185
|
-
const stringifiedPayload = (0,
|
|
1180
|
+
const stringifiedPayload = (0, index_js_3.serialize)(payload, `Serializing for multipart ingestion of run with id: ${payload.id}`);
|
|
1186
1181
|
accumulatedParts.push({
|
|
1187
1182
|
name: `${method}.${payload.id}`,
|
|
1188
1183
|
payload: new Blob([stringifiedPayload], {
|
|
@@ -1194,7 +1189,7 @@ class Client {
|
|
|
1194
1189
|
if (value === undefined) {
|
|
1195
1190
|
continue;
|
|
1196
1191
|
}
|
|
1197
|
-
const stringifiedValue = (0,
|
|
1192
|
+
const stringifiedValue = (0, index_js_3.serialize)(value, `Serializing ${key} for multipart ingestion of run with id: ${payload.id}`);
|
|
1198
1193
|
accumulatedParts.push({
|
|
1199
1194
|
name: `${method}.${payload.id}.${key}`,
|
|
1200
1195
|
payload: new Blob([stringifiedValue], {
|
|
@@ -1424,7 +1419,7 @@ class Client {
|
|
|
1424
1419
|
if (options?.workspaceId !== undefined) {
|
|
1425
1420
|
headers["x-tenant-id"] = options.workspaceId;
|
|
1426
1421
|
}
|
|
1427
|
-
const body = (0,
|
|
1422
|
+
const body = (0, index_js_3.serialize)(run, `Serializing payload to update run with id: ${runId}`);
|
|
1428
1423
|
await this.caller.call(async () => {
|
|
1429
1424
|
const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/${runId}`, {
|
|
1430
1425
|
method: "PATCH",
|
|
@@ -2949,7 +2944,7 @@ class Client {
|
|
|
2949
2944
|
return res;
|
|
2950
2945
|
});
|
|
2951
2946
|
}
|
|
2952
|
-
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, }) {
|
|
2947
|
+
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, sessionId, startTime, }) {
|
|
2953
2948
|
if (!runId && !projectId) {
|
|
2954
2949
|
throw new Error("One of runId or projectId must be provided");
|
|
2955
2950
|
}
|
|
@@ -2980,7 +2975,8 @@ class Client {
|
|
|
2980
2975
|
feedback_source: feedback_source,
|
|
2981
2976
|
comparative_experiment_id: comparativeExperimentId,
|
|
2982
2977
|
feedbackConfig,
|
|
2983
|
-
session_id: projectId,
|
|
2978
|
+
session_id: sessionId ?? projectId,
|
|
2979
|
+
start_time: startTime,
|
|
2984
2980
|
};
|
|
2985
2981
|
const body = JSON.stringify(feedback);
|
|
2986
2982
|
const url = `${this.apiUrl}/feedback`;
|
|
@@ -3201,6 +3197,8 @@ class Client {
|
|
|
3201
3197
|
sourceRunId: res.sourceRunId,
|
|
3202
3198
|
feedbackConfig: res.feedbackConfig,
|
|
3203
3199
|
feedbackSourceType: "model",
|
|
3200
|
+
sessionId: run?.session_id,
|
|
3201
|
+
startTime: run?.start_time,
|
|
3204
3202
|
}));
|
|
3205
3203
|
}
|
|
3206
3204
|
return [evalResults, feedbacks];
|
|
@@ -3605,14 +3603,14 @@ class Client {
|
|
|
3605
3603
|
...(example.split && { split: example.split }),
|
|
3606
3604
|
};
|
|
3607
3605
|
// Add main example data
|
|
3608
|
-
const stringifiedExample = (0,
|
|
3606
|
+
const stringifiedExample = (0, index_js_3.serialize)(exampleBody, `Serializing body for example with id: ${exampleId}`);
|
|
3609
3607
|
const exampleBlob = new Blob([stringifiedExample], {
|
|
3610
3608
|
type: "application/json",
|
|
3611
3609
|
});
|
|
3612
3610
|
formData.append(exampleId, exampleBlob);
|
|
3613
3611
|
// Add inputs if present
|
|
3614
3612
|
if (example.inputs) {
|
|
3615
|
-
const stringifiedInputs = (0,
|
|
3613
|
+
const stringifiedInputs = (0, index_js_3.serialize)(example.inputs, `Serializing inputs for example with id: ${exampleId}`);
|
|
3616
3614
|
const inputsBlob = new Blob([stringifiedInputs], {
|
|
3617
3615
|
type: "application/json",
|
|
3618
3616
|
});
|
|
@@ -3620,7 +3618,7 @@ class Client {
|
|
|
3620
3618
|
}
|
|
3621
3619
|
// Add outputs if present
|
|
3622
3620
|
if (example.outputs) {
|
|
3623
|
-
const stringifiedOutputs = (0,
|
|
3621
|
+
const stringifiedOutputs = (0, index_js_3.serialize)(example.outputs, `Serializing outputs whle updating example with id: ${exampleId}`);
|
|
3624
3622
|
const outputsBlob = new Blob([stringifiedOutputs], {
|
|
3625
3623
|
type: "application/json",
|
|
3626
3624
|
});
|
|
@@ -3645,7 +3643,7 @@ class Client {
|
|
|
3645
3643
|
}
|
|
3646
3644
|
}
|
|
3647
3645
|
if (example.attachments_operations) {
|
|
3648
|
-
const stringifiedAttachmentsOperations = (0,
|
|
3646
|
+
const stringifiedAttachmentsOperations = (0, index_js_3.serialize)(example.attachments_operations, `Serializing attachments while updating example with id: ${exampleId}`);
|
|
3649
3647
|
const attachmentsOperationsBlob = new Blob([stringifiedAttachmentsOperations], {
|
|
3650
3648
|
type: "application/json",
|
|
3651
3649
|
});
|
|
@@ -3696,14 +3694,14 @@ class Client {
|
|
|
3696
3694
|
}),
|
|
3697
3695
|
};
|
|
3698
3696
|
// Add main example data
|
|
3699
|
-
const stringifiedExample = (0,
|
|
3697
|
+
const stringifiedExample = (0, index_js_3.serialize)(exampleBody, `Serializing body for uploaded example with id: ${exampleId}`);
|
|
3700
3698
|
const exampleBlob = new Blob([stringifiedExample], {
|
|
3701
3699
|
type: "application/json",
|
|
3702
3700
|
});
|
|
3703
3701
|
formData.append(exampleId, exampleBlob);
|
|
3704
3702
|
// Add inputs if present
|
|
3705
3703
|
if (example.inputs) {
|
|
3706
|
-
const stringifiedInputs = (0,
|
|
3704
|
+
const stringifiedInputs = (0, index_js_3.serialize)(example.inputs, `Serializing inputs for uploaded example with id: ${exampleId}`);
|
|
3707
3705
|
const inputsBlob = new Blob([stringifiedInputs], {
|
|
3708
3706
|
type: "application/json",
|
|
3709
3707
|
});
|
|
@@ -3711,7 +3709,7 @@ class Client {
|
|
|
3711
3709
|
}
|
|
3712
3710
|
// Add outputs if present
|
|
3713
3711
|
if (example.outputs) {
|
|
3714
|
-
const stringifiedOutputs = (0,
|
|
3712
|
+
const stringifiedOutputs = (0, index_js_3.serialize)(example.outputs, `Serializing outputs for uploaded example with id: ${exampleId}`);
|
|
3715
3713
|
const outputsBlob = new Blob([stringifiedOutputs], {
|
|
3716
3714
|
type: "application/json",
|
|
3717
3715
|
});
|
package/dist/client.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { OTELContext } from "./experimental/otel/types.js";
|
|
|
2
2
|
import { AsyncCallerParams } from "./utils/async_caller.js";
|
|
3
3
|
import { ComparativeExperiment, DataType, Dataset, DatasetDiffInfo, DatasetShareSchema, Example, ExampleCreate, ExampleUpdate, ExampleUpdateWithoutId, Feedback, FeedbackConfig, FeedbackIngestToken, KVMap, LangChainBaseMessage, LangSmithSettings, LikePromptResponse, Prompt, PromptCommit, PromptSortField, Run, RunCreate, RunUpdate, ScoreType, ExampleSearch, TimeDelta, TracerSession, TracerSessionResult, ValueType, AnnotationQueue, RunWithAnnotationQueueInfo, Attachments, UploadExamplesResponse, UpdateExamplesResponse, DatasetVersion, AnnotationQueueWithDetails } from "./schemas.js";
|
|
4
4
|
import { EvaluationResult, EvaluationResults } from "./evaluation/evaluator.js";
|
|
5
|
-
import {
|
|
5
|
+
import { PromptCache } from "./utils/prompt_cache/index.js";
|
|
6
6
|
export interface ClientConfig {
|
|
7
7
|
apiUrl?: string;
|
|
8
8
|
apiKey?: string;
|
|
@@ -71,7 +71,11 @@ export interface ClientConfig {
|
|
|
71
71
|
* const client2 = new Client({ cache: myCache });
|
|
72
72
|
* ```
|
|
73
73
|
*/
|
|
74
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Disable prompt caching for this client.
|
|
76
|
+
* By default, prompt caching is enabled globally.
|
|
77
|
+
*/
|
|
78
|
+
disablePromptCache?: boolean;
|
|
75
79
|
}
|
|
76
80
|
/**
|
|
77
81
|
* Represents the parameters for listing runs (spans) from the Langsmith server.
|
|
@@ -822,7 +826,7 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
822
826
|
exampleIds: string[];
|
|
823
827
|
remove?: boolean;
|
|
824
828
|
}): Promise<void>;
|
|
825
|
-
createFeedback(runId: string | null, key: string, { score, value, correction, comment, sourceInfo, feedbackSourceType, sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, }: {
|
|
829
|
+
createFeedback(runId: string | null, key: string, { score, value, correction, comment, sourceInfo, feedbackSourceType, sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, sessionId, startTime, }: {
|
|
826
830
|
score?: ScoreType;
|
|
827
831
|
value?: ValueType;
|
|
828
832
|
correction?: object;
|
|
@@ -835,6 +839,10 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
835
839
|
eager?: boolean;
|
|
836
840
|
projectId?: string;
|
|
837
841
|
comparativeExperimentId?: string;
|
|
842
|
+
/** The session (project) ID of the run this feedback is for. */
|
|
843
|
+
sessionId?: string;
|
|
844
|
+
/** The start time of the run this feedback is for. Accepts ISO string or epoch ms. */
|
|
845
|
+
startTime?: number | string;
|
|
838
846
|
}): Promise<Feedback>;
|
|
839
847
|
updateFeedback(feedbackId: string, { score, value, correction, comment, }: {
|
|
840
848
|
score?: number | boolean | null;
|
|
@@ -1070,7 +1078,7 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
1070
1078
|
* Get the cache instance, if caching is enabled.
|
|
1071
1079
|
* Useful for accessing cache metrics or manually managing the cache.
|
|
1072
1080
|
*/
|
|
1073
|
-
get cache():
|
|
1081
|
+
get cache(): PromptCache | undefined;
|
|
1074
1082
|
/**
|
|
1075
1083
|
* Cleanup resources held by the client.
|
|
1076
1084
|
* Stops the cache's background refresh timer.
|
package/dist/client.js
CHANGED
|
@@ -9,7 +9,7 @@ import { assertUuid } from "./utils/_uuid.js";
|
|
|
9
9
|
import { warnOnce } from "./utils/warn.js";
|
|
10
10
|
import { parsePromptIdentifier } from "./utils/prompts.js";
|
|
11
11
|
import { raiseForStatus, isLangSmithNotFoundError } from "./utils/error.js";
|
|
12
|
-
import {
|
|
12
|
+
import { promptCacheSingleton, } from "./utils/prompt_cache/index.js";
|
|
13
13
|
import { _globalFetchImplementationIsNodeFetch, _getFetchImplementation, } from "./singletons/fetch.js";
|
|
14
14
|
import { serialize as serializePayloadForTracing } from "./utils/fast-safe-stringify/index.js";
|
|
15
15
|
export function mergeRuntimeEnvIntoRun(run, cachedEnvVars, omitTracedRuntimeInfo) {
|
|
@@ -456,15 +456,10 @@ export class Client {
|
|
|
456
456
|
}
|
|
457
457
|
// Cache metadata env vars once during construction to avoid repeatedly scanning process.env
|
|
458
458
|
this.cachedLSEnvVarsForMetadata = getLangSmithEnvVarsMetadata();
|
|
459
|
-
// Initialize cache
|
|
460
|
-
if (config.
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
else if (config.cache && typeof config.cache === "object") {
|
|
464
|
-
this._cache = config.cache;
|
|
465
|
-
}
|
|
466
|
-
else {
|
|
467
|
-
this._cache = undefined;
|
|
459
|
+
// Initialize prompt cache
|
|
460
|
+
if (!config.disablePromptCache) {
|
|
461
|
+
// Use the global singleton instance
|
|
462
|
+
this._cache = promptCacheSingleton;
|
|
468
463
|
}
|
|
469
464
|
}
|
|
470
465
|
static getDefaultClientConfig() {
|
|
@@ -2911,7 +2906,7 @@ export class Client {
|
|
|
2911
2906
|
return res;
|
|
2912
2907
|
});
|
|
2913
2908
|
}
|
|
2914
|
-
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, }) {
|
|
2909
|
+
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, sessionId, startTime, }) {
|
|
2915
2910
|
if (!runId && !projectId) {
|
|
2916
2911
|
throw new Error("One of runId or projectId must be provided");
|
|
2917
2912
|
}
|
|
@@ -2942,7 +2937,8 @@ export class Client {
|
|
|
2942
2937
|
feedback_source: feedback_source,
|
|
2943
2938
|
comparative_experiment_id: comparativeExperimentId,
|
|
2944
2939
|
feedbackConfig,
|
|
2945
|
-
session_id: projectId,
|
|
2940
|
+
session_id: sessionId ?? projectId,
|
|
2941
|
+
start_time: startTime,
|
|
2946
2942
|
};
|
|
2947
2943
|
const body = JSON.stringify(feedback);
|
|
2948
2944
|
const url = `${this.apiUrl}/feedback`;
|
|
@@ -3163,6 +3159,8 @@ export class Client {
|
|
|
3163
3159
|
sourceRunId: res.sourceRunId,
|
|
3164
3160
|
feedbackConfig: res.feedbackConfig,
|
|
3165
3161
|
feedbackSourceType: "model",
|
|
3162
|
+
sessionId: run?.session_id,
|
|
3163
|
+
startTime: run?.start_time,
|
|
3166
3164
|
}));
|
|
3167
3165
|
}
|
|
3168
3166
|
return [evalResults, feedbacks];
|
|
@@ -176,15 +176,20 @@ async function evaluateComparative(experiments, options) {
|
|
|
176
176
|
referenceOutputs: example.outputs || {},
|
|
177
177
|
})
|
|
178
178
|
: await evaluator(runs, example);
|
|
179
|
+
// Build a lookup for run metadata
|
|
180
|
+
const runsById = new Map(runs.map((r) => [r.id, r]));
|
|
179
181
|
for (const [runId, score] of Object.entries(result.scores)) {
|
|
180
182
|
// validate if the run id
|
|
181
183
|
if (!expectedRunIds.has(runId)) {
|
|
182
184
|
throw new Error(`Returning an invalid run id ${runId} from evaluator.`);
|
|
183
185
|
}
|
|
186
|
+
const run = runsById.get(runId);
|
|
184
187
|
await client.createFeedback(runId, result.key, {
|
|
185
188
|
score,
|
|
186
189
|
sourceRunId: result.source_run_id,
|
|
187
190
|
comparativeExperimentId: comparativeExperiment.id,
|
|
191
|
+
sessionId: run?.session_id,
|
|
192
|
+
startTime: run?.start_time,
|
|
188
193
|
});
|
|
189
194
|
}
|
|
190
195
|
return result;
|
|
@@ -170,15 +170,20 @@ export async function evaluateComparative(experiments, options) {
|
|
|
170
170
|
referenceOutputs: example.outputs || {},
|
|
171
171
|
})
|
|
172
172
|
: await evaluator(runs, example);
|
|
173
|
+
// Build a lookup for run metadata
|
|
174
|
+
const runsById = new Map(runs.map((r) => [r.id, r]));
|
|
173
175
|
for (const [runId, score] of Object.entries(result.scores)) {
|
|
174
176
|
// validate if the run id
|
|
175
177
|
if (!expectedRunIds.has(runId)) {
|
|
176
178
|
throw new Error(`Returning an invalid run id ${runId} from evaluator.`);
|
|
177
179
|
}
|
|
180
|
+
const run = runsById.get(runId);
|
|
178
181
|
await client.createFeedback(runId, result.key, {
|
|
179
182
|
score,
|
|
180
183
|
sourceRunId: result.source_run_id,
|
|
181
184
|
comparativeExperimentId: comparativeExperiment.id,
|
|
185
|
+
sessionId: run?.session_id,
|
|
186
|
+
startTime: run?.start_time,
|
|
182
187
|
});
|
|
183
188
|
}
|
|
184
189
|
return result;
|