langsmith 0.3.77 → 0.3.78
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/experimental/vercel/index.cjs +44 -9
- package/dist/experimental/vercel/index.d.ts +11 -1
- package/dist/experimental/vercel/index.js +43 -8
- package/dist/experimental/vercel/middleware.cjs +4 -1
- package/dist/experimental/vercel/middleware.js +4 -1
- package/dist/experimental/vercel/utils.cjs +4 -1
- package/dist/experimental/vercel/utils.d.ts +1 -1
- package/dist/experimental/vercel/utils.js +4 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run_trees.cjs +3 -0
- package/dist/run_trees.js +3 -0
- package/dist/wrappers/openai.cjs +70 -51
- package/dist/wrappers/openai.d.ts +2 -0
- package/dist/wrappers/openai.js +70 -51
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wrapAISDK = exports.createLangSmithProviderOptions = void 0;
|
|
3
|
+
exports.convertMessageToTracedFormat = exports.wrapAISDK = exports.createLangSmithProviderOptions = void 0;
|
|
4
4
|
const middleware_js_1 = require("./middleware.cjs");
|
|
5
5
|
const utils_js_1 = require("./utils.cjs");
|
|
6
|
+
Object.defineProperty(exports, "convertMessageToTracedFormat", { enumerable: true, get: function () { return utils_js_1.convertMessageToTracedFormat; } });
|
|
6
7
|
const traceable_js_1 = require("../../traceable.cjs");
|
|
7
8
|
const _wrapTools = (tools, lsConfig) => {
|
|
8
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -49,10 +50,16 @@ const _getModelId = (model) => {
|
|
|
49
50
|
const _formatTracedInputs = (params) => {
|
|
50
51
|
const { prompt, messages, model, tools, ...rest } = params;
|
|
51
52
|
if (Array.isArray(prompt)) {
|
|
52
|
-
return {
|
|
53
|
+
return {
|
|
54
|
+
...rest,
|
|
55
|
+
messages: prompt.map((message) => (0, utils_js_1.convertMessageToTracedFormat)(message)),
|
|
56
|
+
};
|
|
53
57
|
}
|
|
54
58
|
else if (Array.isArray(messages)) {
|
|
55
|
-
return {
|
|
59
|
+
return {
|
|
60
|
+
...rest,
|
|
61
|
+
messages: messages.map((message) => (0, utils_js_1.convertMessageToTracedFormat)(message)),
|
|
62
|
+
};
|
|
56
63
|
}
|
|
57
64
|
else {
|
|
58
65
|
return { ...rest, prompt, messages };
|
|
@@ -75,6 +82,8 @@ const _extractChildRunConfig = (lsConfig) => {
|
|
|
75
82
|
childConfig.processInputs = processChildLLMRunInputs;
|
|
76
83
|
}
|
|
77
84
|
if (processChildLLMRunOutputs) {
|
|
85
|
+
// TODO: Fix this typing on minor bump
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
87
|
childConfig.processOutputs = processChildLLMRunOutputs;
|
|
79
88
|
}
|
|
80
89
|
return childConfig;
|
|
@@ -168,6 +177,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
168
177
|
middleware: (0, middleware_js_1.LangSmithMiddleware)({
|
|
169
178
|
name: _getModelDisplayName(params.model),
|
|
170
179
|
modelId: _getModelId(params.model),
|
|
180
|
+
// TODO: Fix this typing on minor bump
|
|
171
181
|
lsConfig: resolvedChildLLMRunConfig,
|
|
172
182
|
}),
|
|
173
183
|
});
|
|
@@ -190,7 +200,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
190
200
|
},
|
|
191
201
|
processOutputs: async (outputs) => {
|
|
192
202
|
if (resolvedLsConfig?.processOutputs) {
|
|
193
|
-
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
203
|
+
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
204
|
+
// TODO: Fix this typing on minor bump
|
|
205
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
206
|
+
outputs);
|
|
194
207
|
return processedOutputs;
|
|
195
208
|
}
|
|
196
209
|
if (outputs.outputs == null || typeof outputs.outputs !== "object") {
|
|
@@ -206,7 +219,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
206
219
|
return (0, utils_js_1.convertMessageToTracedFormat)({
|
|
207
220
|
content: content ?? outputs.outputs.text,
|
|
208
221
|
role: "assistant",
|
|
209
|
-
});
|
|
222
|
+
}, resolvedLsConfig?.traceResponseMetadata ? { steps } : undefined);
|
|
210
223
|
}
|
|
211
224
|
else {
|
|
212
225
|
return outputs;
|
|
@@ -244,6 +257,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
244
257
|
middleware: (0, middleware_js_1.LangSmithMiddleware)({
|
|
245
258
|
name: _getModelDisplayName(params.model),
|
|
246
259
|
modelId: _getModelId(params.model),
|
|
260
|
+
// TODO: Fix this typing on minor bump
|
|
247
261
|
lsConfig: resolvedChildLLMRunConfig,
|
|
248
262
|
}),
|
|
249
263
|
});
|
|
@@ -265,7 +279,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
265
279
|
},
|
|
266
280
|
processOutputs: async (outputs) => {
|
|
267
281
|
if (resolvedLsConfig?.processOutputs) {
|
|
268
|
-
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
282
|
+
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
283
|
+
// TODO: Fix this typing on minor bump
|
|
284
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
285
|
+
outputs);
|
|
269
286
|
return processedOutputs;
|
|
270
287
|
}
|
|
271
288
|
if (outputs.outputs == null || typeof outputs.outputs !== "object") {
|
|
@@ -306,6 +323,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
306
323
|
middleware: (0, middleware_js_1.LangSmithMiddleware)({
|
|
307
324
|
name: _getModelDisplayName(params.model),
|
|
308
325
|
modelId: _getModelId(params.model),
|
|
326
|
+
// TODO: Fix this typing on minor bump
|
|
309
327
|
lsConfig: resolvedChildLLMRunConfig,
|
|
310
328
|
}),
|
|
311
329
|
});
|
|
@@ -329,7 +347,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
329
347
|
processOutputs: async (outputs) => {
|
|
330
348
|
try {
|
|
331
349
|
if (resolvedLsConfig?.processOutputs) {
|
|
332
|
-
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
350
|
+
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
351
|
+
// TODO: Fix this typing on minor bump
|
|
352
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
353
|
+
outputs);
|
|
333
354
|
return processedOutputs;
|
|
334
355
|
}
|
|
335
356
|
if (outputs.outputs == null ||
|
|
@@ -347,10 +368,20 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
347
368
|
!["object", "string"].includes(typeof content)) {
|
|
348
369
|
return outputs;
|
|
349
370
|
}
|
|
371
|
+
let responseMetadata = undefined;
|
|
372
|
+
if (resolvedLsConfig?.traceResponseMetadata) {
|
|
373
|
+
try {
|
|
374
|
+
const steps = await outputs.outputs.steps;
|
|
375
|
+
responseMetadata = { steps };
|
|
376
|
+
}
|
|
377
|
+
catch (e) {
|
|
378
|
+
// Do nothing if step parsing fails
|
|
379
|
+
}
|
|
380
|
+
}
|
|
350
381
|
return (0, utils_js_1.convertMessageToTracedFormat)({
|
|
351
382
|
content,
|
|
352
383
|
role: "assistant",
|
|
353
|
-
});
|
|
384
|
+
}, responseMetadata);
|
|
354
385
|
}
|
|
355
386
|
catch (e) {
|
|
356
387
|
// Handle parsing failures without a log
|
|
@@ -390,6 +421,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
390
421
|
middleware: (0, middleware_js_1.LangSmithMiddleware)({
|
|
391
422
|
name: _getModelDisplayName(params.model),
|
|
392
423
|
modelId: _getModelId(params.model),
|
|
424
|
+
// TODO: Fix this typing on minor bump
|
|
393
425
|
lsConfig: resolvedChildLLMRunConfig,
|
|
394
426
|
}),
|
|
395
427
|
});
|
|
@@ -412,7 +444,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
412
444
|
processOutputs: async (outputs) => {
|
|
413
445
|
try {
|
|
414
446
|
if (resolvedLsConfig?.processOutputs) {
|
|
415
|
-
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
447
|
+
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
448
|
+
// TODO: Fix this typing on minor bump
|
|
449
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
450
|
+
outputs);
|
|
416
451
|
return processedOutputs;
|
|
417
452
|
}
|
|
418
453
|
if (outputs.outputs == null ||
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { JSONValue } from "ai";
|
|
2
2
|
import type { LanguageModelV2, LanguageModelV2CallOptions } from "@ai-sdk/provider";
|
|
3
3
|
import { type AggregatedDoStreamOutput } from "./middleware.js";
|
|
4
|
+
import { convertMessageToTracedFormat } from "./utils.js";
|
|
4
5
|
import { RunTreeConfig } from "../../run_trees.js";
|
|
5
6
|
export type { AggregatedDoStreamOutput };
|
|
6
7
|
export type WrapAISDKConfig<T extends (...args: any[]) => any = (...args: any[]) => any> = Partial<Omit<RunTreeConfig, "inputs" | "outputs" | "run_type" | "child_runs" | "parent_run" | "error" | "serialized">> & {
|
|
@@ -97,7 +98,9 @@ export type WrapAISDKConfig<T extends (...args: any[]) => any = (...args: any[])
|
|
|
97
98
|
* @param outputs.raw - Raw outputs from the AI SDK.
|
|
98
99
|
* @returns A single combined key-value map of processed outputs.
|
|
99
100
|
*/
|
|
100
|
-
processOutputs?: (outputs:
|
|
101
|
+
processOutputs?: (outputs: {
|
|
102
|
+
outputs: Awaited<ReturnType<T>>;
|
|
103
|
+
}) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
101
104
|
/**
|
|
102
105
|
* Apply transformations to AI SDK child LLM run inputs before logging.
|
|
103
106
|
* This function should NOT mutate the inputs.
|
|
@@ -180,6 +183,12 @@ export type WrapAISDKConfig<T extends (...args: any[]) => any = (...args: any[])
|
|
|
180
183
|
* @returns A single combined key-value map of processed outputs.
|
|
181
184
|
*/
|
|
182
185
|
processChildLLMRunOutputs?: (outputs: "fullStream" extends keyof Awaited<ReturnType<T>> ? AggregatedDoStreamOutput : Awaited<ReturnType<LanguageModelV2["doGenerate"]>>) => Record<string, unknown>;
|
|
186
|
+
/**
|
|
187
|
+
* Whether to include additional fields such as intermediate steps in traced
|
|
188
|
+
* output messages.
|
|
189
|
+
* @default false
|
|
190
|
+
*/
|
|
191
|
+
traceResponseMetadata?: boolean;
|
|
183
192
|
};
|
|
184
193
|
/**
|
|
185
194
|
* Wraps LangSmith config in a way that matches AI SDK provider types.
|
|
@@ -238,3 +247,4 @@ declare const wrapAISDK: <GenerateTextType extends (...args: any[]) => any, Stre
|
|
|
238
247
|
streamObject: StreamObjectType;
|
|
239
248
|
};
|
|
240
249
|
export { wrapAISDK };
|
|
250
|
+
export { convertMessageToTracedFormat };
|
|
@@ -46,10 +46,16 @@ const _getModelId = (model) => {
|
|
|
46
46
|
const _formatTracedInputs = (params) => {
|
|
47
47
|
const { prompt, messages, model, tools, ...rest } = params;
|
|
48
48
|
if (Array.isArray(prompt)) {
|
|
49
|
-
return {
|
|
49
|
+
return {
|
|
50
|
+
...rest,
|
|
51
|
+
messages: prompt.map((message) => convertMessageToTracedFormat(message)),
|
|
52
|
+
};
|
|
50
53
|
}
|
|
51
54
|
else if (Array.isArray(messages)) {
|
|
52
|
-
return {
|
|
55
|
+
return {
|
|
56
|
+
...rest,
|
|
57
|
+
messages: messages.map((message) => convertMessageToTracedFormat(message)),
|
|
58
|
+
};
|
|
53
59
|
}
|
|
54
60
|
else {
|
|
55
61
|
return { ...rest, prompt, messages };
|
|
@@ -72,6 +78,8 @@ const _extractChildRunConfig = (lsConfig) => {
|
|
|
72
78
|
childConfig.processInputs = processChildLLMRunInputs;
|
|
73
79
|
}
|
|
74
80
|
if (processChildLLMRunOutputs) {
|
|
81
|
+
// TODO: Fix this typing on minor bump
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
83
|
childConfig.processOutputs = processChildLLMRunOutputs;
|
|
76
84
|
}
|
|
77
85
|
return childConfig;
|
|
@@ -164,6 +172,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
164
172
|
middleware: LangSmithMiddleware({
|
|
165
173
|
name: _getModelDisplayName(params.model),
|
|
166
174
|
modelId: _getModelId(params.model),
|
|
175
|
+
// TODO: Fix this typing on minor bump
|
|
167
176
|
lsConfig: resolvedChildLLMRunConfig,
|
|
168
177
|
}),
|
|
169
178
|
});
|
|
@@ -186,7 +195,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
186
195
|
},
|
|
187
196
|
processOutputs: async (outputs) => {
|
|
188
197
|
if (resolvedLsConfig?.processOutputs) {
|
|
189
|
-
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
198
|
+
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
199
|
+
// TODO: Fix this typing on minor bump
|
|
200
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
201
|
+
outputs);
|
|
190
202
|
return processedOutputs;
|
|
191
203
|
}
|
|
192
204
|
if (outputs.outputs == null || typeof outputs.outputs !== "object") {
|
|
@@ -202,7 +214,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
202
214
|
return convertMessageToTracedFormat({
|
|
203
215
|
content: content ?? outputs.outputs.text,
|
|
204
216
|
role: "assistant",
|
|
205
|
-
});
|
|
217
|
+
}, resolvedLsConfig?.traceResponseMetadata ? { steps } : undefined);
|
|
206
218
|
}
|
|
207
219
|
else {
|
|
208
220
|
return outputs;
|
|
@@ -240,6 +252,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
240
252
|
middleware: LangSmithMiddleware({
|
|
241
253
|
name: _getModelDisplayName(params.model),
|
|
242
254
|
modelId: _getModelId(params.model),
|
|
255
|
+
// TODO: Fix this typing on minor bump
|
|
243
256
|
lsConfig: resolvedChildLLMRunConfig,
|
|
244
257
|
}),
|
|
245
258
|
});
|
|
@@ -261,7 +274,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
261
274
|
},
|
|
262
275
|
processOutputs: async (outputs) => {
|
|
263
276
|
if (resolvedLsConfig?.processOutputs) {
|
|
264
|
-
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
277
|
+
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
278
|
+
// TODO: Fix this typing on minor bump
|
|
279
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
280
|
+
outputs);
|
|
265
281
|
return processedOutputs;
|
|
266
282
|
}
|
|
267
283
|
if (outputs.outputs == null || typeof outputs.outputs !== "object") {
|
|
@@ -302,6 +318,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
302
318
|
middleware: LangSmithMiddleware({
|
|
303
319
|
name: _getModelDisplayName(params.model),
|
|
304
320
|
modelId: _getModelId(params.model),
|
|
321
|
+
// TODO: Fix this typing on minor bump
|
|
305
322
|
lsConfig: resolvedChildLLMRunConfig,
|
|
306
323
|
}),
|
|
307
324
|
});
|
|
@@ -325,7 +342,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
325
342
|
processOutputs: async (outputs) => {
|
|
326
343
|
try {
|
|
327
344
|
if (resolvedLsConfig?.processOutputs) {
|
|
328
|
-
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
345
|
+
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
346
|
+
// TODO: Fix this typing on minor bump
|
|
347
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
348
|
+
outputs);
|
|
329
349
|
return processedOutputs;
|
|
330
350
|
}
|
|
331
351
|
if (outputs.outputs == null ||
|
|
@@ -343,10 +363,20 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
343
363
|
!["object", "string"].includes(typeof content)) {
|
|
344
364
|
return outputs;
|
|
345
365
|
}
|
|
366
|
+
let responseMetadata = undefined;
|
|
367
|
+
if (resolvedLsConfig?.traceResponseMetadata) {
|
|
368
|
+
try {
|
|
369
|
+
const steps = await outputs.outputs.steps;
|
|
370
|
+
responseMetadata = { steps };
|
|
371
|
+
}
|
|
372
|
+
catch (e) {
|
|
373
|
+
// Do nothing if step parsing fails
|
|
374
|
+
}
|
|
375
|
+
}
|
|
346
376
|
return convertMessageToTracedFormat({
|
|
347
377
|
content,
|
|
348
378
|
role: "assistant",
|
|
349
|
-
});
|
|
379
|
+
}, responseMetadata);
|
|
350
380
|
}
|
|
351
381
|
catch (e) {
|
|
352
382
|
// Handle parsing failures without a log
|
|
@@ -386,6 +416,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
386
416
|
middleware: LangSmithMiddleware({
|
|
387
417
|
name: _getModelDisplayName(params.model),
|
|
388
418
|
modelId: _getModelId(params.model),
|
|
419
|
+
// TODO: Fix this typing on minor bump
|
|
389
420
|
lsConfig: resolvedChildLLMRunConfig,
|
|
390
421
|
}),
|
|
391
422
|
});
|
|
@@ -408,7 +439,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
408
439
|
processOutputs: async (outputs) => {
|
|
409
440
|
try {
|
|
410
441
|
if (resolvedLsConfig?.processOutputs) {
|
|
411
|
-
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
442
|
+
const processedOutputs = await resolvedLsConfig.processOutputs(
|
|
443
|
+
// TODO: Fix this typing on minor bump
|
|
444
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
445
|
+
outputs);
|
|
412
446
|
return processedOutputs;
|
|
413
447
|
}
|
|
414
448
|
if (outputs.outputs == null ||
|
|
@@ -437,3 +471,4 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
|
|
|
437
471
|
};
|
|
438
472
|
};
|
|
439
473
|
export { wrapAISDK };
|
|
474
|
+
export { convertMessageToTracedFormat };
|
|
@@ -11,7 +11,10 @@ const _formatTracedInputs = (params) => {
|
|
|
11
11
|
return params;
|
|
12
12
|
}
|
|
13
13
|
if (Array.isArray(prompt)) {
|
|
14
|
-
return {
|
|
14
|
+
return {
|
|
15
|
+
...rest,
|
|
16
|
+
messages: prompt.map((message) => (0, utils_js_1.convertMessageToTracedFormat)(message)),
|
|
17
|
+
};
|
|
15
18
|
}
|
|
16
19
|
return rest;
|
|
17
20
|
};
|
|
@@ -8,7 +8,10 @@ const _formatTracedInputs = (params) => {
|
|
|
8
8
|
return params;
|
|
9
9
|
}
|
|
10
10
|
if (Array.isArray(prompt)) {
|
|
11
|
-
return {
|
|
11
|
+
return {
|
|
12
|
+
...rest,
|
|
13
|
+
messages: prompt.map((message) => convertMessageToTracedFormat(message)),
|
|
14
|
+
};
|
|
12
15
|
}
|
|
13
16
|
return rest;
|
|
14
17
|
};
|
|
@@ -97,7 +97,7 @@ const normalizeFileDataAsDataURL = (fileData, mimeType) => {
|
|
|
97
97
|
return normalizedFileData;
|
|
98
98
|
};
|
|
99
99
|
exports.normalizeFileDataAsDataURL = normalizeFileDataAsDataURL;
|
|
100
|
-
const convertMessageToTracedFormat = (message) => {
|
|
100
|
+
const convertMessageToTracedFormat = (message, responseMetadata) => {
|
|
101
101
|
const formattedMessage = {
|
|
102
102
|
...message,
|
|
103
103
|
};
|
|
@@ -165,6 +165,9 @@ const convertMessageToTracedFormat = (message) => {
|
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
+
if (responseMetadata != null) {
|
|
169
|
+
formattedMessage.response_metadata = responseMetadata;
|
|
170
|
+
}
|
|
168
171
|
return formattedMessage;
|
|
169
172
|
};
|
|
170
173
|
exports.convertMessageToTracedFormat = convertMessageToTracedFormat;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { LanguageModelV2DataContent, LanguageModelV2Message } from "@ai-sdk/provider";
|
|
2
2
|
import type { ModelMessage } from "ai";
|
|
3
3
|
export declare const normalizeFileDataAsDataURL: (fileData: LanguageModelV2DataContent | ArrayBuffer, mimeType?: string) => string;
|
|
4
|
-
export declare const convertMessageToTracedFormat: (message: LanguageModelV2Message | ModelMessage) => Record<string, unknown>;
|
|
4
|
+
export declare const convertMessageToTracedFormat: (message: LanguageModelV2Message | ModelMessage, responseMetadata?: Record<string, unknown>) => Record<string, unknown>;
|
|
@@ -93,7 +93,7 @@ export const normalizeFileDataAsDataURL = (fileData, mimeType) => {
|
|
|
93
93
|
}
|
|
94
94
|
return normalizedFileData;
|
|
95
95
|
};
|
|
96
|
-
export const convertMessageToTracedFormat = (message) => {
|
|
96
|
+
export const convertMessageToTracedFormat = (message, responseMetadata) => {
|
|
97
97
|
const formattedMessage = {
|
|
98
98
|
...message,
|
|
99
99
|
};
|
|
@@ -161,5 +161,8 @@ export const convertMessageToTracedFormat = (message) => {
|
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
+
if (responseMetadata != null) {
|
|
165
|
+
formattedMessage.response_metadata = responseMetadata;
|
|
166
|
+
}
|
|
164
167
|
return formattedMessage;
|
|
165
168
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -10,4 +10,4 @@ Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true
|
|
|
10
10
|
var project_js_1 = require("./utils/project.cjs");
|
|
11
11
|
Object.defineProperty(exports, "getDefaultProjectName", { enumerable: true, get: function () { return project_js_1.getDefaultProjectName; } });
|
|
12
12
|
// Update using yarn bump-version
|
|
13
|
-
exports.__version__ = "0.3.
|
|
13
|
+
exports.__version__ = "0.3.78";
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, }
|
|
|
3
3
|
export { RunTree, type RunTreeConfig } from "./run_trees.js";
|
|
4
4
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
5
5
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
6
|
-
export declare const __version__ = "0.3.
|
|
6
|
+
export declare const __version__ = "0.3.78";
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,4 @@ export { RunTree } from "./run_trees.js";
|
|
|
3
3
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
4
4
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
5
5
|
// Update using yarn bump-version
|
|
6
|
-
export const __version__ = "0.3.
|
|
6
|
+
export const __version__ = "0.3.78";
|
package/dist/run_trees.cjs
CHANGED
|
@@ -311,6 +311,9 @@ class RunTree {
|
|
|
311
311
|
...config?.extra?.metadata,
|
|
312
312
|
};
|
|
313
313
|
config.extra = { ...config.extra, metadata: dedupedMetadata };
|
|
314
|
+
if ("id" in config && config.id == null) {
|
|
315
|
+
delete config.id;
|
|
316
|
+
}
|
|
314
317
|
Object.assign(this, { ...defaultConfig, ...config, client });
|
|
315
318
|
if (!this.trace_id) {
|
|
316
319
|
if (this.parent_run) {
|
package/dist/run_trees.js
CHANGED
|
@@ -272,6 +272,9 @@ export class RunTree {
|
|
|
272
272
|
...config?.extra?.metadata,
|
|
273
273
|
};
|
|
274
274
|
config.extra = { ...config.extra, metadata: dedupedMetadata };
|
|
275
|
+
if ("id" in config && config.id == null) {
|
|
276
|
+
delete config.id;
|
|
277
|
+
}
|
|
275
278
|
Object.assign(this, { ...defaultConfig, ...config, client });
|
|
276
279
|
if (!this.trace_id) {
|
|
277
280
|
if (this.parent_run) {
|
package/dist/wrappers/openai.cjs
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.wrapOpenAI = void 0;
|
|
4
4
|
const traceable_js_1 = require("../traceable.cjs");
|
|
5
|
+
const TRACED_INVOCATION_KEYS = [
|
|
6
|
+
"frequency_penalty",
|
|
7
|
+
"n",
|
|
8
|
+
"logit_bias",
|
|
9
|
+
"logprobs",
|
|
10
|
+
"modalities",
|
|
11
|
+
"parallel_tool_calls",
|
|
12
|
+
"prediction",
|
|
13
|
+
"presence_penalty",
|
|
14
|
+
"prompt_cache_key",
|
|
15
|
+
"reasoning",
|
|
16
|
+
"reasoning_effort",
|
|
17
|
+
"response_format",
|
|
18
|
+
"seed",
|
|
19
|
+
"service_tier",
|
|
20
|
+
"stream_options",
|
|
21
|
+
"top_logprobs",
|
|
22
|
+
"top_p",
|
|
23
|
+
"truncation",
|
|
24
|
+
"user",
|
|
25
|
+
"verbosity",
|
|
26
|
+
"web_search_options",
|
|
27
|
+
];
|
|
5
28
|
function _combineChatCompletionChoices(choices
|
|
6
29
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
30
|
) {
|
|
@@ -263,33 +286,9 @@ const wrapOpenAI = (openai, options) => {
|
|
|
263
286
|
const params = payload;
|
|
264
287
|
const ls_stop = (typeof params.stop === "string" ? [params.stop] : params.stop) ??
|
|
265
288
|
undefined;
|
|
266
|
-
// Allowlist of safe invocation parameters to include
|
|
267
|
-
const allowedInvocationKeys = new Set([
|
|
268
|
-
"frequency_penalty",
|
|
269
|
-
"n",
|
|
270
|
-
"logit_bias",
|
|
271
|
-
"logprobs",
|
|
272
|
-
"modalities",
|
|
273
|
-
"parallel_tool_calls",
|
|
274
|
-
"prediction",
|
|
275
|
-
"presence_penalty",
|
|
276
|
-
"prompt_cache_key",
|
|
277
|
-
"reasoning",
|
|
278
|
-
"reasoning_effort",
|
|
279
|
-
"response_format",
|
|
280
|
-
"seed",
|
|
281
|
-
"service_tier",
|
|
282
|
-
"stream_options",
|
|
283
|
-
"top_logprobs",
|
|
284
|
-
"top_p",
|
|
285
|
-
"truncation",
|
|
286
|
-
"user",
|
|
287
|
-
"verbosity",
|
|
288
|
-
"web_search_options",
|
|
289
|
-
]);
|
|
290
289
|
const ls_invocation_params = {};
|
|
291
290
|
for (const [key, value] of Object.entries(params)) {
|
|
292
|
-
if (
|
|
291
|
+
if (TRACED_INVOCATION_KEYS.includes(key)) {
|
|
293
292
|
ls_invocation_params[key] = value;
|
|
294
293
|
}
|
|
295
294
|
}
|
|
@@ -340,33 +339,9 @@ const wrapOpenAI = (openai, options) => {
|
|
|
340
339
|
const params = payload;
|
|
341
340
|
const ls_stop = (typeof params.stop === "string" ? [params.stop] : params.stop) ??
|
|
342
341
|
undefined;
|
|
343
|
-
// Allowlist of safe invocation parameters to include
|
|
344
|
-
const allowedInvocationKeys = new Set([
|
|
345
|
-
"frequency_penalty",
|
|
346
|
-
"n",
|
|
347
|
-
"logit_bias",
|
|
348
|
-
"logprobs",
|
|
349
|
-
"modalities",
|
|
350
|
-
"parallel_tool_calls",
|
|
351
|
-
"prediction",
|
|
352
|
-
"presence_penalty",
|
|
353
|
-
"prompt_cache_key",
|
|
354
|
-
"reasoning",
|
|
355
|
-
"reasoning_effort",
|
|
356
|
-
"response_format",
|
|
357
|
-
"seed",
|
|
358
|
-
"service_tier",
|
|
359
|
-
"stream_options",
|
|
360
|
-
"top_logprobs",
|
|
361
|
-
"top_p",
|
|
362
|
-
"truncation",
|
|
363
|
-
"user",
|
|
364
|
-
"verbosity",
|
|
365
|
-
"web_search_options",
|
|
366
|
-
]);
|
|
367
342
|
const ls_invocation_params = {};
|
|
368
343
|
for (const [key, value] of Object.entries(params)) {
|
|
369
|
-
if (
|
|
344
|
+
if (TRACED_INVOCATION_KEYS.includes(key)) {
|
|
370
345
|
ls_invocation_params[key] = value;
|
|
371
346
|
}
|
|
372
347
|
}
|
|
@@ -406,7 +381,51 @@ const wrapOpenAI = (openai, options) => {
|
|
|
406
381
|
const params = payload;
|
|
407
382
|
return {
|
|
408
383
|
ls_provider: provider,
|
|
409
|
-
ls_model_type: "
|
|
384
|
+
ls_model_type: "chat",
|
|
385
|
+
ls_model_name: params.model || "unknown",
|
|
386
|
+
};
|
|
387
|
+
},
|
|
388
|
+
processOutputs: processChatCompletion,
|
|
389
|
+
...options,
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
if (tracedOpenAIClient.responses &&
|
|
393
|
+
typeof tracedOpenAIClient.responses.parse === "function") {
|
|
394
|
+
tracedOpenAIClient.responses.parse = (0, traceable_js_1.traceable)(openai.responses.parse.bind(openai.responses), {
|
|
395
|
+
name: chatName,
|
|
396
|
+
run_type: "llm",
|
|
397
|
+
aggregator: responsesAggregator,
|
|
398
|
+
argsConfigPath: [1, "langsmithExtra"],
|
|
399
|
+
getInvocationParams: (payload) => {
|
|
400
|
+
if (typeof payload !== "object" || payload == null)
|
|
401
|
+
return undefined;
|
|
402
|
+
// Handle responses API parameters
|
|
403
|
+
const params = payload;
|
|
404
|
+
return {
|
|
405
|
+
ls_provider: provider,
|
|
406
|
+
ls_model_type: "chat",
|
|
407
|
+
ls_model_name: params.model || "unknown",
|
|
408
|
+
};
|
|
409
|
+
},
|
|
410
|
+
processOutputs: processChatCompletion,
|
|
411
|
+
...options,
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
if (tracedOpenAIClient.responses &&
|
|
415
|
+
typeof tracedOpenAIClient.responses.stream === "function") {
|
|
416
|
+
tracedOpenAIClient.responses.stream = (0, traceable_js_1.traceable)(openai.responses.stream.bind(openai.responses), {
|
|
417
|
+
name: chatName,
|
|
418
|
+
run_type: "llm",
|
|
419
|
+
aggregator: responsesAggregator,
|
|
420
|
+
argsConfigPath: [1, "langsmithExtra"],
|
|
421
|
+
getInvocationParams: (payload) => {
|
|
422
|
+
if (typeof payload !== "object" || payload == null)
|
|
423
|
+
return undefined;
|
|
424
|
+
// Handle responses API parameters
|
|
425
|
+
const params = payload;
|
|
426
|
+
return {
|
|
427
|
+
ls_provider: provider,
|
|
428
|
+
ls_model_type: "chat",
|
|
410
429
|
ls_model_name: params.model || "unknown",
|
|
411
430
|
};
|
|
412
431
|
},
|
|
@@ -15,6 +15,8 @@ type OpenAIType = {
|
|
|
15
15
|
responses?: {
|
|
16
16
|
create: (...args: any[]) => any;
|
|
17
17
|
retrieve: (...args: any[]) => any;
|
|
18
|
+
parse: (...args: any[]) => any;
|
|
19
|
+
stream: (...args: any[]) => any;
|
|
18
20
|
};
|
|
19
21
|
};
|
|
20
22
|
type ExtraRunTreeConfig = Pick<Partial<RunTreeConfig>, "name" | "metadata" | "tags">;
|
package/dist/wrappers/openai.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
import { isTraceableFunction, traceable, } from "../traceable.js";
|
|
2
|
+
const TRACED_INVOCATION_KEYS = [
|
|
3
|
+
"frequency_penalty",
|
|
4
|
+
"n",
|
|
5
|
+
"logit_bias",
|
|
6
|
+
"logprobs",
|
|
7
|
+
"modalities",
|
|
8
|
+
"parallel_tool_calls",
|
|
9
|
+
"prediction",
|
|
10
|
+
"presence_penalty",
|
|
11
|
+
"prompt_cache_key",
|
|
12
|
+
"reasoning",
|
|
13
|
+
"reasoning_effort",
|
|
14
|
+
"response_format",
|
|
15
|
+
"seed",
|
|
16
|
+
"service_tier",
|
|
17
|
+
"stream_options",
|
|
18
|
+
"top_logprobs",
|
|
19
|
+
"top_p",
|
|
20
|
+
"truncation",
|
|
21
|
+
"user",
|
|
22
|
+
"verbosity",
|
|
23
|
+
"web_search_options",
|
|
24
|
+
];
|
|
2
25
|
function _combineChatCompletionChoices(choices
|
|
3
26
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
27
|
) {
|
|
@@ -260,33 +283,9 @@ export const wrapOpenAI = (openai, options) => {
|
|
|
260
283
|
const params = payload;
|
|
261
284
|
const ls_stop = (typeof params.stop === "string" ? [params.stop] : params.stop) ??
|
|
262
285
|
undefined;
|
|
263
|
-
// Allowlist of safe invocation parameters to include
|
|
264
|
-
const allowedInvocationKeys = new Set([
|
|
265
|
-
"frequency_penalty",
|
|
266
|
-
"n",
|
|
267
|
-
"logit_bias",
|
|
268
|
-
"logprobs",
|
|
269
|
-
"modalities",
|
|
270
|
-
"parallel_tool_calls",
|
|
271
|
-
"prediction",
|
|
272
|
-
"presence_penalty",
|
|
273
|
-
"prompt_cache_key",
|
|
274
|
-
"reasoning",
|
|
275
|
-
"reasoning_effort",
|
|
276
|
-
"response_format",
|
|
277
|
-
"seed",
|
|
278
|
-
"service_tier",
|
|
279
|
-
"stream_options",
|
|
280
|
-
"top_logprobs",
|
|
281
|
-
"top_p",
|
|
282
|
-
"truncation",
|
|
283
|
-
"user",
|
|
284
|
-
"verbosity",
|
|
285
|
-
"web_search_options",
|
|
286
|
-
]);
|
|
287
286
|
const ls_invocation_params = {};
|
|
288
287
|
for (const [key, value] of Object.entries(params)) {
|
|
289
|
-
if (
|
|
288
|
+
if (TRACED_INVOCATION_KEYS.includes(key)) {
|
|
290
289
|
ls_invocation_params[key] = value;
|
|
291
290
|
}
|
|
292
291
|
}
|
|
@@ -337,33 +336,9 @@ export const wrapOpenAI = (openai, options) => {
|
|
|
337
336
|
const params = payload;
|
|
338
337
|
const ls_stop = (typeof params.stop === "string" ? [params.stop] : params.stop) ??
|
|
339
338
|
undefined;
|
|
340
|
-
// Allowlist of safe invocation parameters to include
|
|
341
|
-
const allowedInvocationKeys = new Set([
|
|
342
|
-
"frequency_penalty",
|
|
343
|
-
"n",
|
|
344
|
-
"logit_bias",
|
|
345
|
-
"logprobs",
|
|
346
|
-
"modalities",
|
|
347
|
-
"parallel_tool_calls",
|
|
348
|
-
"prediction",
|
|
349
|
-
"presence_penalty",
|
|
350
|
-
"prompt_cache_key",
|
|
351
|
-
"reasoning",
|
|
352
|
-
"reasoning_effort",
|
|
353
|
-
"response_format",
|
|
354
|
-
"seed",
|
|
355
|
-
"service_tier",
|
|
356
|
-
"stream_options",
|
|
357
|
-
"top_logprobs",
|
|
358
|
-
"top_p",
|
|
359
|
-
"truncation",
|
|
360
|
-
"user",
|
|
361
|
-
"verbosity",
|
|
362
|
-
"web_search_options",
|
|
363
|
-
]);
|
|
364
339
|
const ls_invocation_params = {};
|
|
365
340
|
for (const [key, value] of Object.entries(params)) {
|
|
366
|
-
if (
|
|
341
|
+
if (TRACED_INVOCATION_KEYS.includes(key)) {
|
|
367
342
|
ls_invocation_params[key] = value;
|
|
368
343
|
}
|
|
369
344
|
}
|
|
@@ -403,7 +378,51 @@ export const wrapOpenAI = (openai, options) => {
|
|
|
403
378
|
const params = payload;
|
|
404
379
|
return {
|
|
405
380
|
ls_provider: provider,
|
|
406
|
-
ls_model_type: "
|
|
381
|
+
ls_model_type: "chat",
|
|
382
|
+
ls_model_name: params.model || "unknown",
|
|
383
|
+
};
|
|
384
|
+
},
|
|
385
|
+
processOutputs: processChatCompletion,
|
|
386
|
+
...options,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
if (tracedOpenAIClient.responses &&
|
|
390
|
+
typeof tracedOpenAIClient.responses.parse === "function") {
|
|
391
|
+
tracedOpenAIClient.responses.parse = traceable(openai.responses.parse.bind(openai.responses), {
|
|
392
|
+
name: chatName,
|
|
393
|
+
run_type: "llm",
|
|
394
|
+
aggregator: responsesAggregator,
|
|
395
|
+
argsConfigPath: [1, "langsmithExtra"],
|
|
396
|
+
getInvocationParams: (payload) => {
|
|
397
|
+
if (typeof payload !== "object" || payload == null)
|
|
398
|
+
return undefined;
|
|
399
|
+
// Handle responses API parameters
|
|
400
|
+
const params = payload;
|
|
401
|
+
return {
|
|
402
|
+
ls_provider: provider,
|
|
403
|
+
ls_model_type: "chat",
|
|
404
|
+
ls_model_name: params.model || "unknown",
|
|
405
|
+
};
|
|
406
|
+
},
|
|
407
|
+
processOutputs: processChatCompletion,
|
|
408
|
+
...options,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
if (tracedOpenAIClient.responses &&
|
|
412
|
+
typeof tracedOpenAIClient.responses.stream === "function") {
|
|
413
|
+
tracedOpenAIClient.responses.stream = traceable(openai.responses.stream.bind(openai.responses), {
|
|
414
|
+
name: chatName,
|
|
415
|
+
run_type: "llm",
|
|
416
|
+
aggregator: responsesAggregator,
|
|
417
|
+
argsConfigPath: [1, "langsmithExtra"],
|
|
418
|
+
getInvocationParams: (payload) => {
|
|
419
|
+
if (typeof payload !== "object" || payload == null)
|
|
420
|
+
return undefined;
|
|
421
|
+
// Handle responses API parameters
|
|
422
|
+
const params = payload;
|
|
423
|
+
return {
|
|
424
|
+
ls_provider: provider,
|
|
425
|
+
ls_model_type: "chat",
|
|
407
426
|
ls_model_name: params.model || "unknown",
|
|
408
427
|
};
|
|
409
428
|
},
|