langsmith 0.1.38 → 0.1.39-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/README.md +0 -1
- package/dist/client.cjs +0 -18
- package/dist/client.d.ts +1 -2
- package/dist/client.js +0 -18
- package/dist/langchain.cjs +14 -6
- package/dist/langchain.js +14 -6
- package/dist/run_trees.cjs +34 -6
- package/dist/run_trees.d.ts +16 -0
- package/dist/run_trees.js +32 -5
- package/dist/schemas.d.ts +0 -3
- package/dist/singletons/traceable.cjs +8 -18
- package/dist/singletons/traceable.d.ts +0 -2
- package/dist/singletons/traceable.js +8 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,7 +53,6 @@ Tracing can be activated by setting the following environment variables or by ma
|
|
|
53
53
|
```typescript
|
|
54
54
|
process.env["LANGSMITH_TRACING"] = "true";
|
|
55
55
|
process.env["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com";
|
|
56
|
-
// process.env["LANGCHAIN_ENDPOINT"] = "https://eu.api.smith.langchain.com"; // If signed up in the EU region
|
|
57
56
|
process.env["LANGCHAIN_API_KEY"] = "<YOUR-LANGSMITH-API-KEY>";
|
|
58
57
|
// process.env["LANGCHAIN_PROJECT"] = "My Project Name"; // Optional: "default" is used if not set
|
|
59
58
|
```
|
package/dist/client.cjs
CHANGED
|
@@ -319,10 +319,6 @@ class Client {
|
|
|
319
319
|
this.webUrl = "https://dev.smith.langchain.com";
|
|
320
320
|
return this.webUrl;
|
|
321
321
|
}
|
|
322
|
-
else if (this.apiUrl.split(".", 1)[0].includes("eu")) {
|
|
323
|
-
this.webUrl = "https://eu.smith.langchain.com";
|
|
324
|
-
return this.webUrl;
|
|
325
|
-
}
|
|
326
322
|
else {
|
|
327
323
|
this.webUrl = "https://smith.langchain.com";
|
|
328
324
|
return this.webUrl;
|
|
@@ -1663,20 +1659,6 @@ class Client {
|
|
|
1663
1659
|
const result = await response.json();
|
|
1664
1660
|
return result;
|
|
1665
1661
|
}
|
|
1666
|
-
async updateExamples(update) {
|
|
1667
|
-
const response = await this.caller.call(fetch, `${this.apiUrl}/examples/bulk`, {
|
|
1668
|
-
method: "PATCH",
|
|
1669
|
-
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1670
|
-
body: JSON.stringify(update),
|
|
1671
|
-
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1672
|
-
...this.fetchOptions,
|
|
1673
|
-
});
|
|
1674
|
-
if (!response.ok) {
|
|
1675
|
-
throw new Error(`Failed to update examples: ${response.status} ${response.statusText}`);
|
|
1676
|
-
}
|
|
1677
|
-
const result = await response.json();
|
|
1678
|
-
return result;
|
|
1679
|
-
}
|
|
1680
1662
|
async listDatasetSplits({ datasetId, datasetName, asOf, }) {
|
|
1681
1663
|
let datasetId_;
|
|
1682
1664
|
if (datasetId === undefined && datasetName === undefined) {
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncCallerParams } from "./utils/async_caller.js";
|
|
2
|
-
import { ComparativeExperiment, DataType, Dataset, DatasetDiffInfo, DatasetShareSchema, Example, ExampleUpdate,
|
|
2
|
+
import { ComparativeExperiment, DataType, Dataset, DatasetDiffInfo, DatasetShareSchema, Example, ExampleUpdate, Feedback, FeedbackConfig, FeedbackIngestToken, KVMap, LangChainBaseMessage, Run, RunCreate, RunUpdate, ScoreType, TimeDelta, TracerSession, TracerSessionResult, ValueType } from "./schemas.js";
|
|
3
3
|
import { EvaluationResult, EvaluationResults, RunEvaluator } from "./evaluation/evaluator.js";
|
|
4
4
|
interface ClientConfig {
|
|
5
5
|
apiUrl?: string;
|
|
@@ -430,7 +430,6 @@ export declare class Client {
|
|
|
430
430
|
}): AsyncIterable<Example>;
|
|
431
431
|
deleteExample(exampleId: string): Promise<void>;
|
|
432
432
|
updateExample(exampleId: string, update: ExampleUpdate): Promise<object>;
|
|
433
|
-
updateExamples(update: ExampleUpdateWithId[]): Promise<object>;
|
|
434
433
|
listDatasetSplits({ datasetId, datasetName, asOf, }: {
|
|
435
434
|
datasetId?: string;
|
|
436
435
|
datasetName?: string;
|
package/dist/client.js
CHANGED
|
@@ -292,10 +292,6 @@ export class Client {
|
|
|
292
292
|
this.webUrl = "https://dev.smith.langchain.com";
|
|
293
293
|
return this.webUrl;
|
|
294
294
|
}
|
|
295
|
-
else if (this.apiUrl.split(".", 1)[0].includes("eu")) {
|
|
296
|
-
this.webUrl = "https://eu.smith.langchain.com";
|
|
297
|
-
return this.webUrl;
|
|
298
|
-
}
|
|
299
295
|
else {
|
|
300
296
|
this.webUrl = "https://smith.langchain.com";
|
|
301
297
|
return this.webUrl;
|
|
@@ -1636,20 +1632,6 @@ export class Client {
|
|
|
1636
1632
|
const result = await response.json();
|
|
1637
1633
|
return result;
|
|
1638
1634
|
}
|
|
1639
|
-
async updateExamples(update) {
|
|
1640
|
-
const response = await this.caller.call(fetch, `${this.apiUrl}/examples/bulk`, {
|
|
1641
|
-
method: "PATCH",
|
|
1642
|
-
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1643
|
-
body: JSON.stringify(update),
|
|
1644
|
-
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1645
|
-
...this.fetchOptions,
|
|
1646
|
-
});
|
|
1647
|
-
if (!response.ok) {
|
|
1648
|
-
throw new Error(`Failed to update examples: ${response.status} ${response.statusText}`);
|
|
1649
|
-
}
|
|
1650
|
-
const result = await response.json();
|
|
1651
|
-
return result;
|
|
1652
|
-
}
|
|
1653
1635
|
async listDatasetSplits({ datasetId, datasetName, asOf, }) {
|
|
1654
1636
|
let datasetId_;
|
|
1655
1637
|
if (datasetId === undefined && datasetName === undefined) {
|
package/dist/langchain.cjs
CHANGED
|
@@ -55,12 +55,20 @@ async function getLangchainCallbacks(currentRunTree) {
|
|
|
55
55
|
Object.assign(callbacks, { _parentRunId: runTree.id });
|
|
56
56
|
}
|
|
57
57
|
if (langChainTracer != null) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
58
|
+
if ("updateFromRunTree" in langChainTracer &&
|
|
59
|
+
typeof langChainTracer === "function") {
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
61
|
+
// @ts-ignore @langchain/core can use a different version of LangSmith
|
|
62
|
+
langChainTracer.updateFromRunTree(runTree);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
Object.assign(langChainTracer, {
|
|
66
|
+
runMap,
|
|
67
|
+
client: runTree.client,
|
|
68
|
+
projectName: runTree.project_name || langChainTracer.projectName,
|
|
69
|
+
exampleId: runTree.reference_example_id || langChainTracer.exampleId,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
64
72
|
}
|
|
65
73
|
return callbacks;
|
|
66
74
|
}
|
package/dist/langchain.js
CHANGED
|
@@ -52,12 +52,20 @@ export async function getLangchainCallbacks(currentRunTree) {
|
|
|
52
52
|
Object.assign(callbacks, { _parentRunId: runTree.id });
|
|
53
53
|
}
|
|
54
54
|
if (langChainTracer != null) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
55
|
+
if ("updateFromRunTree" in langChainTracer &&
|
|
56
|
+
typeof langChainTracer === "function") {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
58
|
+
// @ts-ignore @langchain/core can use a different version of LangSmith
|
|
59
|
+
langChainTracer.updateFromRunTree(runTree);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
Object.assign(langChainTracer, {
|
|
63
|
+
runMap,
|
|
64
|
+
client: runTree.client,
|
|
65
|
+
projectName: runTree.project_name || langChainTracer.projectName,
|
|
66
|
+
exampleId: runTree.reference_example_id || langChainTracer.exampleId,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
61
69
|
}
|
|
62
70
|
return callbacks;
|
|
63
71
|
}
|
package/dist/run_trees.cjs
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isRunnableConfigLike = exports.isRunTree = exports.RunTree = exports.convertToDottedOrderFormat = void 0;
|
|
26
|
+
exports.isRunnableConfigLike = exports.isCallbackManagerLike = exports.isRunTree = exports.RunTree = exports.convertToDottedOrderFormat = void 0;
|
|
27
27
|
const uuid = __importStar(require("uuid"));
|
|
28
28
|
const env_js_1 = require("./utils/env.cjs");
|
|
29
29
|
const client_js_1 = require("./client.cjs");
|
|
@@ -278,6 +278,26 @@ class RunTree {
|
|
|
278
278
|
execution_order: child_execution_order,
|
|
279
279
|
child_execution_order: child_execution_order,
|
|
280
280
|
});
|
|
281
|
+
const LC_CHILD = Symbol.for("lc:child_config");
|
|
282
|
+
const presentConfig = config.extra?.[LC_CHILD] ??
|
|
283
|
+
this.extra[LC_CHILD];
|
|
284
|
+
// tracing for LangChain is defined by the _parentRunId and runMap of the tracer
|
|
285
|
+
if (isRunnableConfigLike(presentConfig)) {
|
|
286
|
+
const newConfig = { ...presentConfig };
|
|
287
|
+
const callbacks = isCallbackManagerLike(newConfig.callbacks)
|
|
288
|
+
? newConfig.callbacks.copy?.()
|
|
289
|
+
: undefined;
|
|
290
|
+
if (callbacks) {
|
|
291
|
+
// update the parent run id
|
|
292
|
+
Object.assign(callbacks, { _parentRunId: child.id });
|
|
293
|
+
// only populate if we're in a newer LC.JS version
|
|
294
|
+
callbacks.handlers
|
|
295
|
+
?.find(isLangChainTracerLike)
|
|
296
|
+
?.updateFromRunTree?.(child);
|
|
297
|
+
newConfig.callbacks = callbacks;
|
|
298
|
+
}
|
|
299
|
+
child.extra[LC_CHILD] = newConfig;
|
|
300
|
+
}
|
|
281
301
|
// propagate child_execution_order upwards
|
|
282
302
|
const visited = new Set();
|
|
283
303
|
let current = this;
|
|
@@ -463,13 +483,21 @@ function isRunTree(x) {
|
|
|
463
483
|
typeof x.postRun === "function");
|
|
464
484
|
}
|
|
465
485
|
exports.isRunTree = isRunTree;
|
|
486
|
+
function isLangChainTracerLike(x) {
|
|
487
|
+
return (typeof x === "object" &&
|
|
488
|
+
x != null &&
|
|
489
|
+
typeof x.name === "string" &&
|
|
490
|
+
x.name === "langchain_tracer");
|
|
491
|
+
}
|
|
466
492
|
function containsLangChainTracerLike(x) {
|
|
467
|
-
return (Array.isArray(x) &&
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
493
|
+
return (Array.isArray(x) && x.some((callback) => isLangChainTracerLike(callback)));
|
|
494
|
+
}
|
|
495
|
+
function isCallbackManagerLike(x) {
|
|
496
|
+
return (typeof x === "object" &&
|
|
497
|
+
x != null &&
|
|
498
|
+
Array.isArray(x.handlers));
|
|
472
499
|
}
|
|
500
|
+
exports.isCallbackManagerLike = isCallbackManagerLike;
|
|
473
501
|
function isRunnableConfigLike(x) {
|
|
474
502
|
// Check that it's an object with a callbacks arg
|
|
475
503
|
// that has either a CallbackManagerLike object with a langchain tracer within it
|
package/dist/run_trees.d.ts
CHANGED
|
@@ -44,6 +44,21 @@ export interface RunnableConfigLike {
|
|
|
44
44
|
*/
|
|
45
45
|
callbacks?: any;
|
|
46
46
|
}
|
|
47
|
+
interface CallbackManagerLike {
|
|
48
|
+
handlers: TracerLike[];
|
|
49
|
+
getParentRunId?: () => string | undefined;
|
|
50
|
+
copy?: () => CallbackManagerLike;
|
|
51
|
+
}
|
|
52
|
+
interface TracerLike {
|
|
53
|
+
name: string;
|
|
54
|
+
}
|
|
55
|
+
export interface LangChainTracerLike extends TracerLike {
|
|
56
|
+
name: "langchain_tracer";
|
|
57
|
+
projectName: string;
|
|
58
|
+
getRun?: (id: string) => RunTree | undefined;
|
|
59
|
+
client: Client;
|
|
60
|
+
updateFromRunTree?: (runTree: RunTree) => void;
|
|
61
|
+
}
|
|
47
62
|
interface HeadersLike {
|
|
48
63
|
get(name: string): string | null;
|
|
49
64
|
set(name: string, value: string): void;
|
|
@@ -88,5 +103,6 @@ export declare class RunTree implements BaseRun {
|
|
|
88
103
|
};
|
|
89
104
|
}
|
|
90
105
|
export declare function isRunTree(x?: unknown): x is RunTree;
|
|
106
|
+
export declare function isCallbackManagerLike(x: unknown): x is CallbackManagerLike;
|
|
91
107
|
export declare function isRunnableConfigLike(x?: unknown): x is RunnableConfigLike;
|
|
92
108
|
export {};
|
package/dist/run_trees.js
CHANGED
|
@@ -251,6 +251,26 @@ export class RunTree {
|
|
|
251
251
|
execution_order: child_execution_order,
|
|
252
252
|
child_execution_order: child_execution_order,
|
|
253
253
|
});
|
|
254
|
+
const LC_CHILD = Symbol.for("lc:child_config");
|
|
255
|
+
const presentConfig = config.extra?.[LC_CHILD] ??
|
|
256
|
+
this.extra[LC_CHILD];
|
|
257
|
+
// tracing for LangChain is defined by the _parentRunId and runMap of the tracer
|
|
258
|
+
if (isRunnableConfigLike(presentConfig)) {
|
|
259
|
+
const newConfig = { ...presentConfig };
|
|
260
|
+
const callbacks = isCallbackManagerLike(newConfig.callbacks)
|
|
261
|
+
? newConfig.callbacks.copy?.()
|
|
262
|
+
: undefined;
|
|
263
|
+
if (callbacks) {
|
|
264
|
+
// update the parent run id
|
|
265
|
+
Object.assign(callbacks, { _parentRunId: child.id });
|
|
266
|
+
// only populate if we're in a newer LC.JS version
|
|
267
|
+
callbacks.handlers
|
|
268
|
+
?.find(isLangChainTracerLike)
|
|
269
|
+
?.updateFromRunTree?.(child);
|
|
270
|
+
newConfig.callbacks = callbacks;
|
|
271
|
+
}
|
|
272
|
+
child.extra[LC_CHILD] = newConfig;
|
|
273
|
+
}
|
|
254
274
|
// propagate child_execution_order upwards
|
|
255
275
|
const visited = new Set();
|
|
256
276
|
let current = this;
|
|
@@ -434,12 +454,19 @@ export function isRunTree(x) {
|
|
|
434
454
|
typeof x.createChild === "function" &&
|
|
435
455
|
typeof x.postRun === "function");
|
|
436
456
|
}
|
|
457
|
+
function isLangChainTracerLike(x) {
|
|
458
|
+
return (typeof x === "object" &&
|
|
459
|
+
x != null &&
|
|
460
|
+
typeof x.name === "string" &&
|
|
461
|
+
x.name === "langchain_tracer");
|
|
462
|
+
}
|
|
437
463
|
function containsLangChainTracerLike(x) {
|
|
438
|
-
return (Array.isArray(x) &&
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
464
|
+
return (Array.isArray(x) && x.some((callback) => isLangChainTracerLike(callback)));
|
|
465
|
+
}
|
|
466
|
+
export function isCallbackManagerLike(x) {
|
|
467
|
+
return (typeof x === "object" &&
|
|
468
|
+
x != null &&
|
|
469
|
+
Array.isArray(x.handlers));
|
|
443
470
|
}
|
|
444
471
|
export function isRunnableConfigLike(x) {
|
|
445
472
|
// Check that it's an object with a callbacks arg
|
package/dist/schemas.d.ts
CHANGED
|
@@ -178,9 +178,6 @@ export interface ExampleUpdate {
|
|
|
178
178
|
metadata?: KVMap;
|
|
179
179
|
split?: string | string[];
|
|
180
180
|
}
|
|
181
|
-
export interface ExampleUpdateWithId extends ExampleUpdate {
|
|
182
|
-
id: string;
|
|
183
|
-
}
|
|
184
181
|
export interface BaseDataset {
|
|
185
182
|
name: string;
|
|
186
183
|
description: string;
|
|
@@ -9,28 +9,18 @@ class MockAsyncLocalStorage {
|
|
|
9
9
|
return callback();
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
+
const TRACING_ALS_KEY = Symbol.for("ls:tracing_async_local_storage");
|
|
13
|
+
const mockAsyncLocalStorage = new MockAsyncLocalStorage();
|
|
12
14
|
class AsyncLocalStorageProvider {
|
|
13
|
-
constructor() {
|
|
14
|
-
Object.defineProperty(this, "asyncLocalStorage", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true,
|
|
18
|
-
value: new MockAsyncLocalStorage()
|
|
19
|
-
});
|
|
20
|
-
Object.defineProperty(this, "hasBeenInitialized", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
configurable: true,
|
|
23
|
-
writable: true,
|
|
24
|
-
value: false
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
15
|
getInstance() {
|
|
28
|
-
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
return globalThis[TRACING_ALS_KEY] ?? mockAsyncLocalStorage;
|
|
29
18
|
}
|
|
30
19
|
initializeGlobalInstance(instance) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
if (globalThis[TRACING_ALS_KEY] === undefined) {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
globalThis[TRACING_ALS_KEY] = instance;
|
|
34
24
|
}
|
|
35
25
|
}
|
|
36
26
|
}
|
|
@@ -5,8 +5,6 @@ interface AsyncLocalStorageInterface {
|
|
|
5
5
|
run: (context: RunTree | undefined, fn: () => void) => void;
|
|
6
6
|
}
|
|
7
7
|
declare class AsyncLocalStorageProvider {
|
|
8
|
-
private asyncLocalStorage;
|
|
9
|
-
private hasBeenInitialized;
|
|
10
8
|
getInstance(): AsyncLocalStorageInterface;
|
|
11
9
|
initializeGlobalInstance(instance: AsyncLocalStorageInterface): void;
|
|
12
10
|
}
|
|
@@ -6,28 +6,18 @@ class MockAsyncLocalStorage {
|
|
|
6
6
|
return callback();
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
const TRACING_ALS_KEY = Symbol.for("ls:tracing_async_local_storage");
|
|
10
|
+
const mockAsyncLocalStorage = new MockAsyncLocalStorage();
|
|
9
11
|
class AsyncLocalStorageProvider {
|
|
10
|
-
constructor() {
|
|
11
|
-
Object.defineProperty(this, "asyncLocalStorage", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: new MockAsyncLocalStorage()
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(this, "hasBeenInitialized", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: false
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
12
|
getInstance() {
|
|
25
|
-
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
return globalThis[TRACING_ALS_KEY] ?? mockAsyncLocalStorage;
|
|
26
15
|
}
|
|
27
16
|
initializeGlobalInstance(instance) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
if (globalThis[TRACING_ALS_KEY] === undefined) {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
globalThis[TRACING_ALS_KEY] = instance;
|
|
31
21
|
}
|
|
32
22
|
}
|
|
33
23
|
}
|