langsmith 0.0.62 → 0.0.66
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 +71 -18
- package/dist/client.d.ts +16 -1
- package/dist/client.js +71 -18
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run_trees.cjs +39 -21
- package/dist/run_trees.d.ts +3 -4
- package/dist/run_trees.js +37 -20
- package/dist/schemas.d.ts +1 -5
- package/dist/utils/async_caller.cjs +10 -3
- package/dist/utils/async_caller.js +10 -3
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -59,18 +59,6 @@ function trimQuotes(str) {
|
|
|
59
59
|
.replace(/^"(.*)"$/, "$1")
|
|
60
60
|
.replace(/^'(.*)'$/, "$1");
|
|
61
61
|
}
|
|
62
|
-
function hideInputs(inputs) {
|
|
63
|
-
if ((0, env_js_1.getEnvironmentVariable)("LANGCHAIN_HIDE_INPUTS") === "true") {
|
|
64
|
-
return {};
|
|
65
|
-
}
|
|
66
|
-
return inputs;
|
|
67
|
-
}
|
|
68
|
-
function hideOutputs(outputs) {
|
|
69
|
-
if ((0, env_js_1.getEnvironmentVariable)("LANGCHAIN_HIDE_OUTPUTS") === "true") {
|
|
70
|
-
return {};
|
|
71
|
-
}
|
|
72
|
-
return outputs;
|
|
73
|
-
}
|
|
74
62
|
function assertUuid(str) {
|
|
75
63
|
if (!uuid.validate(str)) {
|
|
76
64
|
throw new Error(`Invalid UUID: ${str}`);
|
|
@@ -114,22 +102,40 @@ class Client {
|
|
|
114
102
|
writable: true,
|
|
115
103
|
value: null
|
|
116
104
|
});
|
|
105
|
+
Object.defineProperty(this, "hideInputs", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
configurable: true,
|
|
108
|
+
writable: true,
|
|
109
|
+
value: void 0
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(this, "hideOutputs", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
configurable: true,
|
|
114
|
+
writable: true,
|
|
115
|
+
value: void 0
|
|
116
|
+
});
|
|
117
117
|
const defaultConfig = Client.getDefaultClientConfig();
|
|
118
118
|
this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
|
|
119
119
|
this.apiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
|
|
120
120
|
this.webUrl = trimQuotes(config.webUrl ?? defaultConfig.webUrl);
|
|
121
121
|
this.validateApiKeyIfHosted();
|
|
122
|
-
this.timeout_ms = config.timeout_ms ??
|
|
122
|
+
this.timeout_ms = config.timeout_ms ?? 12000;
|
|
123
123
|
this.caller = new async_caller_js_1.AsyncCaller(config.callerOptions ?? {});
|
|
124
|
+
this.hideInputs = config.hideInputs ?? defaultConfig.hideInputs;
|
|
125
|
+
this.hideOutputs = config.hideOutputs ?? defaultConfig.hideOutputs;
|
|
124
126
|
}
|
|
125
127
|
static getDefaultClientConfig() {
|
|
126
128
|
const apiKey = (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_API_KEY");
|
|
127
129
|
const apiUrl = (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_ENDPOINT") ??
|
|
128
130
|
"https://api.smith.langchain.com";
|
|
131
|
+
const hideInputs = (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_HIDE_INPUTS") === "true";
|
|
132
|
+
const hideOutputs = (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_HIDE_OUTPUTS") === "true";
|
|
129
133
|
return {
|
|
130
134
|
apiUrl: apiUrl,
|
|
131
135
|
apiKey: apiKey,
|
|
132
136
|
webUrl: undefined,
|
|
137
|
+
hideInputs: hideInputs,
|
|
138
|
+
hideOutputs: hideOutputs,
|
|
133
139
|
};
|
|
134
140
|
}
|
|
135
141
|
validateApiKeyIfHosted() {
|
|
@@ -169,6 +175,18 @@ class Client {
|
|
|
169
175
|
}
|
|
170
176
|
return headers;
|
|
171
177
|
}
|
|
178
|
+
processInputs(inputs) {
|
|
179
|
+
if (this.hideInputs) {
|
|
180
|
+
return {};
|
|
181
|
+
}
|
|
182
|
+
return inputs;
|
|
183
|
+
}
|
|
184
|
+
processOutputs(outputs) {
|
|
185
|
+
if (this.hideOutputs) {
|
|
186
|
+
return {};
|
|
187
|
+
}
|
|
188
|
+
return outputs;
|
|
189
|
+
}
|
|
172
190
|
async _getResponse(path, queryParams) {
|
|
173
191
|
const paramsString = queryParams?.toString() ?? "";
|
|
174
192
|
const url = `${this.apiUrl}${path}?${paramsString}`;
|
|
@@ -265,10 +283,11 @@ class Client {
|
|
|
265
283
|
},
|
|
266
284
|
},
|
|
267
285
|
};
|
|
268
|
-
runCreate.inputs =
|
|
286
|
+
runCreate.inputs = this.processInputs(runCreate.inputs);
|
|
269
287
|
if (runCreate.outputs) {
|
|
270
|
-
runCreate.outputs =
|
|
288
|
+
runCreate.outputs = this.processOutputs(runCreate.outputs);
|
|
271
289
|
}
|
|
290
|
+
runCreate.start_time = run.start_time ?? Date.now();
|
|
272
291
|
const response = await this.caller.call(fetch, `${this.apiUrl}/runs`, {
|
|
273
292
|
method: "POST",
|
|
274
293
|
headers,
|
|
@@ -280,10 +299,10 @@ class Client {
|
|
|
280
299
|
async updateRun(runId, run) {
|
|
281
300
|
assertUuid(runId);
|
|
282
301
|
if (run.inputs) {
|
|
283
|
-
run.inputs =
|
|
302
|
+
run.inputs = this.processInputs(run.inputs);
|
|
284
303
|
}
|
|
285
304
|
if (run.outputs) {
|
|
286
|
-
run.outputs =
|
|
305
|
+
run.outputs = this.processOutputs(run.outputs);
|
|
287
306
|
}
|
|
288
307
|
const headers = { ...this.headers, "Content-Type": "application/json" };
|
|
289
308
|
const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}`, {
|
|
@@ -817,7 +836,7 @@ class Client {
|
|
|
817
836
|
dataset_id: datasetId_,
|
|
818
837
|
inputs,
|
|
819
838
|
outputs,
|
|
820
|
-
created_at: createdAt_
|
|
839
|
+
created_at: createdAt_?.toISOString(),
|
|
821
840
|
id: exampleId,
|
|
822
841
|
};
|
|
823
842
|
const response = await this.caller.call(fetch, `${this.apiUrl}/examples`, {
|
|
@@ -832,6 +851,40 @@ class Client {
|
|
|
832
851
|
const result = await response.json();
|
|
833
852
|
return result;
|
|
834
853
|
}
|
|
854
|
+
async createExamples(props) {
|
|
855
|
+
const { inputs, outputs, sourceRunIds, exampleIds, datasetId, datasetName, } = props;
|
|
856
|
+
let datasetId_ = datasetId;
|
|
857
|
+
if (datasetId_ === undefined && datasetName === undefined) {
|
|
858
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
859
|
+
}
|
|
860
|
+
else if (datasetId_ !== undefined && datasetName !== undefined) {
|
|
861
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
862
|
+
}
|
|
863
|
+
else if (datasetId_ === undefined) {
|
|
864
|
+
const dataset = await this.readDataset({ datasetName });
|
|
865
|
+
datasetId_ = dataset.id;
|
|
866
|
+
}
|
|
867
|
+
const formattedExamples = inputs.map((input, idx) => {
|
|
868
|
+
return {
|
|
869
|
+
dataset_id: datasetId_,
|
|
870
|
+
inputs: input,
|
|
871
|
+
outputs: outputs ? outputs[idx] : undefined,
|
|
872
|
+
id: exampleIds ? exampleIds[idx] : undefined,
|
|
873
|
+
source_run_id: sourceRunIds ? sourceRunIds[idx] : undefined,
|
|
874
|
+
};
|
|
875
|
+
});
|
|
876
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/examples/bulk`, {
|
|
877
|
+
method: "POST",
|
|
878
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
879
|
+
body: JSON.stringify(formattedExamples),
|
|
880
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
881
|
+
});
|
|
882
|
+
if (!response.ok) {
|
|
883
|
+
throw new Error(`Failed to create examples: ${response.status} ${response.statusText}`);
|
|
884
|
+
}
|
|
885
|
+
const result = await response.json();
|
|
886
|
+
return result;
|
|
887
|
+
}
|
|
835
888
|
async createLLMExample(input, generation, options) {
|
|
836
889
|
return this.createExample({ input }, { output: generation }, options);
|
|
837
890
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ interface ClientConfig {
|
|
|
7
7
|
callerOptions?: AsyncCallerParams;
|
|
8
8
|
timeout_ms?: number;
|
|
9
9
|
webUrl?: string;
|
|
10
|
+
hideInputs?: boolean;
|
|
11
|
+
hideOutputs?: boolean;
|
|
10
12
|
}
|
|
11
13
|
interface ListRunsParams {
|
|
12
14
|
projectId?: string;
|
|
@@ -35,7 +37,6 @@ interface CreateRunParams {
|
|
|
35
37
|
name: string;
|
|
36
38
|
inputs: KVMap;
|
|
37
39
|
run_type: string;
|
|
38
|
-
execution_order?: number;
|
|
39
40
|
id?: string;
|
|
40
41
|
start_time?: number;
|
|
41
42
|
end_time?: number;
|
|
@@ -67,15 +68,21 @@ export declare class Client {
|
|
|
67
68
|
private caller;
|
|
68
69
|
private timeout_ms;
|
|
69
70
|
private _tenantId;
|
|
71
|
+
private hideInputs?;
|
|
72
|
+
private hideOutputs?;
|
|
70
73
|
constructor(config?: ClientConfig);
|
|
71
74
|
static getDefaultClientConfig(): {
|
|
72
75
|
apiUrl: string;
|
|
73
76
|
apiKey?: string;
|
|
74
77
|
webUrl?: string;
|
|
78
|
+
hideInputs?: boolean;
|
|
79
|
+
hideOutputs?: boolean;
|
|
75
80
|
};
|
|
76
81
|
private validateApiKeyIfHosted;
|
|
77
82
|
private getHostUrl;
|
|
78
83
|
private get headers();
|
|
84
|
+
private processInputs;
|
|
85
|
+
private processOutputs;
|
|
79
86
|
private _getResponse;
|
|
80
87
|
private _get;
|
|
81
88
|
private _getPaginated;
|
|
@@ -161,6 +168,14 @@ export declare class Client {
|
|
|
161
168
|
datasetName?: string;
|
|
162
169
|
}): Promise<void>;
|
|
163
170
|
createExample(inputs: KVMap, outputs: KVMap, { datasetId, datasetName, createdAt, exampleId }: CreateExampleOptions): Promise<Example>;
|
|
171
|
+
createExamples(props: {
|
|
172
|
+
inputs: Array<KVMap>;
|
|
173
|
+
outputs?: Array<KVMap>;
|
|
174
|
+
sourceRunIds?: Array<string>;
|
|
175
|
+
exampleIds?: Array<string>;
|
|
176
|
+
datasetId?: string;
|
|
177
|
+
datasetName?: string;
|
|
178
|
+
}): Promise<Example[]>;
|
|
164
179
|
createLLMExample(input: string, generation: string | undefined, options: CreateExampleOptions): Promise<Example>;
|
|
165
180
|
createChatExample(input: KVMap[] | LangChainBaseMessage[], generations: KVMap | LangChainBaseMessage | undefined, options: CreateExampleOptions): Promise<Example>;
|
|
166
181
|
readExample(exampleId: string): Promise<Example>;
|
package/dist/client.js
CHANGED
|
@@ -33,18 +33,6 @@ function trimQuotes(str) {
|
|
|
33
33
|
.replace(/^"(.*)"$/, "$1")
|
|
34
34
|
.replace(/^'(.*)'$/, "$1");
|
|
35
35
|
}
|
|
36
|
-
function hideInputs(inputs) {
|
|
37
|
-
if (getEnvironmentVariable("LANGCHAIN_HIDE_INPUTS") === "true") {
|
|
38
|
-
return {};
|
|
39
|
-
}
|
|
40
|
-
return inputs;
|
|
41
|
-
}
|
|
42
|
-
function hideOutputs(outputs) {
|
|
43
|
-
if (getEnvironmentVariable("LANGCHAIN_HIDE_OUTPUTS") === "true") {
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
return outputs;
|
|
47
|
-
}
|
|
48
36
|
function assertUuid(str) {
|
|
49
37
|
if (!uuid.validate(str)) {
|
|
50
38
|
throw new Error(`Invalid UUID: ${str}`);
|
|
@@ -88,22 +76,40 @@ export class Client {
|
|
|
88
76
|
writable: true,
|
|
89
77
|
value: null
|
|
90
78
|
});
|
|
79
|
+
Object.defineProperty(this, "hideInputs", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
configurable: true,
|
|
82
|
+
writable: true,
|
|
83
|
+
value: void 0
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(this, "hideOutputs", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
configurable: true,
|
|
88
|
+
writable: true,
|
|
89
|
+
value: void 0
|
|
90
|
+
});
|
|
91
91
|
const defaultConfig = Client.getDefaultClientConfig();
|
|
92
92
|
this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
|
|
93
93
|
this.apiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
|
|
94
94
|
this.webUrl = trimQuotes(config.webUrl ?? defaultConfig.webUrl);
|
|
95
95
|
this.validateApiKeyIfHosted();
|
|
96
|
-
this.timeout_ms = config.timeout_ms ??
|
|
96
|
+
this.timeout_ms = config.timeout_ms ?? 12000;
|
|
97
97
|
this.caller = new AsyncCaller(config.callerOptions ?? {});
|
|
98
|
+
this.hideInputs = config.hideInputs ?? defaultConfig.hideInputs;
|
|
99
|
+
this.hideOutputs = config.hideOutputs ?? defaultConfig.hideOutputs;
|
|
98
100
|
}
|
|
99
101
|
static getDefaultClientConfig() {
|
|
100
102
|
const apiKey = getEnvironmentVariable("LANGCHAIN_API_KEY");
|
|
101
103
|
const apiUrl = getEnvironmentVariable("LANGCHAIN_ENDPOINT") ??
|
|
102
104
|
"https://api.smith.langchain.com";
|
|
105
|
+
const hideInputs = getEnvironmentVariable("LANGCHAIN_HIDE_INPUTS") === "true";
|
|
106
|
+
const hideOutputs = getEnvironmentVariable("LANGCHAIN_HIDE_OUTPUTS") === "true";
|
|
103
107
|
return {
|
|
104
108
|
apiUrl: apiUrl,
|
|
105
109
|
apiKey: apiKey,
|
|
106
110
|
webUrl: undefined,
|
|
111
|
+
hideInputs: hideInputs,
|
|
112
|
+
hideOutputs: hideOutputs,
|
|
107
113
|
};
|
|
108
114
|
}
|
|
109
115
|
validateApiKeyIfHosted() {
|
|
@@ -143,6 +149,18 @@ export class Client {
|
|
|
143
149
|
}
|
|
144
150
|
return headers;
|
|
145
151
|
}
|
|
152
|
+
processInputs(inputs) {
|
|
153
|
+
if (this.hideInputs) {
|
|
154
|
+
return {};
|
|
155
|
+
}
|
|
156
|
+
return inputs;
|
|
157
|
+
}
|
|
158
|
+
processOutputs(outputs) {
|
|
159
|
+
if (this.hideOutputs) {
|
|
160
|
+
return {};
|
|
161
|
+
}
|
|
162
|
+
return outputs;
|
|
163
|
+
}
|
|
146
164
|
async _getResponse(path, queryParams) {
|
|
147
165
|
const paramsString = queryParams?.toString() ?? "";
|
|
148
166
|
const url = `${this.apiUrl}${path}?${paramsString}`;
|
|
@@ -239,10 +257,11 @@ export class Client {
|
|
|
239
257
|
},
|
|
240
258
|
},
|
|
241
259
|
};
|
|
242
|
-
runCreate.inputs =
|
|
260
|
+
runCreate.inputs = this.processInputs(runCreate.inputs);
|
|
243
261
|
if (runCreate.outputs) {
|
|
244
|
-
runCreate.outputs =
|
|
262
|
+
runCreate.outputs = this.processOutputs(runCreate.outputs);
|
|
245
263
|
}
|
|
264
|
+
runCreate.start_time = run.start_time ?? Date.now();
|
|
246
265
|
const response = await this.caller.call(fetch, `${this.apiUrl}/runs`, {
|
|
247
266
|
method: "POST",
|
|
248
267
|
headers,
|
|
@@ -254,10 +273,10 @@ export class Client {
|
|
|
254
273
|
async updateRun(runId, run) {
|
|
255
274
|
assertUuid(runId);
|
|
256
275
|
if (run.inputs) {
|
|
257
|
-
run.inputs =
|
|
276
|
+
run.inputs = this.processInputs(run.inputs);
|
|
258
277
|
}
|
|
259
278
|
if (run.outputs) {
|
|
260
|
-
run.outputs =
|
|
279
|
+
run.outputs = this.processOutputs(run.outputs);
|
|
261
280
|
}
|
|
262
281
|
const headers = { ...this.headers, "Content-Type": "application/json" };
|
|
263
282
|
const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}`, {
|
|
@@ -791,7 +810,7 @@ export class Client {
|
|
|
791
810
|
dataset_id: datasetId_,
|
|
792
811
|
inputs,
|
|
793
812
|
outputs,
|
|
794
|
-
created_at: createdAt_
|
|
813
|
+
created_at: createdAt_?.toISOString(),
|
|
795
814
|
id: exampleId,
|
|
796
815
|
};
|
|
797
816
|
const response = await this.caller.call(fetch, `${this.apiUrl}/examples`, {
|
|
@@ -806,6 +825,40 @@ export class Client {
|
|
|
806
825
|
const result = await response.json();
|
|
807
826
|
return result;
|
|
808
827
|
}
|
|
828
|
+
async createExamples(props) {
|
|
829
|
+
const { inputs, outputs, sourceRunIds, exampleIds, datasetId, datasetName, } = props;
|
|
830
|
+
let datasetId_ = datasetId;
|
|
831
|
+
if (datasetId_ === undefined && datasetName === undefined) {
|
|
832
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
833
|
+
}
|
|
834
|
+
else if (datasetId_ !== undefined && datasetName !== undefined) {
|
|
835
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
836
|
+
}
|
|
837
|
+
else if (datasetId_ === undefined) {
|
|
838
|
+
const dataset = await this.readDataset({ datasetName });
|
|
839
|
+
datasetId_ = dataset.id;
|
|
840
|
+
}
|
|
841
|
+
const formattedExamples = inputs.map((input, idx) => {
|
|
842
|
+
return {
|
|
843
|
+
dataset_id: datasetId_,
|
|
844
|
+
inputs: input,
|
|
845
|
+
outputs: outputs ? outputs[idx] : undefined,
|
|
846
|
+
id: exampleIds ? exampleIds[idx] : undefined,
|
|
847
|
+
source_run_id: sourceRunIds ? sourceRunIds[idx] : undefined,
|
|
848
|
+
};
|
|
849
|
+
});
|
|
850
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/examples/bulk`, {
|
|
851
|
+
method: "POST",
|
|
852
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
853
|
+
body: JSON.stringify(formattedExamples),
|
|
854
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
855
|
+
});
|
|
856
|
+
if (!response.ok) {
|
|
857
|
+
throw new Error(`Failed to create examples: ${response.status} ${response.statusText}`);
|
|
858
|
+
}
|
|
859
|
+
const result = await response.json();
|
|
860
|
+
return result;
|
|
861
|
+
}
|
|
809
862
|
async createLLMExample(input, generation, options) {
|
|
810
863
|
return this.createExample({ input }, { output: generation }, options);
|
|
811
864
|
}
|
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.0.
|
|
9
|
+
exports.__version__ = "0.0.66";
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
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.RunTree = void 0;
|
|
26
|
+
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");
|
|
@@ -34,6 +34,14 @@ function warnOnce(message) {
|
|
|
34
34
|
warnedMessages[message] = true;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
function stripNonAlphanumeric(input) {
|
|
38
|
+
return input.replace(/[-:.]/g, "");
|
|
39
|
+
}
|
|
40
|
+
function convertToDottedOrderFormat(epoch, runId) {
|
|
41
|
+
return (stripNonAlphanumeric(`${new Date(epoch).toISOString().slice(0, -1)}000Z`) +
|
|
42
|
+
runId);
|
|
43
|
+
}
|
|
44
|
+
exports.convertToDottedOrderFormat = convertToDottedOrderFormat;
|
|
37
45
|
class RunTree {
|
|
38
46
|
constructor(config) {
|
|
39
47
|
Object.defineProperty(this, "id", {
|
|
@@ -72,18 +80,6 @@ class RunTree {
|
|
|
72
80
|
writable: true,
|
|
73
81
|
value: void 0
|
|
74
82
|
});
|
|
75
|
-
Object.defineProperty(this, "execution_order", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
configurable: true,
|
|
78
|
-
writable: true,
|
|
79
|
-
value: void 0
|
|
80
|
-
});
|
|
81
|
-
Object.defineProperty(this, "child_execution_order", {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
configurable: true,
|
|
84
|
-
writable: true,
|
|
85
|
-
value: void 0
|
|
86
|
-
});
|
|
87
83
|
Object.defineProperty(this, "start_time", {
|
|
88
84
|
enumerable: true,
|
|
89
85
|
configurable: true,
|
|
@@ -144,8 +140,38 @@ class RunTree {
|
|
|
144
140
|
writable: true,
|
|
145
141
|
value: void 0
|
|
146
142
|
});
|
|
143
|
+
Object.defineProperty(this, "trace_id", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
value: void 0
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(this, "dotted_order", {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
configurable: true,
|
|
152
|
+
writable: true,
|
|
153
|
+
value: void 0
|
|
154
|
+
});
|
|
147
155
|
const defaultConfig = RunTree.getDefaultConfig();
|
|
148
156
|
Object.assign(this, { ...defaultConfig, ...config });
|
|
157
|
+
if (!this.trace_id) {
|
|
158
|
+
if (this.parent_run) {
|
|
159
|
+
this.trace_id = this.parent_run.trace_id;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.trace_id = this.id;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (!this.dotted_order) {
|
|
166
|
+
const currentDottedOrder = convertToDottedOrderFormat(this.start_time, this.id);
|
|
167
|
+
if (this.parent_run) {
|
|
168
|
+
this.dotted_order =
|
|
169
|
+
this.parent_run.dotted_order + "." + currentDottedOrder;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
this.dotted_order = currentDottedOrder;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
149
175
|
}
|
|
150
176
|
static getDefaultConfig() {
|
|
151
177
|
return {
|
|
@@ -154,8 +180,6 @@ class RunTree {
|
|
|
154
180
|
(0, env_js_1.getEnvironmentVariable)("LANGCHAIN_SESSION") ?? // TODO: Deprecate
|
|
155
181
|
"default",
|
|
156
182
|
child_runs: [],
|
|
157
|
-
execution_order: 1,
|
|
158
|
-
child_execution_order: 1,
|
|
159
183
|
api_url: (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_ENDPOINT") ?? "http://localhost:1984",
|
|
160
184
|
api_key: (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_API_KEY"),
|
|
161
185
|
caller_options: {},
|
|
@@ -172,8 +196,6 @@ class RunTree {
|
|
|
172
196
|
parent_run: this,
|
|
173
197
|
project_name: this.project_name,
|
|
174
198
|
client: this.client,
|
|
175
|
-
execution_order: this.child_execution_order + 1,
|
|
176
|
-
child_execution_order: this.child_execution_order + 1,
|
|
177
199
|
});
|
|
178
200
|
this.child_runs.push(child);
|
|
179
201
|
return child;
|
|
@@ -182,9 +204,6 @@ class RunTree {
|
|
|
182
204
|
this.outputs = outputs;
|
|
183
205
|
this.error = error;
|
|
184
206
|
this.end_time = endTime;
|
|
185
|
-
if (this.parent_run) {
|
|
186
|
-
this.parent_run.child_execution_order = Math.max(this.parent_run.child_execution_order, this.child_execution_order);
|
|
187
|
-
}
|
|
188
207
|
}
|
|
189
208
|
async _convertToCreate(run, excludeChildRuns = true) {
|
|
190
209
|
const runExtra = run.extra ?? {};
|
|
@@ -215,7 +234,6 @@ class RunTree {
|
|
|
215
234
|
run_type: run.run_type,
|
|
216
235
|
reference_example_id: run.reference_example_id,
|
|
217
236
|
extra: runExtra,
|
|
218
|
-
execution_order: run.execution_order,
|
|
219
237
|
serialized: run.serialized,
|
|
220
238
|
error: run.error,
|
|
221
239
|
inputs: run.inputs,
|
package/dist/run_trees.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { BaseRun, KVMap } from "./schemas.js";
|
|
2
2
|
import { Client } from "./client.js";
|
|
3
|
+
export declare function convertToDottedOrderFormat(epoch: number, runId: string): string;
|
|
3
4
|
export interface RunTreeConfig {
|
|
4
5
|
name: string;
|
|
5
6
|
run_type: string;
|
|
6
7
|
id?: string;
|
|
7
8
|
project_name?: string;
|
|
8
|
-
execution_order?: number;
|
|
9
|
-
child_execution_order?: number;
|
|
10
9
|
parent_run?: RunTree;
|
|
11
10
|
child_runs?: RunTree[];
|
|
12
11
|
start_time?: number;
|
|
@@ -26,8 +25,6 @@ export declare class RunTree implements BaseRun {
|
|
|
26
25
|
project_name: string;
|
|
27
26
|
parent_run?: RunTree;
|
|
28
27
|
child_runs: RunTree[];
|
|
29
|
-
execution_order: number;
|
|
30
|
-
child_execution_order: number;
|
|
31
28
|
start_time: number;
|
|
32
29
|
end_time?: number;
|
|
33
30
|
extra: KVMap;
|
|
@@ -38,6 +35,8 @@ export declare class RunTree implements BaseRun {
|
|
|
38
35
|
reference_example_id?: string;
|
|
39
36
|
client: Client;
|
|
40
37
|
events?: KVMap[] | undefined;
|
|
38
|
+
trace_id: string;
|
|
39
|
+
dotted_order: string;
|
|
41
40
|
constructor(config: RunTreeConfig);
|
|
42
41
|
private static getDefaultConfig;
|
|
43
42
|
createChild(config: RunTreeConfig): Promise<RunTree>;
|
package/dist/run_trees.js
CHANGED
|
@@ -8,6 +8,13 @@ function warnOnce(message) {
|
|
|
8
8
|
warnedMessages[message] = true;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
function stripNonAlphanumeric(input) {
|
|
12
|
+
return input.replace(/[-:.]/g, "");
|
|
13
|
+
}
|
|
14
|
+
export function convertToDottedOrderFormat(epoch, runId) {
|
|
15
|
+
return (stripNonAlphanumeric(`${new Date(epoch).toISOString().slice(0, -1)}000Z`) +
|
|
16
|
+
runId);
|
|
17
|
+
}
|
|
11
18
|
export class RunTree {
|
|
12
19
|
constructor(config) {
|
|
13
20
|
Object.defineProperty(this, "id", {
|
|
@@ -46,18 +53,6 @@ export class RunTree {
|
|
|
46
53
|
writable: true,
|
|
47
54
|
value: void 0
|
|
48
55
|
});
|
|
49
|
-
Object.defineProperty(this, "execution_order", {
|
|
50
|
-
enumerable: true,
|
|
51
|
-
configurable: true,
|
|
52
|
-
writable: true,
|
|
53
|
-
value: void 0
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(this, "child_execution_order", {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
writable: true,
|
|
59
|
-
value: void 0
|
|
60
|
-
});
|
|
61
56
|
Object.defineProperty(this, "start_time", {
|
|
62
57
|
enumerable: true,
|
|
63
58
|
configurable: true,
|
|
@@ -118,8 +113,38 @@ export class RunTree {
|
|
|
118
113
|
writable: true,
|
|
119
114
|
value: void 0
|
|
120
115
|
});
|
|
116
|
+
Object.defineProperty(this, "trace_id", {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
configurable: true,
|
|
119
|
+
writable: true,
|
|
120
|
+
value: void 0
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(this, "dotted_order", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
configurable: true,
|
|
125
|
+
writable: true,
|
|
126
|
+
value: void 0
|
|
127
|
+
});
|
|
121
128
|
const defaultConfig = RunTree.getDefaultConfig();
|
|
122
129
|
Object.assign(this, { ...defaultConfig, ...config });
|
|
130
|
+
if (!this.trace_id) {
|
|
131
|
+
if (this.parent_run) {
|
|
132
|
+
this.trace_id = this.parent_run.trace_id;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this.trace_id = this.id;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!this.dotted_order) {
|
|
139
|
+
const currentDottedOrder = convertToDottedOrderFormat(this.start_time, this.id);
|
|
140
|
+
if (this.parent_run) {
|
|
141
|
+
this.dotted_order =
|
|
142
|
+
this.parent_run.dotted_order + "." + currentDottedOrder;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.dotted_order = currentDottedOrder;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
123
148
|
}
|
|
124
149
|
static getDefaultConfig() {
|
|
125
150
|
return {
|
|
@@ -128,8 +153,6 @@ export class RunTree {
|
|
|
128
153
|
getEnvironmentVariable("LANGCHAIN_SESSION") ?? // TODO: Deprecate
|
|
129
154
|
"default",
|
|
130
155
|
child_runs: [],
|
|
131
|
-
execution_order: 1,
|
|
132
|
-
child_execution_order: 1,
|
|
133
156
|
api_url: getEnvironmentVariable("LANGCHAIN_ENDPOINT") ?? "http://localhost:1984",
|
|
134
157
|
api_key: getEnvironmentVariable("LANGCHAIN_API_KEY"),
|
|
135
158
|
caller_options: {},
|
|
@@ -146,8 +169,6 @@ export class RunTree {
|
|
|
146
169
|
parent_run: this,
|
|
147
170
|
project_name: this.project_name,
|
|
148
171
|
client: this.client,
|
|
149
|
-
execution_order: this.child_execution_order + 1,
|
|
150
|
-
child_execution_order: this.child_execution_order + 1,
|
|
151
172
|
});
|
|
152
173
|
this.child_runs.push(child);
|
|
153
174
|
return child;
|
|
@@ -156,9 +177,6 @@ export class RunTree {
|
|
|
156
177
|
this.outputs = outputs;
|
|
157
178
|
this.error = error;
|
|
158
179
|
this.end_time = endTime;
|
|
159
|
-
if (this.parent_run) {
|
|
160
|
-
this.parent_run.child_execution_order = Math.max(this.parent_run.child_execution_order, this.child_execution_order);
|
|
161
|
-
}
|
|
162
180
|
}
|
|
163
181
|
async _convertToCreate(run, excludeChildRuns = true) {
|
|
164
182
|
const runExtra = run.extra ?? {};
|
|
@@ -189,7 +207,6 @@ export class RunTree {
|
|
|
189
207
|
run_type: run.run_type,
|
|
190
208
|
reference_example_id: run.reference_example_id,
|
|
191
209
|
extra: runExtra,
|
|
192
|
-
execution_order: run.execution_order,
|
|
193
210
|
serialized: run.serialized,
|
|
194
211
|
error: run.error,
|
|
195
212
|
inputs: run.inputs,
|
package/dist/schemas.d.ts
CHANGED
|
@@ -37,8 +37,6 @@ export interface BaseRun {
|
|
|
37
37
|
id?: string;
|
|
38
38
|
/** A human-readable name for the run. */
|
|
39
39
|
name: string;
|
|
40
|
-
/** Defines the sequence in which the run was executed. */
|
|
41
|
-
execution_order?: number;
|
|
42
40
|
/** The epoch time at which the run started, if available. */
|
|
43
41
|
start_time?: number;
|
|
44
42
|
/** Specifies the type of run (tool, chain, llm, etc.). */
|
|
@@ -71,8 +69,6 @@ export interface BaseRun {
|
|
|
71
69
|
export interface Run extends BaseRun {
|
|
72
70
|
/** A unique identifier for the run, mandatory when loaded from DB. */
|
|
73
71
|
id: string;
|
|
74
|
-
/** Defines the sequence in which the run was executed. */
|
|
75
|
-
execution_order?: number;
|
|
76
72
|
/** The ID of the project that owns this run. */
|
|
77
73
|
session_id?: string;
|
|
78
74
|
/** IDs of any child runs spawned by this run. */
|
|
@@ -130,7 +126,7 @@ export interface RunUpdate {
|
|
|
130
126
|
}
|
|
131
127
|
export interface ExampleCreate extends BaseExample {
|
|
132
128
|
id?: string;
|
|
133
|
-
created_at
|
|
129
|
+
created_at?: string;
|
|
134
130
|
}
|
|
135
131
|
export interface Example extends BaseExample {
|
|
136
132
|
id: string;
|
|
@@ -14,7 +14,9 @@ const STATUS_NO_RETRY = [
|
|
|
14
14
|
405,
|
|
15
15
|
406,
|
|
16
16
|
407,
|
|
17
|
-
408,
|
|
17
|
+
408, // Request Timeout
|
|
18
|
+
];
|
|
19
|
+
const STATUS_IGNORE = [
|
|
18
20
|
409, // Conflict
|
|
19
21
|
];
|
|
20
22
|
/**
|
|
@@ -78,8 +80,13 @@ class AsyncCaller {
|
|
|
78
80
|
}
|
|
79
81
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
82
|
const status = error?.response?.status;
|
|
81
|
-
if (status
|
|
82
|
-
|
|
83
|
+
if (status) {
|
|
84
|
+
if (STATUS_NO_RETRY.includes(+status)) {
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
else if (STATUS_IGNORE.includes(+status)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
83
90
|
}
|
|
84
91
|
},
|
|
85
92
|
retries: this.maxRetries,
|
|
@@ -8,7 +8,9 @@ const STATUS_NO_RETRY = [
|
|
|
8
8
|
405,
|
|
9
9
|
406,
|
|
10
10
|
407,
|
|
11
|
-
408,
|
|
11
|
+
408, // Request Timeout
|
|
12
|
+
];
|
|
13
|
+
const STATUS_IGNORE = [
|
|
12
14
|
409, // Conflict
|
|
13
15
|
];
|
|
14
16
|
/**
|
|
@@ -72,8 +74,13 @@ export class AsyncCaller {
|
|
|
72
74
|
}
|
|
73
75
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
76
|
const status = error?.response?.status;
|
|
75
|
-
if (status
|
|
76
|
-
|
|
77
|
+
if (status) {
|
|
78
|
+
if (STATUS_NO_RETRY.includes(+status)) {
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
else if (STATUS_IGNORE.includes(+status)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
77
84
|
}
|
|
78
85
|
},
|
|
79
86
|
retries: this.maxRetries,
|