langsmith 0.1.19 → 0.1.20
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.d.ts +5 -4
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/traceable.cjs +31 -15
- package/dist/traceable.js +31 -15
- package/dist/utils/messages.cjs +3 -1
- package/dist/utils/messages.js +3 -1
- package/package.json +3 -2
package/dist/client.d.ts
CHANGED
|
@@ -138,6 +138,7 @@ interface ProjectOptions {
|
|
|
138
138
|
projectName?: string;
|
|
139
139
|
projectId?: string;
|
|
140
140
|
}
|
|
141
|
+
type RecordStringAny = Record<string, any>;
|
|
141
142
|
export type FeedbackSourceType = "model" | "api" | "app";
|
|
142
143
|
export type CreateExampleOptions = {
|
|
143
144
|
datasetId?: string;
|
|
@@ -313,16 +314,16 @@ export declare class Client {
|
|
|
313
314
|
createProject({ projectName, description, metadata, upsert, projectExtra, referenceDatasetId, }: {
|
|
314
315
|
projectName: string;
|
|
315
316
|
description?: string | null;
|
|
316
|
-
metadata?:
|
|
317
|
+
metadata?: RecordStringAny | null;
|
|
317
318
|
upsert?: boolean;
|
|
318
|
-
projectExtra?:
|
|
319
|
+
projectExtra?: RecordStringAny | null;
|
|
319
320
|
referenceDatasetId?: string | null;
|
|
320
321
|
}): Promise<TracerSession>;
|
|
321
322
|
updateProject(projectId: string, { name, description, metadata, projectExtra, endTime, }: {
|
|
322
323
|
name?: string | null;
|
|
323
324
|
description?: string | null;
|
|
324
|
-
metadata?:
|
|
325
|
-
projectExtra?:
|
|
325
|
+
metadata?: RecordStringAny | null;
|
|
326
|
+
projectExtra?: RecordStringAny | null;
|
|
326
327
|
endTime?: string | null;
|
|
327
328
|
}): Promise<TracerSession>;
|
|
328
329
|
hasProject({ projectId, projectName, }: {
|
package/dist/index.cjs
CHANGED
|
@@ -6,4 +6,4 @@ Object.defineProperty(exports, "Client", { enumerable: true, get: function () {
|
|
|
6
6
|
var run_trees_js_1 = require("./run_trees.cjs");
|
|
7
7
|
Object.defineProperty(exports, "RunTree", { enumerable: true, get: function () { return run_trees_js_1.RunTree; } });
|
|
8
8
|
// Update using yarn bump-version
|
|
9
|
-
exports.__version__ = "0.1.
|
|
9
|
+
exports.__version__ = "0.1.20";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Client } from "./client.js";
|
|
2
2
|
export type { Dataset, Example, TracerSession, Run, Feedback, } from "./schemas.js";
|
|
3
3
|
export { RunTree, type RunTreeConfig } from "./run_trees.js";
|
|
4
|
-
export declare const __version__ = "0.1.
|
|
4
|
+
export declare const __version__ = "0.1.20";
|
package/dist/index.js
CHANGED
package/dist/traceable.cjs
CHANGED
|
@@ -3,11 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isTraceableFunction = exports.getCurrentRunTree = exports.traceable = void 0;
|
|
4
4
|
const async_hooks_1 = require("async_hooks");
|
|
5
5
|
const run_trees_js_1 = require("./run_trees.cjs");
|
|
6
|
+
const env_js_1 = require("./utils/env.cjs");
|
|
6
7
|
const asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
7
8
|
const isAsyncIterable = (x) => x != null &&
|
|
8
9
|
typeof x === "object" &&
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
11
|
typeof x[Symbol.asyncIterator] === "function";
|
|
12
|
+
const getTracingRunTree = (runTree) => {
|
|
13
|
+
const tracingEnabled = (0, env_js_1.getEnvironmentVariable)("LANGSMITH_TRACING_V2") === "true" ||
|
|
14
|
+
(0, env_js_1.getEnvironmentVariable)("LANGCHAIN_TRACING_V2") === "true";
|
|
15
|
+
if (!tracingEnabled) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return runTree;
|
|
19
|
+
};
|
|
11
20
|
/**
|
|
12
21
|
* Higher-order function that takes function as input and returns a
|
|
13
22
|
* "TraceableFunction" - a wrapped version of the input that
|
|
@@ -49,6 +58,7 @@ function traceable(wrappedFunc, config) {
|
|
|
49
58
|
currentRunTree = new run_trees_js_1.RunTree(ensuredConfig);
|
|
50
59
|
rawInputs = args;
|
|
51
60
|
}
|
|
61
|
+
currentRunTree = getTracingRunTree(currentRunTree);
|
|
52
62
|
let inputs;
|
|
53
63
|
const firstInput = rawInputs[0];
|
|
54
64
|
if (firstInput == null) {
|
|
@@ -63,10 +73,12 @@ function traceable(wrappedFunc, config) {
|
|
|
63
73
|
else {
|
|
64
74
|
inputs = { input: firstInput };
|
|
65
75
|
}
|
|
66
|
-
currentRunTree
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
if (currentRunTree) {
|
|
77
|
+
currentRunTree.inputs = inputs;
|
|
78
|
+
}
|
|
79
|
+
const initialOutputs = currentRunTree?.outputs;
|
|
80
|
+
const initialError = currentRunTree?.error;
|
|
81
|
+
await currentRunTree?.postRun();
|
|
70
82
|
return new Promise((resolve, reject) => {
|
|
71
83
|
void asyncLocalStorage.run(currentRunTree, async () => {
|
|
72
84
|
try {
|
|
@@ -95,12 +107,12 @@ function traceable(wrappedFunc, config) {
|
|
|
95
107
|
}
|
|
96
108
|
if (typeof finalOutputs === "object" &&
|
|
97
109
|
!Array.isArray(finalOutputs)) {
|
|
98
|
-
await currentRunTree
|
|
110
|
+
await currentRunTree?.end(finalOutputs);
|
|
99
111
|
}
|
|
100
112
|
else {
|
|
101
|
-
await currentRunTree
|
|
113
|
+
await currentRunTree?.end({ outputs: finalOutputs });
|
|
102
114
|
}
|
|
103
|
-
await currentRunTree
|
|
115
|
+
await currentRunTree?.patchRun();
|
|
104
116
|
}
|
|
105
117
|
return resolve(wrapOutputForTracing());
|
|
106
118
|
}
|
|
@@ -108,24 +120,28 @@ function traceable(wrappedFunc, config) {
|
|
|
108
120
|
const outputs = isKVMap(rawOutput)
|
|
109
121
|
? rawOutput
|
|
110
122
|
: { outputs: rawOutput };
|
|
111
|
-
if (initialOutputs === currentRunTree
|
|
112
|
-
await currentRunTree
|
|
123
|
+
if (initialOutputs === currentRunTree?.outputs) {
|
|
124
|
+
await currentRunTree?.end(outputs);
|
|
113
125
|
}
|
|
114
126
|
else {
|
|
115
|
-
currentRunTree
|
|
127
|
+
if (currentRunTree !== undefined) {
|
|
128
|
+
currentRunTree.end_time = Date.now();
|
|
129
|
+
}
|
|
116
130
|
}
|
|
117
|
-
await currentRunTree
|
|
131
|
+
await currentRunTree?.patchRun();
|
|
118
132
|
return resolve(rawOutput);
|
|
119
133
|
}
|
|
120
134
|
}
|
|
121
135
|
catch (error) {
|
|
122
|
-
if (initialError === currentRunTree
|
|
123
|
-
await currentRunTree
|
|
136
|
+
if (initialError === currentRunTree?.error) {
|
|
137
|
+
await currentRunTree?.end(initialOutputs, String(error));
|
|
124
138
|
}
|
|
125
139
|
else {
|
|
126
|
-
currentRunTree
|
|
140
|
+
if (currentRunTree !== undefined) {
|
|
141
|
+
currentRunTree.end_time = Date.now();
|
|
142
|
+
}
|
|
127
143
|
}
|
|
128
|
-
await currentRunTree
|
|
144
|
+
await currentRunTree?.patchRun();
|
|
129
145
|
reject(error);
|
|
130
146
|
}
|
|
131
147
|
});
|
package/dist/traceable.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "async_hooks";
|
|
2
2
|
import { RunTree, isRunTree, isRunnableConfigLike, } from "./run_trees.js";
|
|
3
|
+
import { getEnvironmentVariable } from "./utils/env.js";
|
|
3
4
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
4
5
|
const isAsyncIterable = (x) => x != null &&
|
|
5
6
|
typeof x === "object" &&
|
|
6
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
8
|
typeof x[Symbol.asyncIterator] === "function";
|
|
9
|
+
const getTracingRunTree = (runTree) => {
|
|
10
|
+
const tracingEnabled = getEnvironmentVariable("LANGSMITH_TRACING_V2") === "true" ||
|
|
11
|
+
getEnvironmentVariable("LANGCHAIN_TRACING_V2") === "true";
|
|
12
|
+
if (!tracingEnabled) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return runTree;
|
|
16
|
+
};
|
|
8
17
|
/**
|
|
9
18
|
* Higher-order function that takes function as input and returns a
|
|
10
19
|
* "TraceableFunction" - a wrapped version of the input that
|
|
@@ -46,6 +55,7 @@ export function traceable(wrappedFunc, config) {
|
|
|
46
55
|
currentRunTree = new RunTree(ensuredConfig);
|
|
47
56
|
rawInputs = args;
|
|
48
57
|
}
|
|
58
|
+
currentRunTree = getTracingRunTree(currentRunTree);
|
|
49
59
|
let inputs;
|
|
50
60
|
const firstInput = rawInputs[0];
|
|
51
61
|
if (firstInput == null) {
|
|
@@ -60,10 +70,12 @@ export function traceable(wrappedFunc, config) {
|
|
|
60
70
|
else {
|
|
61
71
|
inputs = { input: firstInput };
|
|
62
72
|
}
|
|
63
|
-
currentRunTree
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
if (currentRunTree) {
|
|
74
|
+
currentRunTree.inputs = inputs;
|
|
75
|
+
}
|
|
76
|
+
const initialOutputs = currentRunTree?.outputs;
|
|
77
|
+
const initialError = currentRunTree?.error;
|
|
78
|
+
await currentRunTree?.postRun();
|
|
67
79
|
return new Promise((resolve, reject) => {
|
|
68
80
|
void asyncLocalStorage.run(currentRunTree, async () => {
|
|
69
81
|
try {
|
|
@@ -92,12 +104,12 @@ export function traceable(wrappedFunc, config) {
|
|
|
92
104
|
}
|
|
93
105
|
if (typeof finalOutputs === "object" &&
|
|
94
106
|
!Array.isArray(finalOutputs)) {
|
|
95
|
-
await currentRunTree
|
|
107
|
+
await currentRunTree?.end(finalOutputs);
|
|
96
108
|
}
|
|
97
109
|
else {
|
|
98
|
-
await currentRunTree
|
|
110
|
+
await currentRunTree?.end({ outputs: finalOutputs });
|
|
99
111
|
}
|
|
100
|
-
await currentRunTree
|
|
112
|
+
await currentRunTree?.patchRun();
|
|
101
113
|
}
|
|
102
114
|
return resolve(wrapOutputForTracing());
|
|
103
115
|
}
|
|
@@ -105,24 +117,28 @@ export function traceable(wrappedFunc, config) {
|
|
|
105
117
|
const outputs = isKVMap(rawOutput)
|
|
106
118
|
? rawOutput
|
|
107
119
|
: { outputs: rawOutput };
|
|
108
|
-
if (initialOutputs === currentRunTree
|
|
109
|
-
await currentRunTree
|
|
120
|
+
if (initialOutputs === currentRunTree?.outputs) {
|
|
121
|
+
await currentRunTree?.end(outputs);
|
|
110
122
|
}
|
|
111
123
|
else {
|
|
112
|
-
currentRunTree
|
|
124
|
+
if (currentRunTree !== undefined) {
|
|
125
|
+
currentRunTree.end_time = Date.now();
|
|
126
|
+
}
|
|
113
127
|
}
|
|
114
|
-
await currentRunTree
|
|
128
|
+
await currentRunTree?.patchRun();
|
|
115
129
|
return resolve(rawOutput);
|
|
116
130
|
}
|
|
117
131
|
}
|
|
118
132
|
catch (error) {
|
|
119
|
-
if (initialError === currentRunTree
|
|
120
|
-
await currentRunTree
|
|
133
|
+
if (initialError === currentRunTree?.error) {
|
|
134
|
+
await currentRunTree?.end(initialOutputs, String(error));
|
|
121
135
|
}
|
|
122
136
|
else {
|
|
123
|
-
currentRunTree
|
|
137
|
+
if (currentRunTree !== undefined) {
|
|
138
|
+
currentRunTree.end_time = Date.now();
|
|
139
|
+
}
|
|
124
140
|
}
|
|
125
|
-
await currentRunTree
|
|
141
|
+
await currentRunTree?.patchRun();
|
|
126
142
|
reject(error);
|
|
127
143
|
}
|
|
128
144
|
});
|
package/dist/utils/messages.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertLangChainMessageToExample = exports.isLangChainMessage = void 0;
|
|
4
|
-
function isLangChainMessage(
|
|
4
|
+
function isLangChainMessage(
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
message) {
|
|
5
7
|
return typeof message?._getType === "function";
|
|
6
8
|
}
|
|
7
9
|
exports.isLangChainMessage = isLangChainMessage;
|
package/dist/utils/messages.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export function isLangChainMessage(
|
|
1
|
+
export function isLangChainMessage(
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
|
+
message) {
|
|
2
4
|
return typeof message?._getType === "function";
|
|
3
5
|
}
|
|
4
6
|
export function convertLangChainMessageToExample(message) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langsmith",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
|
|
5
5
|
"packageManager": "yarn@1.22.19",
|
|
6
6
|
"files": [
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests --testPathIgnorePatterns='\\.int\\.test.[tj]s' --testTimeout 30000",
|
|
53
53
|
"test:integration": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000",
|
|
54
54
|
"test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
|
|
55
|
-
"lint": "eslint
|
|
55
|
+
"lint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
|
|
56
|
+
"lint:fix": "yarn lint --fix",
|
|
56
57
|
"format": "prettier --write 'src/**/*.{ts,tsx}'",
|
|
57
58
|
"format:check": "prettier --check 'src/**/*.{ts,tsx}'",
|
|
58
59
|
"precommit": "lint-staged",
|