freestyle-sandboxes 0.0.97 → 0.1.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 +39 -48
- package/index.cjs +4362 -0
- package/index.d.cts +9401 -0
- package/index.d.mts +9401 -0
- package/index.mjs +4348 -0
- package/package.json +16 -109
- package/dist/ai/inde.d.cts +0 -75
- package/dist/ai/inde.d.mts +0 -75
- package/dist/ai/index.cjs +0 -13
- package/dist/ai/index.d.cts +0 -75
- package/dist/ai/index.d.mts +0 -75
- package/dist/ai/index.mjs +0 -4
- package/dist/expo/inde.d.cts +0 -6
- package/dist/expo/inde.d.mts +0 -6
- package/dist/expo/index.cjs +0 -319
- package/dist/expo/index.d.cts +0 -6
- package/dist/expo/index.d.mts +0 -6
- package/dist/expo/index.mjs +0 -297
- package/dist/inde.d.cts +0 -373
- package/dist/inde.d.mts +0 -373
- package/dist/index-BKAG8L-o.mjs +0 -3061
- package/dist/index-DuOpIaWc.cjs +0 -3068
- package/dist/index.cjs +0 -1329
- package/dist/index.d-9H_wnIbz.d.ts +0 -4223
- package/dist/index.d.cts +0 -373
- package/dist/index.d.mts +0 -373
- package/dist/index.mjs +0 -1327
- package/dist/langgraph/inde.d.cts +0 -4180
- package/dist/langgraph/inde.d.mts +0 -4180
- package/dist/langgraph/index.cjs +0 -17155
- package/dist/langgraph/index.d.cts +0 -4180
- package/dist/langgraph/index.d.mts +0 -4180
- package/dist/langgraph/index.mjs +0 -17153
- package/dist/mastra/inde.d.cts +0 -2623
- package/dist/mastra/inde.d.mts +0 -2623
- package/dist/mastra/index.cjs +0 -55
- package/dist/mastra/index.d.cts +0 -2623
- package/dist/mastra/index.d.mts +0 -2623
- package/dist/mastra/index.mjs +0 -53
- package/dist/react/dev-server/index..d.cts +0 -33
- package/dist/react/dev-server/index..d.mts +0 -33
- package/dist/react/dev-server/index.cjs +0 -148
- package/dist/react/dev-server/index.d.cts +0 -33
- package/dist/react/dev-server/index.d.mts +0 -33
- package/dist/react/dev-server/index.mjs +0 -145
- package/dist/types.gen-CJa21P0C.d.ts +0 -1902
- package/dist/types.gen-DKjMRuu5.d.ts +0 -1898
- package/dist/utils/inde.d.cts +0 -10
- package/dist/utils/inde.d.mts +0 -10
- package/dist/utils/index.cjs +0 -100
- package/dist/utils/index.d.cts +0 -10
- package/dist/utils/index.d.mts +0 -10
- package/dist/utils/index.mjs +0 -75
- package/openapi/index.ts +0 -3
- package/openapi/sdk.gen.ts +0 -929
- package/openapi/types.gen.ts +0 -2234
- package/openapi-ts.config.ts +0 -7
- package/openapi.json +0 -1
- package/src/ai/index.ts +0 -164
- package/src/dev-server.ts +0 -95
- package/src/expo/_expo_internals.ts +0 -389
- package/src/expo/index.ts +0 -26
- package/src/index.ts +0 -1459
- package/src/langgraph/index.ts +0 -33
- package/src/mastra/index.ts +0 -38
- package/src/react/dev-server/index.tsx +0 -195
- package/src/react/dev-server/types.ts +0 -5
- package/src/utils/index.ts +0 -97
- package/tsconfig.json +0 -8
|
@@ -1,4180 +0,0 @@
|
|
|
1
|
-
import { F as FreestyleExecuteScriptParamsConfiguration } from '../types.gen-CJa21P0C.js';
|
|
2
|
-
import * as z3 from 'zod/v3';
|
|
3
|
-
import { z } from 'zod/v3';
|
|
4
|
-
import * as z4 from 'zod/v4/core';
|
|
5
|
-
|
|
6
|
-
type AgentAction = {
|
|
7
|
-
tool: string;
|
|
8
|
-
toolInput: string | Record<string, any>;
|
|
9
|
-
log: string;
|
|
10
|
-
};
|
|
11
|
-
type AgentFinish = {
|
|
12
|
-
returnValues: Record<string, any>;
|
|
13
|
-
log: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type InteropZodType<Output = any, Input = Output> = z3.ZodType<Output, z3.ZodTypeDef, Input> | z4.$ZodType<Output, Input>;
|
|
17
|
-
type InferInteropZodInput<T> = T extends z3.ZodType<unknown, z3.ZodTypeDef, infer Input> ? Input : T extends z4.$ZodType<unknown, infer Input> ? Input : T extends {
|
|
18
|
-
_zod: {
|
|
19
|
-
input: infer Input;
|
|
20
|
-
};
|
|
21
|
-
} ? Input : never;
|
|
22
|
-
type InferInteropZodOutput<T> = T extends z3.ZodType<infer Output, z3.ZodTypeDef, unknown> ? Output : T extends z4.$ZodType<infer Output, unknown> ? Output : T extends {
|
|
23
|
-
_zod: {
|
|
24
|
-
output: infer Output;
|
|
25
|
-
};
|
|
26
|
-
} ? Output : never;
|
|
27
|
-
|
|
28
|
-
type ChainValues = Record<string, any>;
|
|
29
|
-
|
|
30
|
-
interface SerializedFields {
|
|
31
|
-
[key: string]: any;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface BaseSerialized<T extends string> {
|
|
35
|
-
lc: number;
|
|
36
|
-
type: T;
|
|
37
|
-
id: string[];
|
|
38
|
-
name?: string;
|
|
39
|
-
graph?: Record<string, any>;
|
|
40
|
-
}
|
|
41
|
-
interface SerializedConstructor extends BaseSerialized<"constructor"> {
|
|
42
|
-
kwargs: SerializedFields;
|
|
43
|
-
}
|
|
44
|
-
interface SerializedSecret extends BaseSerialized<"secret"> {
|
|
45
|
-
}
|
|
46
|
-
interface SerializedNotImplemented extends BaseSerialized<"not_implemented"> {
|
|
47
|
-
}
|
|
48
|
-
type Serialized = SerializedConstructor | SerializedSecret | SerializedNotImplemented;
|
|
49
|
-
interface SerializableInterface {
|
|
50
|
-
get lc_id(): string[];
|
|
51
|
-
}
|
|
52
|
-
declare abstract class Serializable implements SerializableInterface {
|
|
53
|
-
lc_serializable: boolean;
|
|
54
|
-
lc_kwargs: SerializedFields;
|
|
55
|
-
/**
|
|
56
|
-
* A path to the module that contains the class, eg. ["langchain", "llms"]
|
|
57
|
-
* Usually should be the same as the entrypoint the class is exported from.
|
|
58
|
-
*/
|
|
59
|
-
abstract lc_namespace: string[];
|
|
60
|
-
/**
|
|
61
|
-
* The name of the serializable. Override to provide an alias or
|
|
62
|
-
* to preserve the serialized module name in minified environments.
|
|
63
|
-
*
|
|
64
|
-
* Implemented as a static method to support loading logic.
|
|
65
|
-
*/
|
|
66
|
-
static lc_name(): string;
|
|
67
|
-
/**
|
|
68
|
-
* The final serialized identifier for the module.
|
|
69
|
-
*/
|
|
70
|
-
get lc_id(): string[];
|
|
71
|
-
/**
|
|
72
|
-
* A map of secrets, which will be omitted from serialization.
|
|
73
|
-
* Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
|
|
74
|
-
* Values are the secret ids, which will be used when deserializing.
|
|
75
|
-
*/
|
|
76
|
-
get lc_secrets(): {
|
|
77
|
-
[key: string]: string;
|
|
78
|
-
} | undefined;
|
|
79
|
-
/**
|
|
80
|
-
* A map of additional attributes to merge with constructor args.
|
|
81
|
-
* Keys are the attribute names, e.g. "foo".
|
|
82
|
-
* Values are the attribute values, which will be serialized.
|
|
83
|
-
* These attributes need to be accepted by the constructor as arguments.
|
|
84
|
-
*/
|
|
85
|
-
get lc_attributes(): SerializedFields | undefined;
|
|
86
|
-
/**
|
|
87
|
-
* A map of aliases for constructor args.
|
|
88
|
-
* Keys are the attribute names, e.g. "foo".
|
|
89
|
-
* Values are the alias that will replace the key in serialization.
|
|
90
|
-
* This is used to eg. make argument names match Python.
|
|
91
|
-
*/
|
|
92
|
-
get lc_aliases(): {
|
|
93
|
-
[key: string]: string;
|
|
94
|
-
} | undefined;
|
|
95
|
-
/**
|
|
96
|
-
* A manual list of keys that should be serialized.
|
|
97
|
-
* If not overridden, all fields passed into the constructor will be serialized.
|
|
98
|
-
*/
|
|
99
|
-
get lc_serializable_keys(): string[] | undefined;
|
|
100
|
-
constructor(kwargs?: SerializedFields, ..._args: never[]);
|
|
101
|
-
toJSON(): Serialized;
|
|
102
|
-
toJSONNotImplemented(): SerializedNotImplemented;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
interface StoredMessageData {
|
|
106
|
-
content: string;
|
|
107
|
-
role: string | undefined;
|
|
108
|
-
name: string | undefined;
|
|
109
|
-
tool_call_id: string | undefined;
|
|
110
|
-
additional_kwargs?: Record<string, any>;
|
|
111
|
-
/** Response metadata. For example: response headers, logprobs, token counts, model name. */
|
|
112
|
-
response_metadata?: Record<string, any>;
|
|
113
|
-
id?: string;
|
|
114
|
-
}
|
|
115
|
-
interface StoredMessage {
|
|
116
|
-
type: string;
|
|
117
|
-
data: StoredMessageData;
|
|
118
|
-
}
|
|
119
|
-
type MessageType = "human" | "ai" | "generic" | "developer" | "system" | "function" | "tool" | "remove";
|
|
120
|
-
type ImageDetail = "auto" | "low" | "high";
|
|
121
|
-
type MessageContentText = {
|
|
122
|
-
type: "text";
|
|
123
|
-
text: string;
|
|
124
|
-
};
|
|
125
|
-
type MessageContentImageUrl = {
|
|
126
|
-
type: "image_url";
|
|
127
|
-
image_url: string | {
|
|
128
|
-
url: string;
|
|
129
|
-
detail?: ImageDetail;
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
type MessageContentComplex = MessageContentText | MessageContentImageUrl | (Record<string, any> & {
|
|
133
|
-
type?: "text" | "image_url" | string;
|
|
134
|
-
}) | (Record<string, any> & {
|
|
135
|
-
type?: never;
|
|
136
|
-
});
|
|
137
|
-
type MessageContent = string | MessageContentComplex[];
|
|
138
|
-
interface FunctionCall {
|
|
139
|
-
/**
|
|
140
|
-
* The arguments to call the function with, as generated by the model in JSON
|
|
141
|
-
* format. Note that the model does not always generate valid JSON, and may
|
|
142
|
-
* hallucinate parameters not defined by your function schema. Validate the
|
|
143
|
-
* arguments in your code before calling your function.
|
|
144
|
-
*/
|
|
145
|
-
arguments: string;
|
|
146
|
-
/**
|
|
147
|
-
* The name of the function to call.
|
|
148
|
-
*/
|
|
149
|
-
name: string;
|
|
150
|
-
}
|
|
151
|
-
type BaseMessageFields = {
|
|
152
|
-
content: MessageContent;
|
|
153
|
-
name?: string;
|
|
154
|
-
additional_kwargs?: {
|
|
155
|
-
/**
|
|
156
|
-
* @deprecated Use "tool_calls" field on AIMessages instead
|
|
157
|
-
*/
|
|
158
|
-
function_call?: FunctionCall;
|
|
159
|
-
/**
|
|
160
|
-
* @deprecated Use "tool_calls" field on AIMessages instead
|
|
161
|
-
*/
|
|
162
|
-
tool_calls?: OpenAIToolCall[];
|
|
163
|
-
[key: string]: unknown;
|
|
164
|
-
};
|
|
165
|
-
/** Response metadata. For example: response headers, logprobs, token counts, model name. */
|
|
166
|
-
response_metadata?: Record<string, any>;
|
|
167
|
-
/**
|
|
168
|
-
* An optional unique identifier for the message. This should ideally be
|
|
169
|
-
* provided by the provider/model which created the message.
|
|
170
|
-
*/
|
|
171
|
-
id?: string;
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* Base class for all types of messages in a conversation. It includes
|
|
175
|
-
* properties like `content`, `name`, and `additional_kwargs`. It also
|
|
176
|
-
* includes methods like `toDict()` and `_getType()`.
|
|
177
|
-
*/
|
|
178
|
-
declare abstract class BaseMessage extends Serializable implements BaseMessageFields {
|
|
179
|
-
lc_namespace: string[];
|
|
180
|
-
lc_serializable: boolean;
|
|
181
|
-
get lc_aliases(): Record<string, string>;
|
|
182
|
-
/**
|
|
183
|
-
* Get text content of the message.
|
|
184
|
-
*/
|
|
185
|
-
get text(): string;
|
|
186
|
-
/** The content of the message. */
|
|
187
|
-
content: MessageContent;
|
|
188
|
-
/** The name of the message sender in a multi-user chat. */
|
|
189
|
-
name?: string;
|
|
190
|
-
/** Additional keyword arguments */
|
|
191
|
-
additional_kwargs: NonNullable<BaseMessageFields["additional_kwargs"]>;
|
|
192
|
-
/** Response metadata. For example: response headers, logprobs, token counts, model name. */
|
|
193
|
-
response_metadata: NonNullable<BaseMessageFields["response_metadata"]>;
|
|
194
|
-
/**
|
|
195
|
-
* An optional unique identifier for the message. This should ideally be
|
|
196
|
-
* provided by the provider/model which created the message.
|
|
197
|
-
*/
|
|
198
|
-
id?: string;
|
|
199
|
-
/**
|
|
200
|
-
* @deprecated Use .getType() instead or import the proper typeguard.
|
|
201
|
-
* For example:
|
|
202
|
-
*
|
|
203
|
-
* ```ts
|
|
204
|
-
* import { isAIMessage } from "@langchain/core/messages";
|
|
205
|
-
*
|
|
206
|
-
* const message = new AIMessage("Hello!");
|
|
207
|
-
* isAIMessage(message); // true
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
abstract _getType(): MessageType;
|
|
211
|
-
/** The type of the message. */
|
|
212
|
-
getType(): MessageType;
|
|
213
|
-
constructor(fields: string | BaseMessageFields,
|
|
214
|
-
/** @deprecated */
|
|
215
|
-
kwargs?: Record<string, unknown>);
|
|
216
|
-
toDict(): StoredMessage;
|
|
217
|
-
static lc_name(): string;
|
|
218
|
-
get _printableFields(): Record<string, unknown>;
|
|
219
|
-
_updateId(value: string | undefined): void;
|
|
220
|
-
get [Symbol.toStringTag](): any;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* @deprecated Use "tool_calls" field on AIMessages instead
|
|
224
|
-
*/
|
|
225
|
-
type OpenAIToolCall = {
|
|
226
|
-
/**
|
|
227
|
-
* The ID of the tool call.
|
|
228
|
-
*/
|
|
229
|
-
id: string;
|
|
230
|
-
/**
|
|
231
|
-
* The function that the model called.
|
|
232
|
-
*/
|
|
233
|
-
function: FunctionCall;
|
|
234
|
-
/**
|
|
235
|
-
* The type of the tool. Currently, only `function` is supported.
|
|
236
|
-
*/
|
|
237
|
-
type: "function";
|
|
238
|
-
index?: number;
|
|
239
|
-
};
|
|
240
|
-
/**
|
|
241
|
-
* Represents a chunk of a message, which can be concatenated with other
|
|
242
|
-
* message chunks. It includes a method `_merge_kwargs_dict()` for merging
|
|
243
|
-
* additional keyword arguments from another `BaseMessageChunk` into this
|
|
244
|
-
* one. It also overrides the `__add__()` method to support concatenation
|
|
245
|
-
* of `BaseMessageChunk` instances.
|
|
246
|
-
*/
|
|
247
|
-
declare abstract class BaseMessageChunk extends BaseMessage {
|
|
248
|
-
abstract concat(chunk: BaseMessageChunk): BaseMessageChunk;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
declare const RUN_KEY = "__run";
|
|
252
|
-
/**
|
|
253
|
-
* Output of a single generation.
|
|
254
|
-
*/
|
|
255
|
-
interface Generation {
|
|
256
|
-
/**
|
|
257
|
-
* Generated text output
|
|
258
|
-
*/
|
|
259
|
-
text: string;
|
|
260
|
-
/**
|
|
261
|
-
* Raw generation info response from the provider.
|
|
262
|
-
* May include things like reason for finishing (e.g. in {@link OpenAI})
|
|
263
|
-
*/
|
|
264
|
-
generationInfo?: Record<string, any>;
|
|
265
|
-
}
|
|
266
|
-
type GenerationChunkFields = {
|
|
267
|
-
text: string;
|
|
268
|
-
generationInfo?: Record<string, any>;
|
|
269
|
-
};
|
|
270
|
-
/**
|
|
271
|
-
* Chunk of a single generation. Used for streaming.
|
|
272
|
-
*/
|
|
273
|
-
declare class GenerationChunk implements Generation {
|
|
274
|
-
text: string;
|
|
275
|
-
generationInfo?: Record<string, any>;
|
|
276
|
-
constructor(fields: GenerationChunkFields);
|
|
277
|
-
concat(chunk: GenerationChunk): GenerationChunk;
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Contains all relevant information returned by an LLM.
|
|
281
|
-
*/
|
|
282
|
-
type LLMResult = {
|
|
283
|
-
/**
|
|
284
|
-
* List of the things generated. Each input could have multiple {@link Generation | generations}, hence this is a list of lists.
|
|
285
|
-
*/
|
|
286
|
-
generations: Generation[][];
|
|
287
|
-
/**
|
|
288
|
-
* Dictionary of arbitrary LLM-provider specific output.
|
|
289
|
-
*/
|
|
290
|
-
llmOutput?: Record<string, any>;
|
|
291
|
-
/**
|
|
292
|
-
* Dictionary of run metadata
|
|
293
|
-
*/
|
|
294
|
-
[RUN_KEY]?: Record<string, any>;
|
|
295
|
-
};
|
|
296
|
-
interface ChatGeneration extends Generation {
|
|
297
|
-
message: BaseMessage;
|
|
298
|
-
}
|
|
299
|
-
type ChatGenerationChunkFields = GenerationChunkFields & {
|
|
300
|
-
message: BaseMessageChunk;
|
|
301
|
-
};
|
|
302
|
-
declare class ChatGenerationChunk extends GenerationChunk implements ChatGeneration {
|
|
303
|
-
message: BaseMessageChunk;
|
|
304
|
-
constructor(fields: ChatGenerationChunkFields);
|
|
305
|
-
concat(chunk: ChatGenerationChunk): ChatGenerationChunk;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
interface DocumentInput<Metadata extends Record<string, any> = Record<string, any>> {
|
|
309
|
-
pageContent: string;
|
|
310
|
-
metadata?: Metadata;
|
|
311
|
-
/**
|
|
312
|
-
* An optional identifier for the document.
|
|
313
|
-
*
|
|
314
|
-
* Ideally this should be unique across the document collection and formatted
|
|
315
|
-
* as a UUID, but this will not be enforced.
|
|
316
|
-
*/
|
|
317
|
-
id?: string;
|
|
318
|
-
}
|
|
319
|
-
interface DocumentInterface<Metadata extends Record<string, any> = Record<string, any>> {
|
|
320
|
-
pageContent: string;
|
|
321
|
-
metadata: Metadata;
|
|
322
|
-
/**
|
|
323
|
-
* An optional identifier for the document.
|
|
324
|
-
*
|
|
325
|
-
* Ideally this should be unique across the document collection and formatted
|
|
326
|
-
* as a UUID, but this will not be enforced.
|
|
327
|
-
*/
|
|
328
|
-
id?: string;
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Interface for interacting with a document.
|
|
332
|
-
*/
|
|
333
|
-
declare class Document<Metadata extends Record<string, any> = Record<string, any>> implements DocumentInput, DocumentInterface {
|
|
334
|
-
pageContent: string;
|
|
335
|
-
metadata: Metadata;
|
|
336
|
-
/**
|
|
337
|
-
* An optional identifier for the document.
|
|
338
|
-
*
|
|
339
|
-
* Ideally this should be unique across the document collection and formatted
|
|
340
|
-
* as a UUID, but this will not be enforced.
|
|
341
|
-
*/
|
|
342
|
-
id?: string;
|
|
343
|
-
constructor(fields: DocumentInput<Metadata>);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
type Error$1 = any;
|
|
347
|
-
/**
|
|
348
|
-
* Interface for the input parameters of the BaseCallbackHandler class. It
|
|
349
|
-
* allows to specify which types of events should be ignored by the
|
|
350
|
-
* callback handler.
|
|
351
|
-
*/
|
|
352
|
-
interface BaseCallbackHandlerInput {
|
|
353
|
-
ignoreLLM?: boolean;
|
|
354
|
-
ignoreChain?: boolean;
|
|
355
|
-
ignoreAgent?: boolean;
|
|
356
|
-
ignoreRetriever?: boolean;
|
|
357
|
-
ignoreCustomEvent?: boolean;
|
|
358
|
-
_awaitHandler?: boolean;
|
|
359
|
-
raiseError?: boolean;
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Interface for the indices of a new token produced by an LLM or Chat
|
|
363
|
-
* Model in streaming mode.
|
|
364
|
-
*/
|
|
365
|
-
interface NewTokenIndices {
|
|
366
|
-
prompt: number;
|
|
367
|
-
completion: number;
|
|
368
|
-
}
|
|
369
|
-
type HandleLLMNewTokenCallbackFields = {
|
|
370
|
-
chunk?: GenerationChunk | ChatGenerationChunk;
|
|
371
|
-
};
|
|
372
|
-
/**
|
|
373
|
-
* Abstract class that provides a set of optional methods that can be
|
|
374
|
-
* overridden in derived classes to handle various events during the
|
|
375
|
-
* execution of a LangChain application.
|
|
376
|
-
*/
|
|
377
|
-
declare abstract class BaseCallbackHandlerMethodsClass {
|
|
378
|
-
/**
|
|
379
|
-
* Called at the start of an LLM or Chat Model run, with the prompt(s)
|
|
380
|
-
* and the run ID.
|
|
381
|
-
*/
|
|
382
|
-
handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
383
|
-
Promise<any> | any;
|
|
384
|
-
/**
|
|
385
|
-
* Called when an LLM/ChatModel in `streaming` mode produces a new token
|
|
386
|
-
*/
|
|
387
|
-
handleLLMNewToken?(token: string,
|
|
388
|
-
/**
|
|
389
|
-
* idx.prompt is the index of the prompt that produced the token
|
|
390
|
-
* (if there are multiple prompts)
|
|
391
|
-
* idx.completion is the index of the completion that produced the token
|
|
392
|
-
* (if multiple completions per prompt are requested)
|
|
393
|
-
*/
|
|
394
|
-
idx: NewTokenIndices, runId: string, parentRunId?: string, tags?: string[], fields?: HandleLLMNewTokenCallbackFields): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
395
|
-
Promise<any> | any;
|
|
396
|
-
/**
|
|
397
|
-
* Called if an LLM/ChatModel run encounters an error
|
|
398
|
-
*/
|
|
399
|
-
handleLLMError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
400
|
-
Promise<any> | any;
|
|
401
|
-
/**
|
|
402
|
-
* Called at the end of an LLM/ChatModel run, with the output and the run ID.
|
|
403
|
-
*/
|
|
404
|
-
handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
405
|
-
Promise<any> | any;
|
|
406
|
-
/**
|
|
407
|
-
* Called at the start of a Chat Model run, with the prompt(s)
|
|
408
|
-
* and the run ID.
|
|
409
|
-
*/
|
|
410
|
-
handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
411
|
-
Promise<any> | any;
|
|
412
|
-
/**
|
|
413
|
-
* Called at the start of a Chain run, with the chain name and inputs
|
|
414
|
-
* and the run ID.
|
|
415
|
-
*/
|
|
416
|
-
handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runType?: string, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
417
|
-
Promise<any> | any;
|
|
418
|
-
/**
|
|
419
|
-
* Called if a Chain run encounters an error
|
|
420
|
-
*/
|
|
421
|
-
handleChainError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
|
|
422
|
-
inputs?: Record<string, unknown>;
|
|
423
|
-
}): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
424
|
-
Promise<any> | any;
|
|
425
|
-
/**
|
|
426
|
-
* Called at the end of a Chain run, with the outputs and the run ID.
|
|
427
|
-
*/
|
|
428
|
-
handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
|
|
429
|
-
inputs?: Record<string, unknown>;
|
|
430
|
-
}): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
431
|
-
Promise<any> | any;
|
|
432
|
-
/**
|
|
433
|
-
* Called at the start of a Tool run, with the tool name and input
|
|
434
|
-
* and the run ID.
|
|
435
|
-
*/
|
|
436
|
-
handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
437
|
-
Promise<any> | any;
|
|
438
|
-
/**
|
|
439
|
-
* Called if a Tool run encounters an error
|
|
440
|
-
*/
|
|
441
|
-
handleToolError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
442
|
-
Promise<any> | any;
|
|
443
|
-
/**
|
|
444
|
-
* Called at the end of a Tool run, with the tool output and the run ID.
|
|
445
|
-
*/
|
|
446
|
-
handleToolEnd?(output: any, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
447
|
-
Promise<any> | any;
|
|
448
|
-
handleText?(text: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
449
|
-
/**
|
|
450
|
-
* Called when an agent is about to execute an action,
|
|
451
|
-
* with the action and the run ID.
|
|
452
|
-
*/
|
|
453
|
-
handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
454
|
-
/**
|
|
455
|
-
* Called when an agent finishes execution, before it exits.
|
|
456
|
-
* with the final output and the run ID.
|
|
457
|
-
*/
|
|
458
|
-
handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
459
|
-
handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
460
|
-
Promise<any> | any;
|
|
461
|
-
handleRetrieverEnd?(documents: DocumentInterface[], runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
462
|
-
Promise<any> | any;
|
|
463
|
-
handleRetrieverError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
464
|
-
Promise<any> | any;
|
|
465
|
-
handleCustomEvent?(eventName: string, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
466
|
-
Promise<any> | any;
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Base interface for callbacks. All methods are optional. If a method is not
|
|
470
|
-
* implemented, it will be ignored. If a method is implemented, it will be
|
|
471
|
-
* called at the appropriate time. All methods are called with the run ID of
|
|
472
|
-
* the LLM/ChatModel/Chain that is running, which is generated by the
|
|
473
|
-
* CallbackManager.
|
|
474
|
-
*
|
|
475
|
-
* @interface
|
|
476
|
-
*/
|
|
477
|
-
type CallbackHandlerMethods = BaseCallbackHandlerMethodsClass;
|
|
478
|
-
/**
|
|
479
|
-
* Interface for handlers that can indicate a preference for streaming responses.
|
|
480
|
-
* When implemented, this allows the handler to signal whether it prefers to receive
|
|
481
|
-
* streaming responses from language models rather than complete responses.
|
|
482
|
-
*/
|
|
483
|
-
interface CallbackHandlerPrefersStreaming {
|
|
484
|
-
readonly lc_prefer_streaming: boolean;
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* Abstract base class for creating callback handlers in the LangChain
|
|
488
|
-
* framework. It provides a set of optional methods that can be overridden
|
|
489
|
-
* in derived classes to handle various events during the execution of a
|
|
490
|
-
* LangChain application.
|
|
491
|
-
*/
|
|
492
|
-
declare abstract class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass implements BaseCallbackHandlerInput, Serializable {
|
|
493
|
-
lc_serializable: boolean;
|
|
494
|
-
get lc_namespace(): ["langchain_core", "callbacks", string];
|
|
495
|
-
get lc_secrets(): {
|
|
496
|
-
[key: string]: string;
|
|
497
|
-
} | undefined;
|
|
498
|
-
get lc_attributes(): {
|
|
499
|
-
[key: string]: string;
|
|
500
|
-
} | undefined;
|
|
501
|
-
get lc_aliases(): {
|
|
502
|
-
[key: string]: string;
|
|
503
|
-
} | undefined;
|
|
504
|
-
get lc_serializable_keys(): string[] | undefined;
|
|
505
|
-
/**
|
|
506
|
-
* The name of the serializable. Override to provide an alias or
|
|
507
|
-
* to preserve the serialized module name in minified environments.
|
|
508
|
-
*
|
|
509
|
-
* Implemented as a static method to support loading logic.
|
|
510
|
-
*/
|
|
511
|
-
static lc_name(): string;
|
|
512
|
-
/**
|
|
513
|
-
* The final serialized identifier for the module.
|
|
514
|
-
*/
|
|
515
|
-
get lc_id(): string[];
|
|
516
|
-
lc_kwargs: SerializedFields;
|
|
517
|
-
abstract name: string;
|
|
518
|
-
ignoreLLM: boolean;
|
|
519
|
-
ignoreChain: boolean;
|
|
520
|
-
ignoreAgent: boolean;
|
|
521
|
-
ignoreRetriever: boolean;
|
|
522
|
-
ignoreCustomEvent: boolean;
|
|
523
|
-
raiseError: boolean;
|
|
524
|
-
awaitHandlers: boolean;
|
|
525
|
-
constructor(input?: BaseCallbackHandlerInput);
|
|
526
|
-
copy(): BaseCallbackHandler;
|
|
527
|
-
toJSON(): Serialized;
|
|
528
|
-
toJSONNotImplemented(): SerializedNotImplemented;
|
|
529
|
-
static fromMethods(methods: CallbackHandlerMethods): {
|
|
530
|
-
name: string;
|
|
531
|
-
lc_serializable: boolean;
|
|
532
|
-
readonly lc_namespace: ["langchain_core", "callbacks", string];
|
|
533
|
-
readonly lc_secrets: {
|
|
534
|
-
[key: string]: string;
|
|
535
|
-
} | undefined;
|
|
536
|
-
readonly lc_attributes: {
|
|
537
|
-
[key: string]: string;
|
|
538
|
-
} | undefined;
|
|
539
|
-
readonly lc_aliases: {
|
|
540
|
-
[key: string]: string;
|
|
541
|
-
} | undefined;
|
|
542
|
-
readonly lc_serializable_keys: string[] | undefined;
|
|
543
|
-
/**
|
|
544
|
-
* The final serialized identifier for the module.
|
|
545
|
-
*/
|
|
546
|
-
readonly lc_id: string[];
|
|
547
|
-
lc_kwargs: SerializedFields;
|
|
548
|
-
ignoreLLM: boolean;
|
|
549
|
-
ignoreChain: boolean;
|
|
550
|
-
ignoreAgent: boolean;
|
|
551
|
-
ignoreRetriever: boolean;
|
|
552
|
-
ignoreCustomEvent: boolean;
|
|
553
|
-
raiseError: boolean;
|
|
554
|
-
awaitHandlers: boolean;
|
|
555
|
-
copy(): BaseCallbackHandler;
|
|
556
|
-
toJSON(): Serialized;
|
|
557
|
-
toJSONNotImplemented(): SerializedNotImplemented;
|
|
558
|
-
/**
|
|
559
|
-
* Called at the start of an LLM or Chat Model run, with the prompt(s)
|
|
560
|
-
* and the run ID.
|
|
561
|
-
*/
|
|
562
|
-
handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
563
|
-
Promise<any> | any;
|
|
564
|
-
/**
|
|
565
|
-
* Called when an LLM/ChatModel in `streaming` mode produces a new token
|
|
566
|
-
*/
|
|
567
|
-
handleLLMNewToken?(token: string, idx: NewTokenIndices, runId: string, parentRunId?: string, tags?: string[], fields?: HandleLLMNewTokenCallbackFields): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
568
|
-
Promise<any> | any;
|
|
569
|
-
/**
|
|
570
|
-
* Called if an LLM/ChatModel run encounters an error
|
|
571
|
-
*/
|
|
572
|
-
handleLLMError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
573
|
-
Promise<any> | any;
|
|
574
|
-
/**
|
|
575
|
-
* Called at the end of an LLM/ChatModel run, with the output and the run ID.
|
|
576
|
-
*/
|
|
577
|
-
handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
578
|
-
Promise<any> | any;
|
|
579
|
-
/**
|
|
580
|
-
* Called at the start of a Chat Model run, with the prompt(s)
|
|
581
|
-
* and the run ID.
|
|
582
|
-
*/
|
|
583
|
-
handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
584
|
-
Promise<any> | any;
|
|
585
|
-
/**
|
|
586
|
-
* Called at the start of a Chain run, with the chain name and inputs
|
|
587
|
-
* and the run ID.
|
|
588
|
-
*/
|
|
589
|
-
handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runType?: string, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
590
|
-
Promise<any> | any;
|
|
591
|
-
/**
|
|
592
|
-
* Called if a Chain run encounters an error
|
|
593
|
-
*/
|
|
594
|
-
handleChainError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
|
|
595
|
-
inputs?: Record<string, unknown>;
|
|
596
|
-
}): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
597
|
-
Promise<any> | any;
|
|
598
|
-
/**
|
|
599
|
-
* Called at the end of a Chain run, with the outputs and the run ID.
|
|
600
|
-
*/
|
|
601
|
-
handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
|
|
602
|
-
inputs?: Record<string, unknown>;
|
|
603
|
-
}): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
604
|
-
Promise<any> | any;
|
|
605
|
-
/**
|
|
606
|
-
* Called at the start of a Tool run, with the tool name and input
|
|
607
|
-
* and the run ID.
|
|
608
|
-
*/
|
|
609
|
-
handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runName?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
610
|
-
Promise<any> | any;
|
|
611
|
-
/**
|
|
612
|
-
* Called if a Tool run encounters an error
|
|
613
|
-
*/
|
|
614
|
-
handleToolError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
615
|
-
Promise<any> | any;
|
|
616
|
-
/**
|
|
617
|
-
* Called at the end of a Tool run, with the tool output and the run ID.
|
|
618
|
-
*/
|
|
619
|
-
handleToolEnd?(output: any, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
620
|
-
Promise<any> | any;
|
|
621
|
-
handleText?(text: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
622
|
-
/**
|
|
623
|
-
* Called when an agent is about to execute an action,
|
|
624
|
-
* with the action and the run ID.
|
|
625
|
-
*/
|
|
626
|
-
handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
627
|
-
/**
|
|
628
|
-
* Called when an agent finishes execution, before it exits.
|
|
629
|
-
* with the final output and the run ID.
|
|
630
|
-
*/
|
|
631
|
-
handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
632
|
-
handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
633
|
-
Promise<any> | any;
|
|
634
|
-
handleRetrieverEnd?(documents: DocumentInterface[], runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
635
|
-
Promise<any> | any;
|
|
636
|
-
handleRetrieverError?(err: Error$1, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
637
|
-
Promise<any> | any;
|
|
638
|
-
handleCustomEvent?(eventName: string, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
639
|
-
Promise<any> | any;
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
type ResponseCallback = (response?: Response) => Promise<boolean>;
|
|
644
|
-
interface AsyncCallerParams {
|
|
645
|
-
/**
|
|
646
|
-
* The maximum number of concurrent calls that can be made.
|
|
647
|
-
* Defaults to `Infinity`, which means no limit.
|
|
648
|
-
*/
|
|
649
|
-
maxConcurrency?: number;
|
|
650
|
-
/**
|
|
651
|
-
* The maximum number of retries that can be made for a single call,
|
|
652
|
-
* with an exponential backoff between each attempt. Defaults to 6.
|
|
653
|
-
*/
|
|
654
|
-
maxRetries?: number;
|
|
655
|
-
onFailedResponseHook?: ResponseCallback;
|
|
656
|
-
debug?: boolean;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
interface TracerSession {
|
|
660
|
-
tenant_id: string;
|
|
661
|
-
id: string;
|
|
662
|
-
start_time: number;
|
|
663
|
-
end_time?: number;
|
|
664
|
-
description?: string;
|
|
665
|
-
name?: string;
|
|
666
|
-
/** Extra metadata for the project. */
|
|
667
|
-
extra?: KVMap;
|
|
668
|
-
reference_dataset_id?: string;
|
|
669
|
-
}
|
|
670
|
-
interface TracerSessionResult extends TracerSession {
|
|
671
|
-
run_count?: number;
|
|
672
|
-
latency_p50?: number;
|
|
673
|
-
latency_p99?: number;
|
|
674
|
-
total_tokens?: number;
|
|
675
|
-
prompt_tokens?: number;
|
|
676
|
-
completion_tokens?: number;
|
|
677
|
-
last_run_start_time?: number;
|
|
678
|
-
feedback_stats?: Record<string, unknown>;
|
|
679
|
-
run_facets?: KVMap[];
|
|
680
|
-
}
|
|
681
|
-
type KVMap = Record<string, any>;
|
|
682
|
-
type ScoreType = number | boolean | null;
|
|
683
|
-
type ValueType = number | boolean | string | object | null;
|
|
684
|
-
type DataType = "kv" | "llm" | "chat";
|
|
685
|
-
interface BaseExample {
|
|
686
|
-
dataset_id: string;
|
|
687
|
-
inputs: KVMap;
|
|
688
|
-
outputs?: KVMap;
|
|
689
|
-
metadata?: KVMap;
|
|
690
|
-
source_run_id?: string;
|
|
691
|
-
}
|
|
692
|
-
interface AttachmentInfo {
|
|
693
|
-
presigned_url: string;
|
|
694
|
-
mime_type?: string;
|
|
695
|
-
}
|
|
696
|
-
type AttachmentData = Uint8Array | ArrayBuffer;
|
|
697
|
-
type AttachmentDescription = {
|
|
698
|
-
mimeType: string;
|
|
699
|
-
data: AttachmentData;
|
|
700
|
-
};
|
|
701
|
-
type Attachments = Record<string, [
|
|
702
|
-
string,
|
|
703
|
-
AttachmentData
|
|
704
|
-
] | AttachmentDescription>;
|
|
705
|
-
/**
|
|
706
|
-
* A run can represent either a trace (root run)
|
|
707
|
-
* or a child run (~span).
|
|
708
|
-
*/
|
|
709
|
-
interface BaseRun {
|
|
710
|
-
/** Optionally, a unique identifier for the run. */
|
|
711
|
-
id?: string;
|
|
712
|
-
/** A human-readable name for the run. */
|
|
713
|
-
name: string;
|
|
714
|
-
/** The epoch time at which the run started, if available. */
|
|
715
|
-
start_time?: number | string;
|
|
716
|
-
/** Specifies the type of run (tool, chain, llm, etc.). */
|
|
717
|
-
run_type: string;
|
|
718
|
-
/** The epoch time at which the run ended, if applicable. */
|
|
719
|
-
end_time?: number | string;
|
|
720
|
-
/** Any additional metadata or settings for the run. */
|
|
721
|
-
extra?: KVMap;
|
|
722
|
-
/** Error message, captured if the run faces any issues. */
|
|
723
|
-
error?: string;
|
|
724
|
-
/** Serialized state of the run for potential future use. */
|
|
725
|
-
serialized?: object;
|
|
726
|
-
/** Events like 'start', 'end' linked to the run. */
|
|
727
|
-
events?: KVMap[];
|
|
728
|
-
/** Inputs that were used to initiate the run. */
|
|
729
|
-
inputs: KVMap;
|
|
730
|
-
/** Outputs produced by the run, if any. */
|
|
731
|
-
outputs?: KVMap;
|
|
732
|
-
/** ID of an example that might be related to this run. */
|
|
733
|
-
reference_example_id?: string;
|
|
734
|
-
/** ID of a parent run, if this run is part of a larger operation. */
|
|
735
|
-
parent_run_id?: string;
|
|
736
|
-
/** Tags for further categorizing or annotating the run. */
|
|
737
|
-
tags?: string[];
|
|
738
|
-
/** Unique ID assigned to every run within this nested trace. **/
|
|
739
|
-
trace_id?: string;
|
|
740
|
-
/**
|
|
741
|
-
* The dotted order for the run.
|
|
742
|
-
*
|
|
743
|
-
* This is a string composed of {time}{run-uuid}.* so that a trace can be
|
|
744
|
-
* sorted in the order it was executed.
|
|
745
|
-
*
|
|
746
|
-
* Example:
|
|
747
|
-
* - Parent: 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8
|
|
748
|
-
* - Children:
|
|
749
|
-
* - 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155649Z809ed3a2-0172-4f4d-8a02-a64e9b7a0f8a
|
|
750
|
-
* - 20230915T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155650Zc8d9f4c5-6c5a-4b2d-9b1c-3d9d7a7c5c7c
|
|
751
|
-
*/
|
|
752
|
-
dotted_order?: string;
|
|
753
|
-
/**
|
|
754
|
-
* Attachments associated with the run.
|
|
755
|
-
* Each entry is a tuple of [mime_type, bytes]
|
|
756
|
-
*/
|
|
757
|
-
attachments?: Attachments;
|
|
758
|
-
}
|
|
759
|
-
type S3URL = {
|
|
760
|
-
ROOT: {
|
|
761
|
-
/** A pre-signed URL */
|
|
762
|
-
presigned_url: string;
|
|
763
|
-
/** The S3 path to the object in storage */
|
|
764
|
-
s3_url: string;
|
|
765
|
-
};
|
|
766
|
-
};
|
|
767
|
-
/**
|
|
768
|
-
* Describes properties of a run when loaded from the database.
|
|
769
|
-
* Extends the BaseRun interface.
|
|
770
|
-
*/
|
|
771
|
-
interface Run$1 extends BaseRun {
|
|
772
|
-
/** A unique identifier for the run, mandatory when loaded from DB. */
|
|
773
|
-
id: string;
|
|
774
|
-
/** The ID of the project that owns this run. */
|
|
775
|
-
session_id?: string;
|
|
776
|
-
/** IDs of any child runs spawned by this run. */
|
|
777
|
-
child_run_ids?: string[];
|
|
778
|
-
/** Child runs, loaded explicitly via a heavier query. */
|
|
779
|
-
child_runs?: Run$1[];
|
|
780
|
-
/** Stats capturing feedback for this run. */
|
|
781
|
-
feedback_stats?: KVMap;
|
|
782
|
-
/** The URL path where this run is accessible within the app. */
|
|
783
|
-
app_path?: string;
|
|
784
|
-
/** The manifest ID that correlates with this run. */
|
|
785
|
-
manifest_id?: string;
|
|
786
|
-
/** The current status of the run, such as 'success'. */
|
|
787
|
-
status?: string;
|
|
788
|
-
/** Number of tokens used in the prompt. */
|
|
789
|
-
prompt_tokens?: number;
|
|
790
|
-
/** Number of tokens generated in the completion. */
|
|
791
|
-
completion_tokens?: number;
|
|
792
|
-
/** Total token count, combining prompt and completion. */
|
|
793
|
-
total_tokens?: number;
|
|
794
|
-
/** Time when the first token was processed. */
|
|
795
|
-
first_token_time?: number;
|
|
796
|
-
/** IDs of parent runs, if multiple exist. */
|
|
797
|
-
parent_run_ids?: string[];
|
|
798
|
-
/** Whether the run is included in a dataset. */
|
|
799
|
-
in_dataset?: boolean;
|
|
800
|
-
/** The output S3 URLs */
|
|
801
|
-
outputs_s3_urls?: S3URL;
|
|
802
|
-
/** The input S3 URLs */
|
|
803
|
-
inputs_s3_urls?: S3URL;
|
|
804
|
-
}
|
|
805
|
-
interface RunCreate extends BaseRun {
|
|
806
|
-
revision_id?: string;
|
|
807
|
-
child_runs?: this[];
|
|
808
|
-
session_name?: string;
|
|
809
|
-
}
|
|
810
|
-
interface RunUpdate {
|
|
811
|
-
id?: string;
|
|
812
|
-
end_time?: number | string;
|
|
813
|
-
extra?: KVMap;
|
|
814
|
-
tags?: string[];
|
|
815
|
-
error?: string;
|
|
816
|
-
inputs?: KVMap;
|
|
817
|
-
outputs?: KVMap;
|
|
818
|
-
parent_run_id?: string;
|
|
819
|
-
reference_example_id?: string;
|
|
820
|
-
events?: KVMap[];
|
|
821
|
-
session_id?: string;
|
|
822
|
-
session_name?: string;
|
|
823
|
-
/** Unique ID assigned to every run within this nested trace. **/
|
|
824
|
-
trace_id?: string;
|
|
825
|
-
/**
|
|
826
|
-
* The dotted order for the run.
|
|
827
|
-
*
|
|
828
|
-
* This is a string composed of {time}{run-uuid}.* so that a trace can be
|
|
829
|
-
* sorted in the order it was executed.
|
|
830
|
-
*
|
|
831
|
-
* Example:
|
|
832
|
-
* - Parent: 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8
|
|
833
|
-
* - Children:
|
|
834
|
-
* - 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155649Z809ed3a2-0172-4f4d-8a02-a64e9b7a0f8a
|
|
835
|
-
* - 20230915T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155650Zc8d9f4c5-6c5a-4b2d-9b1c-3d9d7a7c5c7c
|
|
836
|
-
*/
|
|
837
|
-
dotted_order?: string;
|
|
838
|
-
/**
|
|
839
|
-
* Attachments associated with the run.
|
|
840
|
-
* Each entry is a tuple of [mime_type, bytes]
|
|
841
|
-
*/
|
|
842
|
-
attachments?: Attachments;
|
|
843
|
-
}
|
|
844
|
-
interface ExampleCreate {
|
|
845
|
-
id?: string;
|
|
846
|
-
inputs: KVMap;
|
|
847
|
-
outputs?: KVMap;
|
|
848
|
-
metadata?: KVMap;
|
|
849
|
-
split?: string | string[];
|
|
850
|
-
attachments?: Attachments;
|
|
851
|
-
created_at?: string;
|
|
852
|
-
dataset_id?: string;
|
|
853
|
-
dataset_name?: string;
|
|
854
|
-
source_run_id?: string;
|
|
855
|
-
use_source_run_io?: boolean;
|
|
856
|
-
use_source_run_attachments?: string[];
|
|
857
|
-
}
|
|
858
|
-
interface ExampleUpdate {
|
|
859
|
-
id: string;
|
|
860
|
-
inputs?: KVMap;
|
|
861
|
-
outputs?: KVMap;
|
|
862
|
-
metadata?: KVMap;
|
|
863
|
-
split?: string | string[];
|
|
864
|
-
attachments?: Attachments;
|
|
865
|
-
attachments_operations?: KVMap;
|
|
866
|
-
dataset_id?: string;
|
|
867
|
-
}
|
|
868
|
-
interface ExampleUpdateWithoutId extends Omit<ExampleUpdate, "id"> {
|
|
869
|
-
}
|
|
870
|
-
interface UploadExamplesResponse {
|
|
871
|
-
count: number;
|
|
872
|
-
example_ids: string[];
|
|
873
|
-
}
|
|
874
|
-
interface UpdateExamplesResponse extends UploadExamplesResponse {
|
|
875
|
-
}
|
|
876
|
-
interface Example extends BaseExample {
|
|
877
|
-
id: string;
|
|
878
|
-
created_at: string;
|
|
879
|
-
modified_at?: string;
|
|
880
|
-
source_run_id?: string;
|
|
881
|
-
runs: Run$1[];
|
|
882
|
-
attachments?: Record<string, AttachmentInfo>;
|
|
883
|
-
split?: string | string[];
|
|
884
|
-
}
|
|
885
|
-
interface ExampleSearch extends BaseExample {
|
|
886
|
-
id: string;
|
|
887
|
-
}
|
|
888
|
-
interface BaseDataset {
|
|
889
|
-
name: string;
|
|
890
|
-
description: string;
|
|
891
|
-
tenant_id: string;
|
|
892
|
-
data_type?: DataType;
|
|
893
|
-
inputs_schema_definition?: KVMap;
|
|
894
|
-
outputs_schema_definition?: KVMap;
|
|
895
|
-
}
|
|
896
|
-
interface Dataset extends BaseDataset {
|
|
897
|
-
id: string;
|
|
898
|
-
created_at: string;
|
|
899
|
-
modified_at: string;
|
|
900
|
-
example_count?: number;
|
|
901
|
-
session_count?: number;
|
|
902
|
-
last_session_start_time?: number;
|
|
903
|
-
}
|
|
904
|
-
interface DatasetShareSchema {
|
|
905
|
-
dataset_id: string;
|
|
906
|
-
share_token: string;
|
|
907
|
-
url: string;
|
|
908
|
-
}
|
|
909
|
-
interface DatasetVersion {
|
|
910
|
-
tags?: string[];
|
|
911
|
-
as_of: string;
|
|
912
|
-
}
|
|
913
|
-
interface FeedbackSourceBase {
|
|
914
|
-
type: string;
|
|
915
|
-
metadata?: KVMap;
|
|
916
|
-
}
|
|
917
|
-
interface APIFeedbackSource extends FeedbackSourceBase {
|
|
918
|
-
type: "api";
|
|
919
|
-
}
|
|
920
|
-
interface ModelFeedbackSource extends FeedbackSourceBase {
|
|
921
|
-
type: "model";
|
|
922
|
-
}
|
|
923
|
-
interface FeedbackBase {
|
|
924
|
-
created_at: string;
|
|
925
|
-
modified_at: string;
|
|
926
|
-
run_id: string;
|
|
927
|
-
key: string;
|
|
928
|
-
score: ScoreType;
|
|
929
|
-
value: ValueType;
|
|
930
|
-
comment: string | null;
|
|
931
|
-
correction: string | object | null;
|
|
932
|
-
feedback_source: APIFeedbackSource | ModelFeedbackSource | KVMap | null;
|
|
933
|
-
}
|
|
934
|
-
interface Feedback extends FeedbackBase {
|
|
935
|
-
id: string;
|
|
936
|
-
}
|
|
937
|
-
interface LangChainBaseMessage {
|
|
938
|
-
_getType: () => string;
|
|
939
|
-
content: string;
|
|
940
|
-
additional_kwargs?: KVMap;
|
|
941
|
-
}
|
|
942
|
-
interface FeedbackIngestToken {
|
|
943
|
-
id: string;
|
|
944
|
-
url: string;
|
|
945
|
-
expires_at: string;
|
|
946
|
-
}
|
|
947
|
-
interface TimeDelta {
|
|
948
|
-
days?: number;
|
|
949
|
-
hours?: number;
|
|
950
|
-
minutes?: number;
|
|
951
|
-
}
|
|
952
|
-
interface FeedbackCategory {
|
|
953
|
-
value: number;
|
|
954
|
-
label?: string | null;
|
|
955
|
-
}
|
|
956
|
-
/**
|
|
957
|
-
* Represents the configuration for feedback.
|
|
958
|
-
* This determines how the LangSmith service interprets feedback
|
|
959
|
-
* values of the associated key.
|
|
960
|
-
*/
|
|
961
|
-
interface FeedbackConfig {
|
|
962
|
-
/**
|
|
963
|
-
* The type of feedback.
|
|
964
|
-
* - "continuous": Feedback with a continuous numeric.
|
|
965
|
-
* - "categorical": Feedback with a categorical value (classes)
|
|
966
|
-
* - "freeform": Feedback with a freeform text value (notes).
|
|
967
|
-
*/
|
|
968
|
-
type: "continuous" | "categorical" | "freeform";
|
|
969
|
-
/**
|
|
970
|
-
* The minimum value for continuous feedback.
|
|
971
|
-
*/
|
|
972
|
-
min?: number | null;
|
|
973
|
-
/**
|
|
974
|
-
* The maximum value for continuous feedback.
|
|
975
|
-
*/
|
|
976
|
-
max?: number | null;
|
|
977
|
-
/**
|
|
978
|
-
* The categories for categorical feedback.
|
|
979
|
-
* Each category can be a string or an object with additional properties.
|
|
980
|
-
*
|
|
981
|
-
* If feedback is categorical, this defines the valid categories the server will accept.
|
|
982
|
-
* Not applicable to continuous or freeform feedback types.
|
|
983
|
-
*/
|
|
984
|
-
categories?: FeedbackCategory[] | null;
|
|
985
|
-
}
|
|
986
|
-
interface DatasetDiffInfo {
|
|
987
|
-
examples_modified: string[];
|
|
988
|
-
examples_added: string[];
|
|
989
|
-
examples_removed: string[];
|
|
990
|
-
}
|
|
991
|
-
interface ComparativeExperiment {
|
|
992
|
-
id: string;
|
|
993
|
-
name: string;
|
|
994
|
-
description: string;
|
|
995
|
-
tenant_id: string;
|
|
996
|
-
created_at: string;
|
|
997
|
-
modified_at: string;
|
|
998
|
-
reference_dataset_id: string;
|
|
999
|
-
extra?: Record<string, unknown>;
|
|
1000
|
-
experiments_info?: Array<Record<string, unknown>>;
|
|
1001
|
-
feedback_stats?: Record<string, unknown>;
|
|
1002
|
-
}
|
|
1003
|
-
interface PromptCommit {
|
|
1004
|
-
owner: string;
|
|
1005
|
-
repo: string;
|
|
1006
|
-
commit_hash: string;
|
|
1007
|
-
manifest: Record<string, any>;
|
|
1008
|
-
examples: Array<Record<any, any>>;
|
|
1009
|
-
}
|
|
1010
|
-
interface Prompt {
|
|
1011
|
-
repo_handle: string;
|
|
1012
|
-
description?: string;
|
|
1013
|
-
readme?: string;
|
|
1014
|
-
id: string;
|
|
1015
|
-
tenant_id: string;
|
|
1016
|
-
created_at: string;
|
|
1017
|
-
updated_at: string;
|
|
1018
|
-
is_public: boolean;
|
|
1019
|
-
is_archived: boolean;
|
|
1020
|
-
tags: string[];
|
|
1021
|
-
original_repo_id?: string;
|
|
1022
|
-
upstream_repo_id?: string;
|
|
1023
|
-
owner?: string;
|
|
1024
|
-
full_name: string;
|
|
1025
|
-
num_likes: number;
|
|
1026
|
-
num_downloads: number;
|
|
1027
|
-
num_views: number;
|
|
1028
|
-
liked_by_auth_user: boolean;
|
|
1029
|
-
last_commit_hash?: string;
|
|
1030
|
-
num_commits: number;
|
|
1031
|
-
original_repo_full_name?: string;
|
|
1032
|
-
upstream_repo_full_name?: string;
|
|
1033
|
-
}
|
|
1034
|
-
type PromptSortField = "num_downloads" | "num_views" | "updated_at" | "num_likes";
|
|
1035
|
-
interface LikePromptResponse {
|
|
1036
|
-
likes: number;
|
|
1037
|
-
}
|
|
1038
|
-
interface LangSmithSettings {
|
|
1039
|
-
id: string;
|
|
1040
|
-
display_name: string;
|
|
1041
|
-
created_at: string;
|
|
1042
|
-
tenant_handle?: string;
|
|
1043
|
-
}
|
|
1044
|
-
interface AnnotationQueue {
|
|
1045
|
-
/** The unique identifier of the annotation queue. */
|
|
1046
|
-
id: string;
|
|
1047
|
-
/** The name of the annotation queue. */
|
|
1048
|
-
name: string;
|
|
1049
|
-
/** An optional description of the annotation queue. */
|
|
1050
|
-
description?: string;
|
|
1051
|
-
/** The timestamp when the annotation queue was created. */
|
|
1052
|
-
created_at: string;
|
|
1053
|
-
/** The timestamp when the annotation queue was last updated. */
|
|
1054
|
-
updated_at: string;
|
|
1055
|
-
/** The ID of the tenant associated with the annotation queue. */
|
|
1056
|
-
tenant_id: string;
|
|
1057
|
-
}
|
|
1058
|
-
interface AnnotationQueueWithDetails extends AnnotationQueue {
|
|
1059
|
-
/** The rubric instructions for the annotation queue. */
|
|
1060
|
-
rubric_instructions?: string;
|
|
1061
|
-
}
|
|
1062
|
-
interface RunWithAnnotationQueueInfo extends BaseRun {
|
|
1063
|
-
/** The last time this run was reviewed. */
|
|
1064
|
-
last_reviewed_time?: string;
|
|
1065
|
-
/** The time this run was added to the queue. */
|
|
1066
|
-
added_at?: string;
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
interface RunTreeConfig {
|
|
1070
|
-
name: string;
|
|
1071
|
-
run_type?: string;
|
|
1072
|
-
id?: string;
|
|
1073
|
-
project_name?: string;
|
|
1074
|
-
parent_run?: RunTree;
|
|
1075
|
-
parent_run_id?: string;
|
|
1076
|
-
child_runs?: RunTree[];
|
|
1077
|
-
start_time?: number | string;
|
|
1078
|
-
end_time?: number | string;
|
|
1079
|
-
extra?: KVMap;
|
|
1080
|
-
metadata?: KVMap;
|
|
1081
|
-
tags?: string[];
|
|
1082
|
-
error?: string;
|
|
1083
|
-
serialized?: object;
|
|
1084
|
-
inputs?: KVMap;
|
|
1085
|
-
outputs?: KVMap;
|
|
1086
|
-
reference_example_id?: string;
|
|
1087
|
-
client?: Client;
|
|
1088
|
-
tracingEnabled?: boolean;
|
|
1089
|
-
on_end?: (runTree: RunTree) => void;
|
|
1090
|
-
execution_order?: number;
|
|
1091
|
-
child_execution_order?: number;
|
|
1092
|
-
trace_id?: string;
|
|
1093
|
-
dotted_order?: string;
|
|
1094
|
-
attachments?: Attachments;
|
|
1095
|
-
replicas?: Replica[];
|
|
1096
|
-
}
|
|
1097
|
-
interface RunnableConfigLike {
|
|
1098
|
-
/**
|
|
1099
|
-
* Tags for this call and any sub-calls (eg. a Chain calling an LLM).
|
|
1100
|
-
* You can use these to filter calls.
|
|
1101
|
-
*/
|
|
1102
|
-
tags?: string[];
|
|
1103
|
-
/**
|
|
1104
|
-
* Metadata for this call and any sub-calls (eg. a Chain calling an LLM).
|
|
1105
|
-
* Keys should be strings, values should be JSON-serializable.
|
|
1106
|
-
*/
|
|
1107
|
-
metadata?: Record<string, unknown>;
|
|
1108
|
-
/**
|
|
1109
|
-
* Callbacks for this call and any sub-calls (eg. a Chain calling an LLM).
|
|
1110
|
-
* Tags are passed to all callbacks, metadata is passed to handle*Start callbacks.
|
|
1111
|
-
*/
|
|
1112
|
-
callbacks?: any;
|
|
1113
|
-
}
|
|
1114
|
-
interface HeadersLike {
|
|
1115
|
-
get(name: string): string | null;
|
|
1116
|
-
set(name: string, value: string): void;
|
|
1117
|
-
}
|
|
1118
|
-
type ProjectReplica = [string, KVMap | undefined];
|
|
1119
|
-
type WriteReplica = {
|
|
1120
|
-
apiUrl?: string;
|
|
1121
|
-
apiKey?: string;
|
|
1122
|
-
projectName?: string;
|
|
1123
|
-
updates?: KVMap | undefined;
|
|
1124
|
-
fromEnv?: boolean;
|
|
1125
|
-
};
|
|
1126
|
-
type Replica = ProjectReplica | WriteReplica;
|
|
1127
|
-
declare class RunTree implements BaseRun {
|
|
1128
|
-
private static sharedClient;
|
|
1129
|
-
id: string;
|
|
1130
|
-
name: RunTreeConfig["name"];
|
|
1131
|
-
run_type: string;
|
|
1132
|
-
project_name: string;
|
|
1133
|
-
parent_run?: RunTree;
|
|
1134
|
-
parent_run_id?: string;
|
|
1135
|
-
child_runs: RunTree[];
|
|
1136
|
-
start_time: number;
|
|
1137
|
-
end_time?: number;
|
|
1138
|
-
extra: KVMap;
|
|
1139
|
-
tags?: string[];
|
|
1140
|
-
error?: string;
|
|
1141
|
-
serialized: object;
|
|
1142
|
-
inputs: KVMap;
|
|
1143
|
-
outputs?: KVMap;
|
|
1144
|
-
reference_example_id?: string;
|
|
1145
|
-
client: Client;
|
|
1146
|
-
events?: KVMap[] | undefined;
|
|
1147
|
-
trace_id: string;
|
|
1148
|
-
dotted_order: string;
|
|
1149
|
-
tracingEnabled?: boolean;
|
|
1150
|
-
execution_order: number;
|
|
1151
|
-
child_execution_order: number;
|
|
1152
|
-
/**
|
|
1153
|
-
* Attachments associated with the run.
|
|
1154
|
-
* Each entry is a tuple of [mime_type, bytes]
|
|
1155
|
-
*/
|
|
1156
|
-
attachments?: Attachments;
|
|
1157
|
-
/**
|
|
1158
|
-
* Projects to replicate this run to with optional updates.
|
|
1159
|
-
*/
|
|
1160
|
-
replicas?: WriteReplica[];
|
|
1161
|
-
private _serialized_start_time;
|
|
1162
|
-
constructor(originalConfig: RunTreeConfig | RunTree);
|
|
1163
|
-
set metadata(metadata: KVMap);
|
|
1164
|
-
get metadata(): KVMap;
|
|
1165
|
-
private static getDefaultConfig;
|
|
1166
|
-
static getSharedClient(): Client;
|
|
1167
|
-
createChild(config: RunTreeConfig): RunTree;
|
|
1168
|
-
end(outputs?: KVMap, error?: string, endTime?: number, metadata?: KVMap): Promise<void>;
|
|
1169
|
-
private _convertToCreate;
|
|
1170
|
-
private _remapForProject;
|
|
1171
|
-
postRun(excludeChildRuns?: boolean): Promise<void>;
|
|
1172
|
-
patchRun(): Promise<void>;
|
|
1173
|
-
toJSON(): RunCreate & {
|
|
1174
|
-
id: string;
|
|
1175
|
-
};
|
|
1176
|
-
/**
|
|
1177
|
-
* Add an event to the run tree.
|
|
1178
|
-
* @param event - A single event or string to add
|
|
1179
|
-
*/
|
|
1180
|
-
addEvent(event: RunEvent | string): void;
|
|
1181
|
-
static fromRunnableConfig(parentConfig: RunnableConfigLike, props: RunTreeConfig): RunTree;
|
|
1182
|
-
static fromDottedOrder(dottedOrder: string): RunTree | undefined;
|
|
1183
|
-
static fromHeaders(headers: Record<string, string | string[]> | HeadersLike, inheritArgs?: RunTreeConfig): RunTree | undefined;
|
|
1184
|
-
toHeaders(headers?: HeadersLike): {
|
|
1185
|
-
"langsmith-trace": string;
|
|
1186
|
-
baggage: string;
|
|
1187
|
-
};
|
|
1188
|
-
}
|
|
1189
|
-
interface RunEvent {
|
|
1190
|
-
name?: string;
|
|
1191
|
-
time?: string;
|
|
1192
|
-
message?: string;
|
|
1193
|
-
kwargs?: Record<string, unknown>;
|
|
1194
|
-
[key: string]: unknown;
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
/**
|
|
1198
|
-
* Represents the result of an evaluation.
|
|
1199
|
-
*/
|
|
1200
|
-
type EvaluationResult = {
|
|
1201
|
-
/**
|
|
1202
|
-
* The key associated with the evaluation result.
|
|
1203
|
-
*/
|
|
1204
|
-
key: string;
|
|
1205
|
-
/**
|
|
1206
|
-
* The score of the evaluation result.
|
|
1207
|
-
*/
|
|
1208
|
-
score?: ScoreType;
|
|
1209
|
-
/**
|
|
1210
|
-
* The value of the evaluation result.
|
|
1211
|
-
*/
|
|
1212
|
-
value?: ValueType;
|
|
1213
|
-
/**
|
|
1214
|
-
* A comment associated with the evaluation result.
|
|
1215
|
-
*/
|
|
1216
|
-
comment?: string;
|
|
1217
|
-
/**
|
|
1218
|
-
* A correction record associated with the evaluation result.
|
|
1219
|
-
*/
|
|
1220
|
-
correction?: Record<string, unknown>;
|
|
1221
|
-
/**
|
|
1222
|
-
* Information about the evaluator.
|
|
1223
|
-
*/
|
|
1224
|
-
evaluatorInfo?: Record<string, unknown>;
|
|
1225
|
-
/**
|
|
1226
|
-
* The source run ID of the evaluation result.
|
|
1227
|
-
* If set, a link to the source run will be available in the UI.
|
|
1228
|
-
*/
|
|
1229
|
-
sourceRunId?: string;
|
|
1230
|
-
/**
|
|
1231
|
-
* The target run ID of the evaluation result.
|
|
1232
|
-
* If this is not set, the target run ID is assumed to be
|
|
1233
|
-
* the root of the trace.
|
|
1234
|
-
*/
|
|
1235
|
-
targetRunId?: string;
|
|
1236
|
-
/**
|
|
1237
|
-
* The feedback config associated with the evaluation result.
|
|
1238
|
-
* If set, this will be used to define how a feedback key
|
|
1239
|
-
* should be interpreted.
|
|
1240
|
-
*/
|
|
1241
|
-
feedbackConfig?: FeedbackConfig;
|
|
1242
|
-
};
|
|
1243
|
-
/**
|
|
1244
|
-
* Batch evaluation results, if your evaluator wishes
|
|
1245
|
-
* to return multiple scores.
|
|
1246
|
-
*/
|
|
1247
|
-
type EvaluationResults = {
|
|
1248
|
-
/**
|
|
1249
|
-
* The evaluation results.
|
|
1250
|
-
*/
|
|
1251
|
-
results: Array<EvaluationResult>;
|
|
1252
|
-
};
|
|
1253
|
-
interface RunEvaluator {
|
|
1254
|
-
evaluateRun(run: Run$1, example?: Example, options?: Partial<RunTreeConfig>): Promise<EvaluationResult | EvaluationResults>;
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
interface ClientConfig {
|
|
1258
|
-
apiUrl?: string;
|
|
1259
|
-
apiKey?: string;
|
|
1260
|
-
callerOptions?: AsyncCallerParams;
|
|
1261
|
-
timeout_ms?: number;
|
|
1262
|
-
webUrl?: string;
|
|
1263
|
-
anonymizer?: (values: KVMap) => KVMap | Promise<KVMap>;
|
|
1264
|
-
hideInputs?: boolean | ((inputs: KVMap) => KVMap | Promise<KVMap>);
|
|
1265
|
-
hideOutputs?: boolean | ((outputs: KVMap) => KVMap | Promise<KVMap>);
|
|
1266
|
-
autoBatchTracing?: boolean;
|
|
1267
|
-
batchSizeBytesLimit?: number;
|
|
1268
|
-
blockOnRootRunFinalization?: boolean;
|
|
1269
|
-
traceBatchConcurrency?: number;
|
|
1270
|
-
fetchOptions?: RequestInit;
|
|
1271
|
-
/**
|
|
1272
|
-
* Whether to require manual .flush() calls before sending traces.
|
|
1273
|
-
* Useful if encountering network rate limits at trace high volumes.
|
|
1274
|
-
*/
|
|
1275
|
-
manualFlushMode?: boolean;
|
|
1276
|
-
tracingSamplingRate?: number;
|
|
1277
|
-
/**
|
|
1278
|
-
* Enable debug mode for the client. If set, all sent HTTP requests will be logged.
|
|
1279
|
-
*/
|
|
1280
|
-
debug?: boolean;
|
|
1281
|
-
}
|
|
1282
|
-
/**
|
|
1283
|
-
* Represents the parameters for listing runs (spans) from the Langsmith server.
|
|
1284
|
-
*/
|
|
1285
|
-
interface ListRunsParams {
|
|
1286
|
-
/**
|
|
1287
|
-
* The ID or IDs of the project(s) to filter by.
|
|
1288
|
-
*/
|
|
1289
|
-
projectId?: string | string[];
|
|
1290
|
-
/**
|
|
1291
|
-
* The name or names of the project(s) to filter by.
|
|
1292
|
-
*/
|
|
1293
|
-
projectName?: string | string[];
|
|
1294
|
-
/**
|
|
1295
|
-
* The ID of the trace to filter by.
|
|
1296
|
-
*/
|
|
1297
|
-
traceId?: string;
|
|
1298
|
-
/**
|
|
1299
|
-
* isRoot - Whether to only include root runs.
|
|
1300
|
-
* */
|
|
1301
|
-
isRoot?: boolean;
|
|
1302
|
-
/**
|
|
1303
|
-
* The execution order to filter by.
|
|
1304
|
-
*/
|
|
1305
|
-
executionOrder?: number;
|
|
1306
|
-
/**
|
|
1307
|
-
* The ID of the parent run to filter by.
|
|
1308
|
-
*/
|
|
1309
|
-
parentRunId?: string;
|
|
1310
|
-
/**
|
|
1311
|
-
* The order by run start date
|
|
1312
|
-
*/
|
|
1313
|
-
order?: "asc" | "desc";
|
|
1314
|
-
/**
|
|
1315
|
-
* The ID of the reference example to filter by.
|
|
1316
|
-
*/
|
|
1317
|
-
referenceExampleId?: string;
|
|
1318
|
-
/**
|
|
1319
|
-
* The start time to filter by.
|
|
1320
|
-
*/
|
|
1321
|
-
startTime?: Date;
|
|
1322
|
-
/**
|
|
1323
|
-
* The run type to filter by.
|
|
1324
|
-
*/
|
|
1325
|
-
runType?: string;
|
|
1326
|
-
/**
|
|
1327
|
-
* Indicates whether to filter by error runs.
|
|
1328
|
-
*/
|
|
1329
|
-
error?: boolean;
|
|
1330
|
-
/**
|
|
1331
|
-
* The ID or IDs of the runs to filter by.
|
|
1332
|
-
*/
|
|
1333
|
-
id?: string[];
|
|
1334
|
-
/**
|
|
1335
|
-
* The maximum number of runs to retrieve.
|
|
1336
|
-
*/
|
|
1337
|
-
limit?: number;
|
|
1338
|
-
/**
|
|
1339
|
-
* The query string to filter by.
|
|
1340
|
-
*/
|
|
1341
|
-
query?: string;
|
|
1342
|
-
/**
|
|
1343
|
-
* The filter string to apply.
|
|
1344
|
-
*
|
|
1345
|
-
* Run Filtering:
|
|
1346
|
-
* Listing runs with query params is useful for simple queries, but doesn't support many common needs, such as filtering by metadata, tags, or other fields.
|
|
1347
|
-
* LangSmith supports a filter query language to permit more complex filtering operations when fetching runs. This guide will provide a high level overview of the grammar as well as a few examples of when it can be useful.
|
|
1348
|
-
* If you'd prefer a more visual guide, you can get a taste of the language by viewing the table of runs on any of your projects' pages. We provide some recommended filters to get you started that you can copy and use the SDK.
|
|
1349
|
-
*
|
|
1350
|
-
* Grammar:
|
|
1351
|
-
* The filtering grammar is based on common comparators on fields in the run object. Supported comparators include:
|
|
1352
|
-
* - gte (greater than or equal to)
|
|
1353
|
-
* - gt (greater than)
|
|
1354
|
-
* - lte (less than or equal to)
|
|
1355
|
-
* - lt (less than)
|
|
1356
|
-
* - eq (equal to)
|
|
1357
|
-
* - neq (not equal to)
|
|
1358
|
-
* - has (check if run contains a tag or metadata json blob)
|
|
1359
|
-
* - search (search for a substring in a string field)
|
|
1360
|
-
*/
|
|
1361
|
-
filter?: string;
|
|
1362
|
-
/**
|
|
1363
|
-
* Filter to apply to the ROOT run in the trace tree. This is meant to be used in conjunction with the regular
|
|
1364
|
-
* `filter` parameter to let you filter runs by attributes of the root run within a trace. Example is filtering by
|
|
1365
|
-
* feedback assigned to the trace.
|
|
1366
|
-
*/
|
|
1367
|
-
traceFilter?: string;
|
|
1368
|
-
/**
|
|
1369
|
-
* Filter to apply to OTHER runs in the trace tree, including sibling and child runs. This is meant to be used in
|
|
1370
|
-
* conjunction with the regular `filter` parameter to let you filter runs by attributes of any run within a trace.
|
|
1371
|
-
*/
|
|
1372
|
-
treeFilter?: string;
|
|
1373
|
-
/**
|
|
1374
|
-
* The values to include in the response.
|
|
1375
|
-
*/
|
|
1376
|
-
select?: string[];
|
|
1377
|
-
}
|
|
1378
|
-
interface GroupRunsParams {
|
|
1379
|
-
/**
|
|
1380
|
-
* The ID or IDs of the project(s) to filter by.
|
|
1381
|
-
*/
|
|
1382
|
-
projectId?: string;
|
|
1383
|
-
/**
|
|
1384
|
-
* The ID or IDs of the project(s) to filter by.
|
|
1385
|
-
*/
|
|
1386
|
-
projectName?: string;
|
|
1387
|
-
/**
|
|
1388
|
-
* @example "conversation"
|
|
1389
|
-
*/
|
|
1390
|
-
groupBy: string;
|
|
1391
|
-
/**
|
|
1392
|
-
* The filter string to apply.
|
|
1393
|
-
*
|
|
1394
|
-
* Run Filtering:
|
|
1395
|
-
* Listing runs with query params is useful for simple queries, but doesn't support many common needs, such as filtering by metadata, tags, or other fields.
|
|
1396
|
-
* LangSmith supports a filter query language to permit more complex filtering operations when fetching runs. This guide will provide a high level overview of the grammar as well as a few examples of when it can be useful.
|
|
1397
|
-
* If you'd prefer a more visual guide, you can get a taste of the language by viewing the table of runs on any of your projects' pages. We provide some recommended filters to get you started that you can copy and use the SDK.
|
|
1398
|
-
*
|
|
1399
|
-
* Grammar:
|
|
1400
|
-
* The filtering grammar is based on common comparators on fields in the run object. Supported comparators include:
|
|
1401
|
-
* - gte (greater than or equal to)
|
|
1402
|
-
* - gt (greater than)
|
|
1403
|
-
* - lte (less than or equal to)
|
|
1404
|
-
* - lt (less than)
|
|
1405
|
-
* - eq (equal to)
|
|
1406
|
-
* - neq (not equal to)
|
|
1407
|
-
* - has (check if run contains a tag or metadata json blob)
|
|
1408
|
-
* - search (search for a substring in a string field)
|
|
1409
|
-
*/
|
|
1410
|
-
filter?: string;
|
|
1411
|
-
/**
|
|
1412
|
-
* The start time to filter by.
|
|
1413
|
-
*/
|
|
1414
|
-
startTime?: Date;
|
|
1415
|
-
/**
|
|
1416
|
-
* The end time to filter by.
|
|
1417
|
-
*/
|
|
1418
|
-
endTime?: Date;
|
|
1419
|
-
/**
|
|
1420
|
-
* The maximum number of runs to retrieve.
|
|
1421
|
-
*/
|
|
1422
|
-
limit?: number;
|
|
1423
|
-
/**
|
|
1424
|
-
* The maximum number of runs to retrieve.
|
|
1425
|
-
*/
|
|
1426
|
-
offset?: number;
|
|
1427
|
-
}
|
|
1428
|
-
interface UploadCSVParams {
|
|
1429
|
-
csvFile: Blob;
|
|
1430
|
-
fileName: string;
|
|
1431
|
-
inputKeys: string[];
|
|
1432
|
-
outputKeys: string[];
|
|
1433
|
-
description?: string;
|
|
1434
|
-
dataType?: DataType;
|
|
1435
|
-
name?: string;
|
|
1436
|
-
}
|
|
1437
|
-
interface CreateRunParams {
|
|
1438
|
-
name: string;
|
|
1439
|
-
inputs: KVMap;
|
|
1440
|
-
run_type: string;
|
|
1441
|
-
id?: string;
|
|
1442
|
-
start_time?: number | string;
|
|
1443
|
-
end_time?: number | string;
|
|
1444
|
-
extra?: KVMap;
|
|
1445
|
-
error?: string;
|
|
1446
|
-
serialized?: object;
|
|
1447
|
-
outputs?: KVMap;
|
|
1448
|
-
reference_example_id?: string;
|
|
1449
|
-
child_runs?: RunCreate[];
|
|
1450
|
-
parent_run_id?: string;
|
|
1451
|
-
project_name?: string;
|
|
1452
|
-
revision_id?: string;
|
|
1453
|
-
trace_id?: string;
|
|
1454
|
-
dotted_order?: string;
|
|
1455
|
-
attachments?: Attachments;
|
|
1456
|
-
}
|
|
1457
|
-
interface ProjectOptions {
|
|
1458
|
-
projectName?: string;
|
|
1459
|
-
projectId?: string;
|
|
1460
|
-
}
|
|
1461
|
-
type RecordStringAny = Record<string, any>;
|
|
1462
|
-
type FeedbackSourceType = "model" | "api" | "app";
|
|
1463
|
-
type CreateExampleOptions = {
|
|
1464
|
-
/** The ID of the dataset to create the example in. */
|
|
1465
|
-
datasetId?: string;
|
|
1466
|
-
/** The name of the dataset to create the example in (if dataset ID is not provided). */
|
|
1467
|
-
datasetName?: string;
|
|
1468
|
-
/** The creation date of the example. */
|
|
1469
|
-
createdAt?: Date;
|
|
1470
|
-
/** A unique identifier for the example. */
|
|
1471
|
-
exampleId?: string;
|
|
1472
|
-
/** Additional metadata associated with the example. */
|
|
1473
|
-
metadata?: KVMap;
|
|
1474
|
-
/** The split(s) to assign the example to. */
|
|
1475
|
-
split?: string | string[];
|
|
1476
|
-
/** The ID of the source run associated with this example. */
|
|
1477
|
-
sourceRunId?: string;
|
|
1478
|
-
/** Whether to use the inputs and outputs from the source run. */
|
|
1479
|
-
useSourceRunIO?: boolean;
|
|
1480
|
-
/** Which attachments from the source run to use. */
|
|
1481
|
-
useSourceRunAttachments?: string[];
|
|
1482
|
-
/** Attachments for the example */
|
|
1483
|
-
attachments?: Attachments;
|
|
1484
|
-
};
|
|
1485
|
-
type CreateProjectParams = {
|
|
1486
|
-
projectName: string;
|
|
1487
|
-
description?: string | null;
|
|
1488
|
-
metadata?: RecordStringAny | null;
|
|
1489
|
-
upsert?: boolean;
|
|
1490
|
-
projectExtra?: RecordStringAny | null;
|
|
1491
|
-
referenceDatasetId?: string | null;
|
|
1492
|
-
};
|
|
1493
|
-
type Thread = {
|
|
1494
|
-
filter: string;
|
|
1495
|
-
count: number;
|
|
1496
|
-
total_tokens: number;
|
|
1497
|
-
total_cost: number | null;
|
|
1498
|
-
min_start_time: string;
|
|
1499
|
-
max_start_time: string;
|
|
1500
|
-
latency_p50: number;
|
|
1501
|
-
latency_p99: number;
|
|
1502
|
-
feedback_stats: any | null;
|
|
1503
|
-
group_key: string;
|
|
1504
|
-
first_inputs: string;
|
|
1505
|
-
last_outputs: string;
|
|
1506
|
-
last_error: string | null;
|
|
1507
|
-
};
|
|
1508
|
-
declare class Client implements LangSmithTracingClientInterface {
|
|
1509
|
-
private apiKey?;
|
|
1510
|
-
private apiUrl;
|
|
1511
|
-
private webUrl?;
|
|
1512
|
-
private caller;
|
|
1513
|
-
private batchIngestCaller;
|
|
1514
|
-
private timeout_ms;
|
|
1515
|
-
private _tenantId;
|
|
1516
|
-
private hideInputs?;
|
|
1517
|
-
private hideOutputs?;
|
|
1518
|
-
private tracingSampleRate?;
|
|
1519
|
-
private filteredPostUuids;
|
|
1520
|
-
private autoBatchTracing;
|
|
1521
|
-
private autoBatchQueue;
|
|
1522
|
-
private autoBatchTimeout;
|
|
1523
|
-
private autoBatchAggregationDelayMs;
|
|
1524
|
-
private batchSizeBytesLimit?;
|
|
1525
|
-
private fetchOptions;
|
|
1526
|
-
private settings;
|
|
1527
|
-
private blockOnRootRunFinalization;
|
|
1528
|
-
private traceBatchConcurrency;
|
|
1529
|
-
private _serverInfo;
|
|
1530
|
-
private _getServerInfoPromise?;
|
|
1531
|
-
private manualFlushMode;
|
|
1532
|
-
private langSmithToOTELTranslator?;
|
|
1533
|
-
private multipartStreamingDisabled;
|
|
1534
|
-
debug: boolean;
|
|
1535
|
-
constructor(config?: ClientConfig);
|
|
1536
|
-
static getDefaultClientConfig(): {
|
|
1537
|
-
apiUrl: string;
|
|
1538
|
-
apiKey?: string;
|
|
1539
|
-
webUrl?: string;
|
|
1540
|
-
hideInputs?: boolean;
|
|
1541
|
-
hideOutputs?: boolean;
|
|
1542
|
-
};
|
|
1543
|
-
getHostUrl(): string;
|
|
1544
|
-
private get headers();
|
|
1545
|
-
private _getPlatformEndpointPath;
|
|
1546
|
-
private processInputs;
|
|
1547
|
-
private processOutputs;
|
|
1548
|
-
private prepareRunCreateOrUpdateInputs;
|
|
1549
|
-
private _getResponse;
|
|
1550
|
-
private _get;
|
|
1551
|
-
private _getPaginated;
|
|
1552
|
-
private _getCursorPaginatedList;
|
|
1553
|
-
private _shouldSample;
|
|
1554
|
-
private _filterForSampling;
|
|
1555
|
-
private _getBatchSizeLimitBytes;
|
|
1556
|
-
private _getMultiPartSupport;
|
|
1557
|
-
private drainAutoBatchQueue;
|
|
1558
|
-
private _processBatch;
|
|
1559
|
-
private _sendBatchToOTELTranslator;
|
|
1560
|
-
private processRunOperation;
|
|
1561
|
-
protected _getServerInfo(): Promise<any>;
|
|
1562
|
-
protected _ensureServerInfo(): Promise<Record<string, any>>;
|
|
1563
|
-
protected _getSettings(): Promise<LangSmithSettings>;
|
|
1564
|
-
/**
|
|
1565
|
-
* Flushes current queued traces.
|
|
1566
|
-
*/
|
|
1567
|
-
flush(): Promise<void>;
|
|
1568
|
-
private _cloneCurrentOTELContext;
|
|
1569
|
-
createRun(run: CreateRunParams, options?: {
|
|
1570
|
-
apiKey?: string;
|
|
1571
|
-
apiUrl?: string;
|
|
1572
|
-
}): Promise<void>;
|
|
1573
|
-
/**
|
|
1574
|
-
* Batch ingest/upsert multiple runs in the Langsmith system.
|
|
1575
|
-
* @param runs
|
|
1576
|
-
*/
|
|
1577
|
-
batchIngestRuns({ runCreates, runUpdates, }: {
|
|
1578
|
-
runCreates?: RunCreate[];
|
|
1579
|
-
runUpdates?: RunUpdate[];
|
|
1580
|
-
}, options?: {
|
|
1581
|
-
apiKey?: string;
|
|
1582
|
-
apiUrl?: string;
|
|
1583
|
-
}): Promise<void>;
|
|
1584
|
-
private _postBatchIngestRuns;
|
|
1585
|
-
/**
|
|
1586
|
-
* Batch ingest/upsert multiple runs in the Langsmith system.
|
|
1587
|
-
* @param runs
|
|
1588
|
-
*/
|
|
1589
|
-
multipartIngestRuns({ runCreates, runUpdates, }: {
|
|
1590
|
-
runCreates?: RunCreate[];
|
|
1591
|
-
runUpdates?: RunUpdate[];
|
|
1592
|
-
}, options?: {
|
|
1593
|
-
apiKey?: string;
|
|
1594
|
-
apiUrl?: string;
|
|
1595
|
-
}): Promise<void>;
|
|
1596
|
-
private _createNodeFetchBody;
|
|
1597
|
-
private _createMultipartStream;
|
|
1598
|
-
private _sendMultipartRequest;
|
|
1599
|
-
updateRun(runId: string, run: RunUpdate, options?: {
|
|
1600
|
-
apiKey?: string;
|
|
1601
|
-
apiUrl?: string;
|
|
1602
|
-
}): Promise<void>;
|
|
1603
|
-
readRun(runId: string, { loadChildRuns }?: {
|
|
1604
|
-
loadChildRuns: boolean;
|
|
1605
|
-
}): Promise<Run$1>;
|
|
1606
|
-
getRunUrl({ runId, run, projectOpts, }: {
|
|
1607
|
-
runId?: string;
|
|
1608
|
-
run?: Run$1;
|
|
1609
|
-
projectOpts?: ProjectOptions;
|
|
1610
|
-
}): Promise<string>;
|
|
1611
|
-
private _loadChildRuns;
|
|
1612
|
-
/**
|
|
1613
|
-
* List runs from the LangSmith server.
|
|
1614
|
-
* @param projectId - The ID of the project to filter by.
|
|
1615
|
-
* @param projectName - The name of the project to filter by.
|
|
1616
|
-
* @param parentRunId - The ID of the parent run to filter by.
|
|
1617
|
-
* @param traceId - The ID of the trace to filter by.
|
|
1618
|
-
* @param referenceExampleId - The ID of the reference example to filter by.
|
|
1619
|
-
* @param startTime - The start time to filter by.
|
|
1620
|
-
* @param isRoot - Indicates whether to only return root runs.
|
|
1621
|
-
* @param runType - The run type to filter by.
|
|
1622
|
-
* @param error - Indicates whether to filter by error runs.
|
|
1623
|
-
* @param id - The ID of the run to filter by.
|
|
1624
|
-
* @param query - The query string to filter by.
|
|
1625
|
-
* @param filter - The filter string to apply to the run spans.
|
|
1626
|
-
* @param traceFilter - The filter string to apply on the root run of the trace.
|
|
1627
|
-
* @param treeFilter - The filter string to apply on other runs in the trace.
|
|
1628
|
-
* @param limit - The maximum number of runs to retrieve.
|
|
1629
|
-
* @returns {AsyncIterable<Run>} - The runs.
|
|
1630
|
-
*
|
|
1631
|
-
* @example
|
|
1632
|
-
* // List all runs in a project
|
|
1633
|
-
* const projectRuns = client.listRuns({ projectName: "<your_project>" });
|
|
1634
|
-
*
|
|
1635
|
-
* @example
|
|
1636
|
-
* // List LLM and Chat runs in the last 24 hours
|
|
1637
|
-
* const todaysLLMRuns = client.listRuns({
|
|
1638
|
-
* projectName: "<your_project>",
|
|
1639
|
-
* start_time: new Date(Date.now() - 24 * 60 * 60 * 1000),
|
|
1640
|
-
* run_type: "llm",
|
|
1641
|
-
* });
|
|
1642
|
-
*
|
|
1643
|
-
* @example
|
|
1644
|
-
* // List traces in a project
|
|
1645
|
-
* const rootRuns = client.listRuns({
|
|
1646
|
-
* projectName: "<your_project>",
|
|
1647
|
-
* execution_order: 1,
|
|
1648
|
-
* });
|
|
1649
|
-
*
|
|
1650
|
-
* @example
|
|
1651
|
-
* // List runs without errors
|
|
1652
|
-
* const correctRuns = client.listRuns({
|
|
1653
|
-
* projectName: "<your_project>",
|
|
1654
|
-
* error: false,
|
|
1655
|
-
* });
|
|
1656
|
-
*
|
|
1657
|
-
* @example
|
|
1658
|
-
* // List runs by run ID
|
|
1659
|
-
* const runIds = [
|
|
1660
|
-
* "a36092d2-4ad5-4fb4-9c0d-0dba9a2ed836",
|
|
1661
|
-
* "9398e6be-964f-4aa4-8ae9-ad78cd4b7074",
|
|
1662
|
-
* ];
|
|
1663
|
-
* const selectedRuns = client.listRuns({ run_ids: runIds });
|
|
1664
|
-
*
|
|
1665
|
-
* @example
|
|
1666
|
-
* // List all "chain" type runs that took more than 10 seconds and had `total_tokens` greater than 5000
|
|
1667
|
-
* const chainRuns = client.listRuns({
|
|
1668
|
-
* projectName: "<your_project>",
|
|
1669
|
-
* filter: 'and(eq(run_type, "chain"), gt(latency, 10), gt(total_tokens, 5000))',
|
|
1670
|
-
* });
|
|
1671
|
-
*
|
|
1672
|
-
* @example
|
|
1673
|
-
* // List all runs called "extractor" whose root of the trace was assigned feedback "user_score" score of 1
|
|
1674
|
-
* const goodExtractorRuns = client.listRuns({
|
|
1675
|
-
* projectName: "<your_project>",
|
|
1676
|
-
* filter: 'eq(name, "extractor")',
|
|
1677
|
-
* traceFilter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
|
|
1678
|
-
* });
|
|
1679
|
-
*
|
|
1680
|
-
* @example
|
|
1681
|
-
* // List all runs that started after a specific timestamp and either have "error" not equal to null or a "Correctness" feedback score equal to 0
|
|
1682
|
-
* const complexRuns = client.listRuns({
|
|
1683
|
-
* projectName: "<your_project>",
|
|
1684
|
-
* filter: 'and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(error, null), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))',
|
|
1685
|
-
* });
|
|
1686
|
-
*
|
|
1687
|
-
* @example
|
|
1688
|
-
* // List all runs where `tags` include "experimental" or "beta" and `latency` is greater than 2 seconds
|
|
1689
|
-
* const taggedRuns = client.listRuns({
|
|
1690
|
-
* projectName: "<your_project>",
|
|
1691
|
-
* filter: 'and(or(has(tags, "experimental"), has(tags, "beta")), gt(latency, 2))',
|
|
1692
|
-
* });
|
|
1693
|
-
*/
|
|
1694
|
-
listRuns(props: ListRunsParams): AsyncIterable<Run$1>;
|
|
1695
|
-
listGroupRuns(props: GroupRunsParams): AsyncIterable<Thread>;
|
|
1696
|
-
getRunStats({ id, trace, parentRun, runType, projectNames, projectIds, referenceExampleIds, startTime, endTime, error, query, filter, traceFilter, treeFilter, isRoot, dataSourceType, }: {
|
|
1697
|
-
id?: string[];
|
|
1698
|
-
trace?: string;
|
|
1699
|
-
parentRun?: string;
|
|
1700
|
-
runType?: string;
|
|
1701
|
-
projectNames?: string[];
|
|
1702
|
-
projectIds?: string[];
|
|
1703
|
-
referenceExampleIds?: string[];
|
|
1704
|
-
startTime?: string;
|
|
1705
|
-
endTime?: string;
|
|
1706
|
-
error?: boolean;
|
|
1707
|
-
query?: string;
|
|
1708
|
-
filter?: string;
|
|
1709
|
-
traceFilter?: string;
|
|
1710
|
-
treeFilter?: string;
|
|
1711
|
-
isRoot?: boolean;
|
|
1712
|
-
dataSourceType?: string;
|
|
1713
|
-
}): Promise<any>;
|
|
1714
|
-
shareRun(runId: string, { shareId }?: {
|
|
1715
|
-
shareId?: string;
|
|
1716
|
-
}): Promise<string>;
|
|
1717
|
-
unshareRun(runId: string): Promise<void>;
|
|
1718
|
-
readRunSharedLink(runId: string): Promise<string | undefined>;
|
|
1719
|
-
listSharedRuns(shareToken: string, { runIds, }?: {
|
|
1720
|
-
runIds?: string[];
|
|
1721
|
-
}): Promise<Run$1[]>;
|
|
1722
|
-
readDatasetSharedSchema(datasetId?: string, datasetName?: string): Promise<DatasetShareSchema>;
|
|
1723
|
-
shareDataset(datasetId?: string, datasetName?: string): Promise<DatasetShareSchema>;
|
|
1724
|
-
unshareDataset(datasetId: string): Promise<void>;
|
|
1725
|
-
readSharedDataset(shareToken: string): Promise<Dataset>;
|
|
1726
|
-
/**
|
|
1727
|
-
* Get shared examples.
|
|
1728
|
-
*
|
|
1729
|
-
* @param {string} shareToken The share token to get examples for. A share token is the UUID (or LangSmith URL, including UUID) generated when explicitly marking an example as public.
|
|
1730
|
-
* @param {Object} [options] Additional options for listing the examples.
|
|
1731
|
-
* @param {string[] | undefined} [options.exampleIds] A list of example IDs to filter by.
|
|
1732
|
-
* @returns {Promise<Example[]>} The shared examples.
|
|
1733
|
-
*/
|
|
1734
|
-
listSharedExamples(shareToken: string, options?: {
|
|
1735
|
-
exampleIds?: string[];
|
|
1736
|
-
}): Promise<Example[]>;
|
|
1737
|
-
createProject({ projectName, description, metadata, upsert, projectExtra, referenceDatasetId, }: CreateProjectParams): Promise<TracerSession>;
|
|
1738
|
-
updateProject(projectId: string, { name, description, metadata, projectExtra, endTime, }: {
|
|
1739
|
-
name?: string | null;
|
|
1740
|
-
description?: string | null;
|
|
1741
|
-
metadata?: RecordStringAny | null;
|
|
1742
|
-
projectExtra?: RecordStringAny | null;
|
|
1743
|
-
endTime?: string | null;
|
|
1744
|
-
}): Promise<TracerSession>;
|
|
1745
|
-
hasProject({ projectId, projectName, }: {
|
|
1746
|
-
projectId?: string;
|
|
1747
|
-
projectName?: string;
|
|
1748
|
-
}): Promise<boolean>;
|
|
1749
|
-
readProject({ projectId, projectName, includeStats, }: {
|
|
1750
|
-
projectId?: string;
|
|
1751
|
-
projectName?: string;
|
|
1752
|
-
includeStats?: boolean;
|
|
1753
|
-
}): Promise<TracerSessionResult>;
|
|
1754
|
-
getProjectUrl({ projectId, projectName, }: {
|
|
1755
|
-
projectId?: string;
|
|
1756
|
-
projectName?: string;
|
|
1757
|
-
}): Promise<string>;
|
|
1758
|
-
getDatasetUrl({ datasetId, datasetName, }: {
|
|
1759
|
-
datasetId?: string;
|
|
1760
|
-
datasetName?: string;
|
|
1761
|
-
}): Promise<string>;
|
|
1762
|
-
private _getTenantId;
|
|
1763
|
-
listProjects({ projectIds, name, nameContains, referenceDatasetId, referenceDatasetName, referenceFree, metadata, }?: {
|
|
1764
|
-
projectIds?: string[];
|
|
1765
|
-
name?: string;
|
|
1766
|
-
nameContains?: string;
|
|
1767
|
-
referenceDatasetId?: string;
|
|
1768
|
-
referenceDatasetName?: string;
|
|
1769
|
-
referenceFree?: boolean;
|
|
1770
|
-
metadata?: RecordStringAny;
|
|
1771
|
-
}): AsyncIterable<TracerSession>;
|
|
1772
|
-
deleteProject({ projectId, projectName, }: {
|
|
1773
|
-
projectId?: string;
|
|
1774
|
-
projectName?: string;
|
|
1775
|
-
}): Promise<void>;
|
|
1776
|
-
uploadCsv({ csvFile, fileName, inputKeys, outputKeys, description, dataType, name, }: UploadCSVParams): Promise<Dataset>;
|
|
1777
|
-
createDataset(name: string, { description, dataType, inputsSchema, outputsSchema, metadata, }?: {
|
|
1778
|
-
description?: string;
|
|
1779
|
-
dataType?: DataType;
|
|
1780
|
-
inputsSchema?: KVMap;
|
|
1781
|
-
outputsSchema?: KVMap;
|
|
1782
|
-
metadata?: RecordStringAny;
|
|
1783
|
-
}): Promise<Dataset>;
|
|
1784
|
-
readDataset({ datasetId, datasetName, }: {
|
|
1785
|
-
datasetId?: string;
|
|
1786
|
-
datasetName?: string;
|
|
1787
|
-
}): Promise<Dataset>;
|
|
1788
|
-
hasDataset({ datasetId, datasetName, }: {
|
|
1789
|
-
datasetId?: string;
|
|
1790
|
-
datasetName?: string;
|
|
1791
|
-
}): Promise<boolean>;
|
|
1792
|
-
diffDatasetVersions({ datasetId, datasetName, fromVersion, toVersion, }: {
|
|
1793
|
-
datasetId?: string;
|
|
1794
|
-
datasetName?: string;
|
|
1795
|
-
fromVersion: string | Date;
|
|
1796
|
-
toVersion: string | Date;
|
|
1797
|
-
}): Promise<DatasetDiffInfo>;
|
|
1798
|
-
readDatasetOpenaiFinetuning({ datasetId, datasetName, }: {
|
|
1799
|
-
datasetId?: string;
|
|
1800
|
-
datasetName?: string;
|
|
1801
|
-
}): Promise<any[]>;
|
|
1802
|
-
listDatasets({ limit, offset, datasetIds, datasetName, datasetNameContains, metadata, }?: {
|
|
1803
|
-
limit?: number;
|
|
1804
|
-
offset?: number;
|
|
1805
|
-
datasetIds?: string[];
|
|
1806
|
-
datasetName?: string;
|
|
1807
|
-
datasetNameContains?: string;
|
|
1808
|
-
metadata?: RecordStringAny;
|
|
1809
|
-
}): AsyncIterable<Dataset>;
|
|
1810
|
-
/**
|
|
1811
|
-
* Update a dataset
|
|
1812
|
-
* @param props The dataset details to update
|
|
1813
|
-
* @returns The updated dataset
|
|
1814
|
-
*/
|
|
1815
|
-
updateDataset(props: {
|
|
1816
|
-
datasetId?: string;
|
|
1817
|
-
datasetName?: string;
|
|
1818
|
-
name?: string;
|
|
1819
|
-
description?: string;
|
|
1820
|
-
}): Promise<Dataset>;
|
|
1821
|
-
/**
|
|
1822
|
-
* Updates a tag on a dataset.
|
|
1823
|
-
*
|
|
1824
|
-
* If the tag is already assigned to a different version of this dataset,
|
|
1825
|
-
* the tag will be moved to the new version. The as_of parameter is used to
|
|
1826
|
-
* determine which version of the dataset to apply the new tags to.
|
|
1827
|
-
*
|
|
1828
|
-
* It must be an exact version of the dataset to succeed. You can
|
|
1829
|
-
* use the "readDatasetVersion" method to find the exact version
|
|
1830
|
-
* to apply the tags to.
|
|
1831
|
-
* @param params.datasetId The ID of the dataset to update. Must be provided if "datasetName" is not provided.
|
|
1832
|
-
* @param params.datasetName The name of the dataset to update. Must be provided if "datasetId" is not provided.
|
|
1833
|
-
* @param params.asOf The timestamp of the dataset to apply the new tags to.
|
|
1834
|
-
* @param params.tag The new tag to apply to the dataset.
|
|
1835
|
-
*/
|
|
1836
|
-
updateDatasetTag(props: {
|
|
1837
|
-
datasetId?: string;
|
|
1838
|
-
datasetName?: string;
|
|
1839
|
-
asOf: string | Date;
|
|
1840
|
-
tag: string;
|
|
1841
|
-
}): Promise<void>;
|
|
1842
|
-
deleteDataset({ datasetId, datasetName, }: {
|
|
1843
|
-
datasetId?: string;
|
|
1844
|
-
datasetName?: string;
|
|
1845
|
-
}): Promise<void>;
|
|
1846
|
-
indexDataset({ datasetId, datasetName, tag, }: {
|
|
1847
|
-
datasetId?: string;
|
|
1848
|
-
datasetName?: string;
|
|
1849
|
-
tag?: string;
|
|
1850
|
-
}): Promise<void>;
|
|
1851
|
-
/**
|
|
1852
|
-
* Lets you run a similarity search query on a dataset.
|
|
1853
|
-
*
|
|
1854
|
-
* Requires the dataset to be indexed. Please see the `indexDataset` method to set up indexing.
|
|
1855
|
-
*
|
|
1856
|
-
* @param inputs The input on which to run the similarity search. Must have the
|
|
1857
|
-
* same schema as the dataset.
|
|
1858
|
-
*
|
|
1859
|
-
* @param datasetId The dataset to search for similar examples.
|
|
1860
|
-
*
|
|
1861
|
-
* @param limit The maximum number of examples to return. Will return the top `limit` most
|
|
1862
|
-
* similar examples in order of most similar to least similar. If no similar
|
|
1863
|
-
* examples are found, random examples will be returned.
|
|
1864
|
-
*
|
|
1865
|
-
* @param filter A filter string to apply to the search. Only examples will be returned that
|
|
1866
|
-
* match the filter string. Some examples of filters
|
|
1867
|
-
*
|
|
1868
|
-
* - eq(metadata.mykey, "value")
|
|
1869
|
-
* - and(neq(metadata.my.nested.key, "value"), neq(metadata.mykey, "value"))
|
|
1870
|
-
* - or(eq(metadata.mykey, "value"), eq(metadata.mykey, "othervalue"))
|
|
1871
|
-
*
|
|
1872
|
-
* @returns A list of similar examples.
|
|
1873
|
-
*
|
|
1874
|
-
*
|
|
1875
|
-
* @example
|
|
1876
|
-
* dataset_id = "123e4567-e89b-12d3-a456-426614174000"
|
|
1877
|
-
* inputs = {"text": "How many people live in Berlin?"}
|
|
1878
|
-
* limit = 5
|
|
1879
|
-
* examples = await client.similarExamples(inputs, dataset_id, limit)
|
|
1880
|
-
*/
|
|
1881
|
-
similarExamples(inputs: KVMap, datasetId: string, limit: number, { filter, }?: {
|
|
1882
|
-
filter?: string;
|
|
1883
|
-
}): Promise<ExampleSearch[]>;
|
|
1884
|
-
createExample(update: ExampleCreate): Promise<Example>;
|
|
1885
|
-
/**
|
|
1886
|
-
* @deprecated This signature is deprecated, use createExample(update: ExampleCreate) instead
|
|
1887
|
-
*/
|
|
1888
|
-
createExample(inputs: KVMap, outputs: KVMap, options: CreateExampleOptions): Promise<Example>;
|
|
1889
|
-
createExamples(uploads: ExampleCreate[]): Promise<Example[]>;
|
|
1890
|
-
/** @deprecated Use the uploads-only overload instead */
|
|
1891
|
-
createExamples(props: {
|
|
1892
|
-
inputs?: Array<KVMap>;
|
|
1893
|
-
outputs?: Array<KVMap>;
|
|
1894
|
-
metadata?: Array<KVMap>;
|
|
1895
|
-
splits?: Array<string | Array<string>>;
|
|
1896
|
-
sourceRunIds?: Array<string>;
|
|
1897
|
-
useSourceRunIOs?: Array<boolean>;
|
|
1898
|
-
useSourceRunAttachments?: Array<string[]>;
|
|
1899
|
-
attachments?: Array<Attachments>;
|
|
1900
|
-
exampleIds?: Array<string>;
|
|
1901
|
-
datasetId?: string;
|
|
1902
|
-
datasetName?: string;
|
|
1903
|
-
}): Promise<Example[]>;
|
|
1904
|
-
createLLMExample(input: string, generation: string | undefined, options: CreateExampleOptions): Promise<Example>;
|
|
1905
|
-
createChatExample(input: KVMap[] | LangChainBaseMessage[], generations: KVMap | LangChainBaseMessage | undefined, options: CreateExampleOptions): Promise<Example>;
|
|
1906
|
-
readExample(exampleId: string): Promise<Example>;
|
|
1907
|
-
listExamples({ datasetId, datasetName, exampleIds, asOf, splits, inlineS3Urls, metadata, limit, offset, filter, includeAttachments, }?: {
|
|
1908
|
-
datasetId?: string;
|
|
1909
|
-
datasetName?: string;
|
|
1910
|
-
exampleIds?: string[];
|
|
1911
|
-
asOf?: string | Date;
|
|
1912
|
-
splits?: string[];
|
|
1913
|
-
inlineS3Urls?: boolean;
|
|
1914
|
-
metadata?: KVMap;
|
|
1915
|
-
limit?: number;
|
|
1916
|
-
offset?: number;
|
|
1917
|
-
filter?: string;
|
|
1918
|
-
includeAttachments?: boolean;
|
|
1919
|
-
}): AsyncIterable<Example>;
|
|
1920
|
-
deleteExample(exampleId: string): Promise<void>;
|
|
1921
|
-
/**
|
|
1922
|
-
* @deprecated This signature is deprecated, use updateExample(update: ExampleUpdate) instead
|
|
1923
|
-
*/
|
|
1924
|
-
updateExample(exampleId: string, update: ExampleUpdateWithoutId): Promise<object>;
|
|
1925
|
-
updateExample(update: ExampleUpdate): Promise<object>;
|
|
1926
|
-
updateExamples(update: ExampleUpdate[]): Promise<object>;
|
|
1927
|
-
/**
|
|
1928
|
-
* Get dataset version by closest date or exact tag.
|
|
1929
|
-
*
|
|
1930
|
-
* Use this to resolve the nearest version to a given timestamp or for a given tag.
|
|
1931
|
-
*
|
|
1932
|
-
* @param options The options for getting the dataset version
|
|
1933
|
-
* @param options.datasetId The ID of the dataset
|
|
1934
|
-
* @param options.datasetName The name of the dataset
|
|
1935
|
-
* @param options.asOf The timestamp of the dataset to retrieve
|
|
1936
|
-
* @param options.tag The tag of the dataset to retrieve
|
|
1937
|
-
* @returns The dataset version
|
|
1938
|
-
*/
|
|
1939
|
-
readDatasetVersion({ datasetId, datasetName, asOf, tag, }: {
|
|
1940
|
-
datasetId?: string;
|
|
1941
|
-
datasetName?: string;
|
|
1942
|
-
asOf?: string | Date;
|
|
1943
|
-
tag?: string;
|
|
1944
|
-
}): Promise<DatasetVersion>;
|
|
1945
|
-
listDatasetSplits({ datasetId, datasetName, asOf, }: {
|
|
1946
|
-
datasetId?: string;
|
|
1947
|
-
datasetName?: string;
|
|
1948
|
-
asOf?: string | Date;
|
|
1949
|
-
}): Promise<string[]>;
|
|
1950
|
-
updateDatasetSplits({ datasetId, datasetName, splitName, exampleIds, remove, }: {
|
|
1951
|
-
datasetId?: string;
|
|
1952
|
-
datasetName?: string;
|
|
1953
|
-
splitName: string;
|
|
1954
|
-
exampleIds: string[];
|
|
1955
|
-
remove?: boolean;
|
|
1956
|
-
}): Promise<void>;
|
|
1957
|
-
/**
|
|
1958
|
-
* @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
|
|
1959
|
-
*/
|
|
1960
|
-
evaluateRun(run: Run$1 | string, evaluator: RunEvaluator, { sourceInfo, loadChildRuns, referenceExample, }?: {
|
|
1961
|
-
sourceInfo?: KVMap;
|
|
1962
|
-
loadChildRuns: boolean;
|
|
1963
|
-
referenceExample?: Example;
|
|
1964
|
-
}): Promise<Feedback>;
|
|
1965
|
-
createFeedback(runId: string | null, key: string, { score, value, correction, comment, sourceInfo, feedbackSourceType, sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, }: {
|
|
1966
|
-
score?: ScoreType;
|
|
1967
|
-
value?: ValueType;
|
|
1968
|
-
correction?: object;
|
|
1969
|
-
comment?: string;
|
|
1970
|
-
sourceInfo?: object;
|
|
1971
|
-
feedbackSourceType?: FeedbackSourceType;
|
|
1972
|
-
feedbackConfig?: FeedbackConfig;
|
|
1973
|
-
sourceRunId?: string;
|
|
1974
|
-
feedbackId?: string;
|
|
1975
|
-
eager?: boolean;
|
|
1976
|
-
projectId?: string;
|
|
1977
|
-
comparativeExperimentId?: string;
|
|
1978
|
-
}): Promise<Feedback>;
|
|
1979
|
-
updateFeedback(feedbackId: string, { score, value, correction, comment, }: {
|
|
1980
|
-
score?: number | boolean | null;
|
|
1981
|
-
value?: number | boolean | string | object | null;
|
|
1982
|
-
correction?: object | null;
|
|
1983
|
-
comment?: string | null;
|
|
1984
|
-
}): Promise<void>;
|
|
1985
|
-
readFeedback(feedbackId: string): Promise<Feedback>;
|
|
1986
|
-
deleteFeedback(feedbackId: string): Promise<void>;
|
|
1987
|
-
listFeedback({ runIds, feedbackKeys, feedbackSourceTypes, }?: {
|
|
1988
|
-
runIds?: string[];
|
|
1989
|
-
feedbackKeys?: string[];
|
|
1990
|
-
feedbackSourceTypes?: FeedbackSourceType[];
|
|
1991
|
-
}): AsyncIterable<Feedback>;
|
|
1992
|
-
/**
|
|
1993
|
-
* Creates a presigned feedback token and URL.
|
|
1994
|
-
*
|
|
1995
|
-
* The token can be used to authorize feedback metrics without
|
|
1996
|
-
* needing an API key. This is useful for giving browser-based
|
|
1997
|
-
* applications the ability to submit feedback without needing
|
|
1998
|
-
* to expose an API key.
|
|
1999
|
-
*
|
|
2000
|
-
* @param runId The ID of the run.
|
|
2001
|
-
* @param feedbackKey The feedback key.
|
|
2002
|
-
* @param options Additional options for the token.
|
|
2003
|
-
* @param options.expiration The expiration time for the token.
|
|
2004
|
-
*
|
|
2005
|
-
* @returns A promise that resolves to a FeedbackIngestToken.
|
|
2006
|
-
*/
|
|
2007
|
-
createPresignedFeedbackToken(runId: string, feedbackKey: string, { expiration, feedbackConfig, }?: {
|
|
2008
|
-
expiration?: string | TimeDelta;
|
|
2009
|
-
feedbackConfig?: FeedbackConfig;
|
|
2010
|
-
}): Promise<FeedbackIngestToken>;
|
|
2011
|
-
createComparativeExperiment({ name, experimentIds, referenceDatasetId, createdAt, description, metadata, id, }: {
|
|
2012
|
-
name: string;
|
|
2013
|
-
experimentIds: Array<string>;
|
|
2014
|
-
referenceDatasetId?: string;
|
|
2015
|
-
createdAt?: Date;
|
|
2016
|
-
description?: string;
|
|
2017
|
-
metadata?: Record<string, unknown>;
|
|
2018
|
-
id?: string;
|
|
2019
|
-
}): Promise<ComparativeExperiment>;
|
|
2020
|
-
/**
|
|
2021
|
-
* Retrieves a list of presigned feedback tokens for a given run ID.
|
|
2022
|
-
* @param runId The ID of the run.
|
|
2023
|
-
* @returns An async iterable of FeedbackIngestToken objects.
|
|
2024
|
-
*/
|
|
2025
|
-
listPresignedFeedbackTokens(runId: string): AsyncIterable<FeedbackIngestToken>;
|
|
2026
|
-
_selectEvalResults(results: EvaluationResult | EvaluationResult[] | EvaluationResults): Array<EvaluationResult>;
|
|
2027
|
-
_logEvaluationFeedback(evaluatorResponse: EvaluationResult | EvaluationResult[] | EvaluationResults, run?: Run$1, sourceInfo?: {
|
|
2028
|
-
[key: string]: any;
|
|
2029
|
-
}): Promise<[results: EvaluationResult[], feedbacks: Feedback[]]>;
|
|
2030
|
-
logEvaluationFeedback(evaluatorResponse: EvaluationResult | EvaluationResult[] | EvaluationResults, run?: Run$1, sourceInfo?: {
|
|
2031
|
-
[key: string]: any;
|
|
2032
|
-
}): Promise<EvaluationResult[]>;
|
|
2033
|
-
/**
|
|
2034
|
-
* API for managing annotation queues
|
|
2035
|
-
*/
|
|
2036
|
-
/**
|
|
2037
|
-
* List the annotation queues on the LangSmith API.
|
|
2038
|
-
* @param options - The options for listing annotation queues
|
|
2039
|
-
* @param options.queueIds - The IDs of the queues to filter by
|
|
2040
|
-
* @param options.name - The name of the queue to filter by
|
|
2041
|
-
* @param options.nameContains - The substring that the queue name should contain
|
|
2042
|
-
* @param options.limit - The maximum number of queues to return
|
|
2043
|
-
* @returns An iterator of AnnotationQueue objects
|
|
2044
|
-
*/
|
|
2045
|
-
listAnnotationQueues(options?: {
|
|
2046
|
-
queueIds?: string[];
|
|
2047
|
-
name?: string;
|
|
2048
|
-
nameContains?: string;
|
|
2049
|
-
limit?: number;
|
|
2050
|
-
}): AsyncIterableIterator<AnnotationQueue>;
|
|
2051
|
-
/**
|
|
2052
|
-
* Create an annotation queue on the LangSmith API.
|
|
2053
|
-
* @param options - The options for creating an annotation queue
|
|
2054
|
-
* @param options.name - The name of the annotation queue
|
|
2055
|
-
* @param options.description - The description of the annotation queue
|
|
2056
|
-
* @param options.queueId - The ID of the annotation queue
|
|
2057
|
-
* @returns The created AnnotationQueue object
|
|
2058
|
-
*/
|
|
2059
|
-
createAnnotationQueue(options: {
|
|
2060
|
-
name: string;
|
|
2061
|
-
description?: string;
|
|
2062
|
-
queueId?: string;
|
|
2063
|
-
rubricInstructions?: string;
|
|
2064
|
-
}): Promise<AnnotationQueueWithDetails>;
|
|
2065
|
-
/**
|
|
2066
|
-
* Read an annotation queue with the specified queue ID.
|
|
2067
|
-
* @param queueId - The ID of the annotation queue to read
|
|
2068
|
-
* @returns The AnnotationQueueWithDetails object
|
|
2069
|
-
*/
|
|
2070
|
-
readAnnotationQueue(queueId: string): Promise<AnnotationQueueWithDetails>;
|
|
2071
|
-
/**
|
|
2072
|
-
* Update an annotation queue with the specified queue ID.
|
|
2073
|
-
* @param queueId - The ID of the annotation queue to update
|
|
2074
|
-
* @param options - The options for updating the annotation queue
|
|
2075
|
-
* @param options.name - The new name for the annotation queue
|
|
2076
|
-
* @param options.description - The new description for the annotation queue
|
|
2077
|
-
*/
|
|
2078
|
-
updateAnnotationQueue(queueId: string, options: {
|
|
2079
|
-
name: string;
|
|
2080
|
-
description?: string;
|
|
2081
|
-
rubricInstructions?: string;
|
|
2082
|
-
}): Promise<void>;
|
|
2083
|
-
/**
|
|
2084
|
-
* Delete an annotation queue with the specified queue ID.
|
|
2085
|
-
* @param queueId - The ID of the annotation queue to delete
|
|
2086
|
-
*/
|
|
2087
|
-
deleteAnnotationQueue(queueId: string): Promise<void>;
|
|
2088
|
-
/**
|
|
2089
|
-
* Add runs to an annotation queue with the specified queue ID.
|
|
2090
|
-
* @param queueId - The ID of the annotation queue
|
|
2091
|
-
* @param runIds - The IDs of the runs to be added to the annotation queue
|
|
2092
|
-
*/
|
|
2093
|
-
addRunsToAnnotationQueue(queueId: string, runIds: string[]): Promise<void>;
|
|
2094
|
-
/**
|
|
2095
|
-
* Get a run from an annotation queue at the specified index.
|
|
2096
|
-
* @param queueId - The ID of the annotation queue
|
|
2097
|
-
* @param index - The index of the run to retrieve
|
|
2098
|
-
* @returns A Promise that resolves to a RunWithAnnotationQueueInfo object
|
|
2099
|
-
* @throws {Error} If the run is not found at the given index or for other API-related errors
|
|
2100
|
-
*/
|
|
2101
|
-
getRunFromAnnotationQueue(queueId: string, index: number): Promise<RunWithAnnotationQueueInfo>;
|
|
2102
|
-
/**
|
|
2103
|
-
* Delete a run from an an annotation queue.
|
|
2104
|
-
* @param queueId - The ID of the annotation queue to delete the run from
|
|
2105
|
-
* @param queueRunId - The ID of the run to delete from the annotation queue
|
|
2106
|
-
*/
|
|
2107
|
-
deleteRunFromAnnotationQueue(queueId: string, queueRunId: string): Promise<void>;
|
|
2108
|
-
/**
|
|
2109
|
-
* Get the size of an annotation queue.
|
|
2110
|
-
* @param queueId - The ID of the annotation queue
|
|
2111
|
-
*/
|
|
2112
|
-
getSizeFromAnnotationQueue(queueId: string): Promise<{
|
|
2113
|
-
size: number;
|
|
2114
|
-
}>;
|
|
2115
|
-
protected _currentTenantIsOwner(owner: string): Promise<boolean>;
|
|
2116
|
-
protected _ownerConflictError(action: string, owner: string): Promise<Error>;
|
|
2117
|
-
protected _getLatestCommitHash(promptOwnerAndName: string): Promise<string | undefined>;
|
|
2118
|
-
protected _likeOrUnlikePrompt(promptIdentifier: string, like: boolean): Promise<LikePromptResponse>;
|
|
2119
|
-
protected _getPromptUrl(promptIdentifier: string): Promise<string>;
|
|
2120
|
-
promptExists(promptIdentifier: string): Promise<boolean>;
|
|
2121
|
-
likePrompt(promptIdentifier: string): Promise<LikePromptResponse>;
|
|
2122
|
-
unlikePrompt(promptIdentifier: string): Promise<LikePromptResponse>;
|
|
2123
|
-
listCommits(promptOwnerAndName: string): AsyncIterableIterator<PromptCommit>;
|
|
2124
|
-
listPrompts(options?: {
|
|
2125
|
-
isPublic?: boolean;
|
|
2126
|
-
isArchived?: boolean;
|
|
2127
|
-
sortField?: PromptSortField;
|
|
2128
|
-
query?: string;
|
|
2129
|
-
}): AsyncIterableIterator<Prompt>;
|
|
2130
|
-
getPrompt(promptIdentifier: string): Promise<Prompt | null>;
|
|
2131
|
-
createPrompt(promptIdentifier: string, options?: {
|
|
2132
|
-
description?: string;
|
|
2133
|
-
readme?: string;
|
|
2134
|
-
tags?: string[];
|
|
2135
|
-
isPublic?: boolean;
|
|
2136
|
-
}): Promise<Prompt>;
|
|
2137
|
-
createCommit(promptIdentifier: string, object: any, options?: {
|
|
2138
|
-
parentCommitHash?: string;
|
|
2139
|
-
}): Promise<string>;
|
|
2140
|
-
/**
|
|
2141
|
-
* Update examples with attachments using multipart form data.
|
|
2142
|
-
* @param updates List of ExampleUpdateWithAttachments objects to upsert
|
|
2143
|
-
* @returns Promise with the update response
|
|
2144
|
-
*/
|
|
2145
|
-
updateExamplesMultipart(datasetId: string, updates?: ExampleUpdate[]): Promise<UpdateExamplesResponse>;
|
|
2146
|
-
private _updateExamplesMultipart;
|
|
2147
|
-
/**
|
|
2148
|
-
* Upload examples with attachments using multipart form data.
|
|
2149
|
-
* @param uploads List of ExampleUploadWithAttachments objects to upload
|
|
2150
|
-
* @returns Promise with the upload response
|
|
2151
|
-
* @deprecated This method is deprecated and will be removed in future LangSmith versions, please use `createExamples` instead
|
|
2152
|
-
*/
|
|
2153
|
-
uploadExamplesMultipart(datasetId: string, uploads?: ExampleCreate[]): Promise<UploadExamplesResponse>;
|
|
2154
|
-
private _uploadExamplesMultipart;
|
|
2155
|
-
updatePrompt(promptIdentifier: string, options?: {
|
|
2156
|
-
description?: string;
|
|
2157
|
-
readme?: string;
|
|
2158
|
-
tags?: string[];
|
|
2159
|
-
isPublic?: boolean;
|
|
2160
|
-
isArchived?: boolean;
|
|
2161
|
-
}): Promise<Record<string, any>>;
|
|
2162
|
-
deletePrompt(promptIdentifier: string): Promise<void>;
|
|
2163
|
-
pullPromptCommit(promptIdentifier: string, options?: {
|
|
2164
|
-
includeModel?: boolean;
|
|
2165
|
-
}): Promise<PromptCommit>;
|
|
2166
|
-
/**
|
|
2167
|
-
* This method should not be used directly, use `import { pull } from "langchain/hub"` instead.
|
|
2168
|
-
* Using this method directly returns the JSON string of the prompt rather than a LangChain object.
|
|
2169
|
-
* @private
|
|
2170
|
-
*/
|
|
2171
|
-
_pullPrompt(promptIdentifier: string, options?: {
|
|
2172
|
-
includeModel?: boolean;
|
|
2173
|
-
}): Promise<any>;
|
|
2174
|
-
pushPrompt(promptIdentifier: string, options?: {
|
|
2175
|
-
object?: any;
|
|
2176
|
-
parentCommitHash?: string;
|
|
2177
|
-
isPublic?: boolean;
|
|
2178
|
-
description?: string;
|
|
2179
|
-
readme?: string;
|
|
2180
|
-
tags?: string[];
|
|
2181
|
-
}): Promise<string>;
|
|
2182
|
-
/**
|
|
2183
|
-
* Clone a public dataset to your own langsmith tenant.
|
|
2184
|
-
* This operation is idempotent. If you already have a dataset with the given name,
|
|
2185
|
-
* this function will do nothing.
|
|
2186
|
-
|
|
2187
|
-
* @param {string} tokenOrUrl The token of the public dataset to clone.
|
|
2188
|
-
* @param {Object} [options] Additional options for cloning the dataset.
|
|
2189
|
-
* @param {string} [options.sourceApiUrl] The URL of the langsmith server where the data is hosted. Defaults to the API URL of your current client.
|
|
2190
|
-
* @param {string} [options.datasetName] The name of the dataset to create in your tenant. Defaults to the name of the public dataset.
|
|
2191
|
-
* @returns {Promise<void>}
|
|
2192
|
-
*/
|
|
2193
|
-
clonePublicDataset(tokenOrUrl: string, options?: {
|
|
2194
|
-
sourceApiUrl?: string;
|
|
2195
|
-
datasetName?: string;
|
|
2196
|
-
}): Promise<void>;
|
|
2197
|
-
private parseTokenOrUrl;
|
|
2198
|
-
/**
|
|
2199
|
-
* Awaits all pending trace batches. Useful for environments where
|
|
2200
|
-
* you need to be sure that all tracing requests finish before execution ends,
|
|
2201
|
-
* such as serverless environments.
|
|
2202
|
-
*
|
|
2203
|
-
* @example
|
|
2204
|
-
* ```
|
|
2205
|
-
* import { Client } from "langsmith";
|
|
2206
|
-
*
|
|
2207
|
-
* const client = new Client();
|
|
2208
|
-
*
|
|
2209
|
-
* try {
|
|
2210
|
-
* // Tracing happens here
|
|
2211
|
-
* ...
|
|
2212
|
-
* } finally {
|
|
2213
|
-
* await client.awaitPendingTraceBatches();
|
|
2214
|
-
* }
|
|
2215
|
-
* ```
|
|
2216
|
-
*
|
|
2217
|
-
* @returns A promise that resolves once all currently pending traces have sent.
|
|
2218
|
-
*/
|
|
2219
|
-
awaitPendingTraceBatches(): Promise<void>;
|
|
2220
|
-
}
|
|
2221
|
-
interface LangSmithTracingClientInterface {
|
|
2222
|
-
createRun: (run: CreateRunParams) => Promise<void>;
|
|
2223
|
-
updateRun: (runId: string, run: RunUpdate) => Promise<void>;
|
|
2224
|
-
}
|
|
2225
|
-
|
|
2226
|
-
interface Run extends BaseRun {
|
|
2227
|
-
id: string;
|
|
2228
|
-
start_time: number;
|
|
2229
|
-
end_time?: number;
|
|
2230
|
-
execution_order: number;
|
|
2231
|
-
child_runs: this[];
|
|
2232
|
-
child_execution_order: number;
|
|
2233
|
-
events: Array<{
|
|
2234
|
-
name: string;
|
|
2235
|
-
time: string;
|
|
2236
|
-
kwargs?: Record<string, unknown>;
|
|
2237
|
-
}>;
|
|
2238
|
-
trace_id?: string;
|
|
2239
|
-
dotted_order?: string;
|
|
2240
|
-
/** @internal */
|
|
2241
|
-
_serialized_start_time?: string;
|
|
2242
|
-
}
|
|
2243
|
-
declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
2244
|
-
/** @deprecated Use `runTreeMap` instead. */
|
|
2245
|
-
protected runMap: Map<string, Run>;
|
|
2246
|
-
protected runTreeMap: Map<string, RunTree>;
|
|
2247
|
-
protected usesRunTreeMap: boolean;
|
|
2248
|
-
constructor(_fields?: BaseCallbackHandlerInput);
|
|
2249
|
-
copy(): this;
|
|
2250
|
-
protected getRunById(runId?: string): Run | undefined;
|
|
2251
|
-
protected stringifyError(error: unknown): string;
|
|
2252
|
-
protected abstract persistRun(run: Run): Promise<void>;
|
|
2253
|
-
protected _addChildRun(parentRun: Run, childRun: Run): void;
|
|
2254
|
-
_addRunToRunMap(run: Run): {
|
|
2255
|
-
id: string;
|
|
2256
|
-
start_time: number;
|
|
2257
|
-
end_time?: number;
|
|
2258
|
-
execution_order: number;
|
|
2259
|
-
child_runs: Run[];
|
|
2260
|
-
child_execution_order: number;
|
|
2261
|
-
events: Array<{
|
|
2262
|
-
name: string;
|
|
2263
|
-
time: string;
|
|
2264
|
-
kwargs?: Record<string, unknown>;
|
|
2265
|
-
}>;
|
|
2266
|
-
trace_id?: string;
|
|
2267
|
-
dotted_order?: string;
|
|
2268
|
-
/** @internal */
|
|
2269
|
-
_serialized_start_time?: string;
|
|
2270
|
-
name: string;
|
|
2271
|
-
run_type: string;
|
|
2272
|
-
extra?: KVMap;
|
|
2273
|
-
error?: string;
|
|
2274
|
-
serialized?: object;
|
|
2275
|
-
inputs: KVMap;
|
|
2276
|
-
outputs?: KVMap;
|
|
2277
|
-
reference_example_id?: string;
|
|
2278
|
-
parent_run_id?: string;
|
|
2279
|
-
tags?: string[];
|
|
2280
|
-
attachments?: Attachments;
|
|
2281
|
-
};
|
|
2282
|
-
protected _endTrace(run: Run): Promise<void>;
|
|
2283
|
-
protected _getExecutionOrder(parentRunId: string | undefined): number;
|
|
2284
|
-
/**
|
|
2285
|
-
* Create and add a run to the run map for LLM start events.
|
|
2286
|
-
* This must sometimes be done synchronously to avoid race conditions
|
|
2287
|
-
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
2288
|
-
*/
|
|
2289
|
-
_createRunForLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): {
|
|
2290
|
-
id: string;
|
|
2291
|
-
start_time: number;
|
|
2292
|
-
end_time?: number;
|
|
2293
|
-
execution_order: number;
|
|
2294
|
-
child_runs: Run[];
|
|
2295
|
-
child_execution_order: number;
|
|
2296
|
-
events: Array<{
|
|
2297
|
-
name: string;
|
|
2298
|
-
time: string;
|
|
2299
|
-
kwargs?: Record<string, unknown>;
|
|
2300
|
-
}>;
|
|
2301
|
-
trace_id?: string;
|
|
2302
|
-
dotted_order?: string;
|
|
2303
|
-
/** @internal */
|
|
2304
|
-
_serialized_start_time?: string;
|
|
2305
|
-
name: string;
|
|
2306
|
-
run_type: string;
|
|
2307
|
-
extra?: KVMap;
|
|
2308
|
-
error?: string;
|
|
2309
|
-
serialized?: object;
|
|
2310
|
-
inputs: KVMap;
|
|
2311
|
-
outputs?: KVMap;
|
|
2312
|
-
reference_example_id?: string;
|
|
2313
|
-
parent_run_id?: string;
|
|
2314
|
-
tags?: string[];
|
|
2315
|
-
attachments?: Attachments;
|
|
2316
|
-
};
|
|
2317
|
-
handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
|
|
2318
|
-
/**
|
|
2319
|
-
* Create and add a run to the run map for chat model start events.
|
|
2320
|
-
* This must sometimes be done synchronously to avoid race conditions
|
|
2321
|
-
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
2322
|
-
*/
|
|
2323
|
-
_createRunForChatModelStart(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): {
|
|
2324
|
-
id: string;
|
|
2325
|
-
start_time: number;
|
|
2326
|
-
end_time?: number;
|
|
2327
|
-
execution_order: number;
|
|
2328
|
-
child_runs: Run[];
|
|
2329
|
-
child_execution_order: number;
|
|
2330
|
-
events: Array<{
|
|
2331
|
-
name: string;
|
|
2332
|
-
time: string;
|
|
2333
|
-
kwargs?: Record<string, unknown>;
|
|
2334
|
-
}>;
|
|
2335
|
-
trace_id?: string;
|
|
2336
|
-
dotted_order?: string;
|
|
2337
|
-
/** @internal */
|
|
2338
|
-
_serialized_start_time?: string;
|
|
2339
|
-
name: string;
|
|
2340
|
-
run_type: string;
|
|
2341
|
-
extra?: KVMap;
|
|
2342
|
-
error?: string;
|
|
2343
|
-
serialized?: object;
|
|
2344
|
-
inputs: KVMap;
|
|
2345
|
-
outputs?: KVMap;
|
|
2346
|
-
reference_example_id?: string;
|
|
2347
|
-
parent_run_id?: string;
|
|
2348
|
-
tags?: string[];
|
|
2349
|
-
attachments?: Attachments;
|
|
2350
|
-
};
|
|
2351
|
-
handleChatModelStart(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
|
|
2352
|
-
handleLLMEnd(output: LLMResult, runId: string, _parentRunId?: string, _tags?: string[], extraParams?: Record<string, unknown>): Promise<Run>;
|
|
2353
|
-
handleLLMError(error: unknown, runId: string, _parentRunId?: string, _tags?: string[], extraParams?: Record<string, unknown>): Promise<Run>;
|
|
2354
|
-
/**
|
|
2355
|
-
* Create and add a run to the run map for chain start events.
|
|
2356
|
-
* This must sometimes be done synchronously to avoid race conditions
|
|
2357
|
-
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
2358
|
-
*/
|
|
2359
|
-
_createRunForChainStart(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, runType?: string, name?: string): {
|
|
2360
|
-
id: string;
|
|
2361
|
-
start_time: number;
|
|
2362
|
-
end_time?: number;
|
|
2363
|
-
execution_order: number;
|
|
2364
|
-
child_runs: Run[];
|
|
2365
|
-
child_execution_order: number;
|
|
2366
|
-
events: Array<{
|
|
2367
|
-
name: string;
|
|
2368
|
-
time: string;
|
|
2369
|
-
kwargs?: Record<string, unknown>;
|
|
2370
|
-
}>;
|
|
2371
|
-
trace_id?: string;
|
|
2372
|
-
dotted_order?: string;
|
|
2373
|
-
/** @internal */
|
|
2374
|
-
_serialized_start_time?: string;
|
|
2375
|
-
name: string;
|
|
2376
|
-
run_type: string;
|
|
2377
|
-
extra?: KVMap;
|
|
2378
|
-
error?: string;
|
|
2379
|
-
serialized?: object;
|
|
2380
|
-
inputs: KVMap;
|
|
2381
|
-
outputs?: KVMap;
|
|
2382
|
-
reference_example_id?: string;
|
|
2383
|
-
parent_run_id?: string;
|
|
2384
|
-
tags?: string[];
|
|
2385
|
-
attachments?: Attachments;
|
|
2386
|
-
};
|
|
2387
|
-
handleChainStart(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, runType?: string, name?: string): Promise<Run>;
|
|
2388
|
-
handleChainEnd(outputs: ChainValues, runId: string, _parentRunId?: string, _tags?: string[], kwargs?: {
|
|
2389
|
-
inputs?: Record<string, unknown>;
|
|
2390
|
-
}): Promise<Run>;
|
|
2391
|
-
handleChainError(error: unknown, runId: string, _parentRunId?: string, _tags?: string[], kwargs?: {
|
|
2392
|
-
inputs?: Record<string, unknown>;
|
|
2393
|
-
}): Promise<Run>;
|
|
2394
|
-
/**
|
|
2395
|
-
* Create and add a run to the run map for tool start events.
|
|
2396
|
-
* This must sometimes be done synchronously to avoid race conditions
|
|
2397
|
-
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
2398
|
-
*/
|
|
2399
|
-
_createRunForToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): {
|
|
2400
|
-
id: string;
|
|
2401
|
-
start_time: number;
|
|
2402
|
-
end_time?: number;
|
|
2403
|
-
execution_order: number;
|
|
2404
|
-
child_runs: Run[];
|
|
2405
|
-
child_execution_order: number;
|
|
2406
|
-
events: Array<{
|
|
2407
|
-
name: string;
|
|
2408
|
-
time: string;
|
|
2409
|
-
kwargs?: Record<string, unknown>;
|
|
2410
|
-
}>;
|
|
2411
|
-
trace_id?: string;
|
|
2412
|
-
dotted_order?: string;
|
|
2413
|
-
/** @internal */
|
|
2414
|
-
_serialized_start_time?: string;
|
|
2415
|
-
name: string;
|
|
2416
|
-
run_type: string;
|
|
2417
|
-
extra?: KVMap;
|
|
2418
|
-
error?: string;
|
|
2419
|
-
serialized?: object;
|
|
2420
|
-
inputs: KVMap;
|
|
2421
|
-
outputs?: KVMap;
|
|
2422
|
-
reference_example_id?: string;
|
|
2423
|
-
parent_run_id?: string;
|
|
2424
|
-
tags?: string[];
|
|
2425
|
-
attachments?: Attachments;
|
|
2426
|
-
};
|
|
2427
|
-
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
|
|
2428
|
-
handleToolEnd(output: any, runId: string): Promise<Run>;
|
|
2429
|
-
handleToolError(error: unknown, runId: string): Promise<Run>;
|
|
2430
|
-
handleAgentAction(action: AgentAction, runId: string): Promise<void>;
|
|
2431
|
-
handleAgentEnd(action: AgentFinish, runId: string): Promise<void>;
|
|
2432
|
-
/**
|
|
2433
|
-
* Create and add a run to the run map for retriever start events.
|
|
2434
|
-
* This must sometimes be done synchronously to avoid race conditions
|
|
2435
|
-
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
2436
|
-
*/
|
|
2437
|
-
_createRunForRetrieverStart(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): {
|
|
2438
|
-
id: string;
|
|
2439
|
-
start_time: number;
|
|
2440
|
-
end_time?: number;
|
|
2441
|
-
execution_order: number;
|
|
2442
|
-
child_runs: Run[];
|
|
2443
|
-
child_execution_order: number;
|
|
2444
|
-
events: Array<{
|
|
2445
|
-
name: string;
|
|
2446
|
-
time: string;
|
|
2447
|
-
kwargs?: Record<string, unknown>;
|
|
2448
|
-
}>;
|
|
2449
|
-
trace_id?: string;
|
|
2450
|
-
dotted_order?: string;
|
|
2451
|
-
/** @internal */
|
|
2452
|
-
_serialized_start_time?: string;
|
|
2453
|
-
name: string;
|
|
2454
|
-
run_type: string;
|
|
2455
|
-
extra?: KVMap;
|
|
2456
|
-
error?: string;
|
|
2457
|
-
serialized?: object;
|
|
2458
|
-
inputs: KVMap;
|
|
2459
|
-
outputs?: KVMap;
|
|
2460
|
-
reference_example_id?: string;
|
|
2461
|
-
parent_run_id?: string;
|
|
2462
|
-
tags?: string[];
|
|
2463
|
-
attachments?: Attachments;
|
|
2464
|
-
};
|
|
2465
|
-
handleRetrieverStart(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
|
|
2466
|
-
handleRetrieverEnd(documents: Document<Record<string, unknown>>[], runId: string): Promise<Run>;
|
|
2467
|
-
handleRetrieverError(error: unknown, runId: string): Promise<Run>;
|
|
2468
|
-
handleText(text: string, runId: string): Promise<void>;
|
|
2469
|
-
handleLLMNewToken(token: string, idx: NewTokenIndices, runId: string, _parentRunId?: string, _tags?: string[], fields?: HandleLLMNewTokenCallbackFields): Promise<Run>;
|
|
2470
|
-
onRunCreate?(run: Run): void | Promise<void>;
|
|
2471
|
-
onRunUpdate?(run: Run): void | Promise<void>;
|
|
2472
|
-
onLLMStart?(run: Run): void | Promise<void>;
|
|
2473
|
-
onLLMEnd?(run: Run): void | Promise<void>;
|
|
2474
|
-
onLLMError?(run: Run): void | Promise<void>;
|
|
2475
|
-
onChainStart?(run: Run): void | Promise<void>;
|
|
2476
|
-
onChainEnd?(run: Run): void | Promise<void>;
|
|
2477
|
-
onChainError?(run: Run): void | Promise<void>;
|
|
2478
|
-
onToolStart?(run: Run): void | Promise<void>;
|
|
2479
|
-
onToolEnd?(run: Run): void | Promise<void>;
|
|
2480
|
-
onToolError?(run: Run): void | Promise<void>;
|
|
2481
|
-
onAgentAction?(run: Run): void | Promise<void>;
|
|
2482
|
-
onAgentEnd?(run: Run): void | Promise<void>;
|
|
2483
|
-
onRetrieverStart?(run: Run): void | Promise<void>;
|
|
2484
|
-
onRetrieverEnd?(run: Run): void | Promise<void>;
|
|
2485
|
-
onRetrieverError?(run: Run): void | Promise<void>;
|
|
2486
|
-
onText?(run: Run): void | Promise<void>;
|
|
2487
|
-
onLLMNewToken?(run: Run, token: string, kwargs?: {
|
|
2488
|
-
chunk: any;
|
|
2489
|
-
}): void | Promise<void>;
|
|
2490
|
-
}
|
|
2491
|
-
|
|
2492
|
-
type BaseCallbackManagerMethods = {
|
|
2493
|
-
[K in keyof CallbackHandlerMethods]?: (...args: Parameters<Required<CallbackHandlerMethods>[K]>) => Promise<unknown>;
|
|
2494
|
-
};
|
|
2495
|
-
interface CallbackManagerOptions {
|
|
2496
|
-
verbose?: boolean;
|
|
2497
|
-
tracing?: boolean;
|
|
2498
|
-
}
|
|
2499
|
-
type Callbacks = CallbackManager | (BaseCallbackHandler | CallbackHandlerMethods)[];
|
|
2500
|
-
interface BaseCallbackConfig {
|
|
2501
|
-
/**
|
|
2502
|
-
* Name for the tracer run for this call. Defaults to the name of the class.
|
|
2503
|
-
*/
|
|
2504
|
-
runName?: string;
|
|
2505
|
-
/**
|
|
2506
|
-
* Tags for this call and any sub-calls (eg. a Chain calling an LLM).
|
|
2507
|
-
* You can use these to filter calls.
|
|
2508
|
-
*/
|
|
2509
|
-
tags?: string[];
|
|
2510
|
-
/**
|
|
2511
|
-
* Metadata for this call and any sub-calls (eg. a Chain calling an LLM).
|
|
2512
|
-
* Keys should be strings, values should be JSON-serializable.
|
|
2513
|
-
*/
|
|
2514
|
-
metadata?: Record<string, unknown>;
|
|
2515
|
-
/**
|
|
2516
|
-
* Callbacks for this call and any sub-calls (eg. a Chain calling an LLM).
|
|
2517
|
-
* Tags are passed to all callbacks, metadata is passed to handle*Start callbacks.
|
|
2518
|
-
*/
|
|
2519
|
-
callbacks?: Callbacks;
|
|
2520
|
-
/**
|
|
2521
|
-
* Unique identifier for the tracer run for this call. If not provided, a new UUID
|
|
2522
|
-
* will be generated.
|
|
2523
|
-
*/
|
|
2524
|
-
runId?: string;
|
|
2525
|
-
}
|
|
2526
|
-
/**
|
|
2527
|
-
* Manage callbacks from different components of LangChain.
|
|
2528
|
-
*/
|
|
2529
|
-
declare abstract class BaseCallbackManager {
|
|
2530
|
-
abstract addHandler(handler: BaseCallbackHandler): void;
|
|
2531
|
-
abstract removeHandler(handler: BaseCallbackHandler): void;
|
|
2532
|
-
abstract setHandlers(handlers: BaseCallbackHandler[]): void;
|
|
2533
|
-
setHandler(handler: BaseCallbackHandler): void;
|
|
2534
|
-
}
|
|
2535
|
-
/**
|
|
2536
|
-
* Base class for run manager in LangChain.
|
|
2537
|
-
*/
|
|
2538
|
-
declare class BaseRunManager {
|
|
2539
|
-
readonly runId: string;
|
|
2540
|
-
readonly handlers: BaseCallbackHandler[];
|
|
2541
|
-
protected readonly inheritableHandlers: BaseCallbackHandler[];
|
|
2542
|
-
protected readonly tags: string[];
|
|
2543
|
-
protected readonly inheritableTags: string[];
|
|
2544
|
-
protected readonly metadata: Record<string, unknown>;
|
|
2545
|
-
protected readonly inheritableMetadata: Record<string, unknown>;
|
|
2546
|
-
protected readonly _parentRunId?: string | undefined;
|
|
2547
|
-
constructor(runId: string, handlers: BaseCallbackHandler[], inheritableHandlers: BaseCallbackHandler[], tags: string[], inheritableTags: string[], metadata: Record<string, unknown>, inheritableMetadata: Record<string, unknown>, _parentRunId?: string | undefined);
|
|
2548
|
-
get parentRunId(): string | undefined;
|
|
2549
|
-
handleText(text: string): Promise<void>;
|
|
2550
|
-
handleCustomEvent(eventName: string, data: any, _runId?: string, _tags?: string[], _metadata?: Record<string, any>): Promise<void>;
|
|
2551
|
-
}
|
|
2552
|
-
/**
|
|
2553
|
-
* Manages callbacks for retriever runs.
|
|
2554
|
-
*/
|
|
2555
|
-
declare class CallbackManagerForRetrieverRun extends BaseRunManager implements BaseCallbackManagerMethods {
|
|
2556
|
-
getChild(tag?: string): CallbackManager;
|
|
2557
|
-
handleRetrieverEnd(documents: DocumentInterface[]): Promise<void>;
|
|
2558
|
-
handleRetrieverError(err: Error | unknown): Promise<void>;
|
|
2559
|
-
}
|
|
2560
|
-
declare class CallbackManagerForLLMRun extends BaseRunManager implements BaseCallbackManagerMethods {
|
|
2561
|
-
handleLLMNewToken(token: string, idx?: NewTokenIndices, _runId?: string, _parentRunId?: string, _tags?: string[], fields?: HandleLLMNewTokenCallbackFields): Promise<void>;
|
|
2562
|
-
handleLLMError(err: Error | unknown, _runId?: string, _parentRunId?: string, _tags?: string[], extraParams?: Record<string, unknown>): Promise<void>;
|
|
2563
|
-
handleLLMEnd(output: LLMResult, _runId?: string, _parentRunId?: string, _tags?: string[], extraParams?: Record<string, unknown>): Promise<void>;
|
|
2564
|
-
}
|
|
2565
|
-
declare class CallbackManagerForChainRun extends BaseRunManager implements BaseCallbackManagerMethods {
|
|
2566
|
-
getChild(tag?: string): CallbackManager;
|
|
2567
|
-
handleChainError(err: Error | unknown, _runId?: string, _parentRunId?: string, _tags?: string[], kwargs?: {
|
|
2568
|
-
inputs?: Record<string, unknown>;
|
|
2569
|
-
}): Promise<void>;
|
|
2570
|
-
handleChainEnd(output: ChainValues, _runId?: string, _parentRunId?: string, _tags?: string[], kwargs?: {
|
|
2571
|
-
inputs?: Record<string, unknown>;
|
|
2572
|
-
}): Promise<void>;
|
|
2573
|
-
handleAgentAction(action: AgentAction): Promise<void>;
|
|
2574
|
-
handleAgentEnd(action: AgentFinish): Promise<void>;
|
|
2575
|
-
}
|
|
2576
|
-
declare class CallbackManagerForToolRun extends BaseRunManager implements BaseCallbackManagerMethods {
|
|
2577
|
-
getChild(tag?: string): CallbackManager;
|
|
2578
|
-
handleToolError(err: Error | unknown): Promise<void>;
|
|
2579
|
-
handleToolEnd(output: any): Promise<void>;
|
|
2580
|
-
}
|
|
2581
|
-
/**
|
|
2582
|
-
* @example
|
|
2583
|
-
* ```typescript
|
|
2584
|
-
* const prompt = PromptTemplate.fromTemplate("What is the answer to {question}?");
|
|
2585
|
-
*
|
|
2586
|
-
* // Example of using LLMChain with OpenAI and a simple prompt
|
|
2587
|
-
* const chain = new LLMChain({
|
|
2588
|
-
* llm: new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0.9 }),
|
|
2589
|
-
* prompt,
|
|
2590
|
-
* });
|
|
2591
|
-
*
|
|
2592
|
-
* // Running the chain with a single question
|
|
2593
|
-
* const result = await chain.call({
|
|
2594
|
-
* question: "What is the airspeed velocity of an unladen swallow?",
|
|
2595
|
-
* });
|
|
2596
|
-
* console.log("The answer is:", result);
|
|
2597
|
-
* ```
|
|
2598
|
-
*/
|
|
2599
|
-
declare class CallbackManager extends BaseCallbackManager implements BaseCallbackManagerMethods {
|
|
2600
|
-
handlers: BaseCallbackHandler[];
|
|
2601
|
-
inheritableHandlers: BaseCallbackHandler[];
|
|
2602
|
-
tags: string[];
|
|
2603
|
-
inheritableTags: string[];
|
|
2604
|
-
metadata: Record<string, unknown>;
|
|
2605
|
-
inheritableMetadata: Record<string, unknown>;
|
|
2606
|
-
name: string;
|
|
2607
|
-
_parentRunId?: string;
|
|
2608
|
-
constructor(parentRunId?: string, options?: {
|
|
2609
|
-
handlers?: BaseCallbackHandler[];
|
|
2610
|
-
inheritableHandlers?: BaseCallbackHandler[];
|
|
2611
|
-
tags?: string[];
|
|
2612
|
-
inheritableTags?: string[];
|
|
2613
|
-
metadata?: Record<string, unknown>;
|
|
2614
|
-
inheritableMetadata?: Record<string, unknown>;
|
|
2615
|
-
});
|
|
2616
|
-
/**
|
|
2617
|
-
* Gets the parent run ID, if any.
|
|
2618
|
-
*
|
|
2619
|
-
* @returns The parent run ID.
|
|
2620
|
-
*/
|
|
2621
|
-
getParentRunId(): string | undefined;
|
|
2622
|
-
handleLLMStart(llm: Serialized, prompts: string[], runId?: string | undefined, _parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, _tags?: string[] | undefined, _metadata?: Record<string, unknown> | undefined, runName?: string | undefined): Promise<CallbackManagerForLLMRun[]>;
|
|
2623
|
-
handleChatModelStart(llm: Serialized, messages: BaseMessage[][], runId?: string | undefined, _parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, _tags?: string[] | undefined, _metadata?: Record<string, unknown> | undefined, runName?: string | undefined): Promise<CallbackManagerForLLMRun[]>;
|
|
2624
|
-
handleChainStart(chain: Serialized, inputs: ChainValues, runId?: string, runType?: string | undefined, _tags?: string[] | undefined, _metadata?: Record<string, unknown> | undefined, runName?: string | undefined): Promise<CallbackManagerForChainRun>;
|
|
2625
|
-
handleToolStart(tool: Serialized, input: string, runId?: string, _parentRunId?: string | undefined, _tags?: string[] | undefined, _metadata?: Record<string, unknown> | undefined, runName?: string | undefined): Promise<CallbackManagerForToolRun>;
|
|
2626
|
-
handleRetrieverStart(retriever: Serialized, query: string, runId?: string, _parentRunId?: string | undefined, _tags?: string[] | undefined, _metadata?: Record<string, unknown> | undefined, runName?: string | undefined): Promise<CallbackManagerForRetrieverRun>;
|
|
2627
|
-
handleCustomEvent?(eventName: string, data: any, runId: string, _tags?: string[], _metadata?: Record<string, any>): Promise<any>;
|
|
2628
|
-
addHandler(handler: BaseCallbackHandler, inherit?: boolean): void;
|
|
2629
|
-
removeHandler(handler: BaseCallbackHandler): void;
|
|
2630
|
-
setHandlers(handlers: BaseCallbackHandler[], inherit?: boolean): void;
|
|
2631
|
-
addTags(tags: string[], inherit?: boolean): void;
|
|
2632
|
-
removeTags(tags: string[]): void;
|
|
2633
|
-
addMetadata(metadata: Record<string, unknown>, inherit?: boolean): void;
|
|
2634
|
-
removeMetadata(metadata: Record<string, unknown>): void;
|
|
2635
|
-
copy(additionalHandlers?: BaseCallbackHandler[], inherit?: boolean): CallbackManager;
|
|
2636
|
-
static fromHandlers(handlers: CallbackHandlerMethods): CallbackManager;
|
|
2637
|
-
static configure(inheritableHandlers?: Callbacks, localHandlers?: Callbacks, inheritableTags?: string[], localTags?: string[], inheritableMetadata?: Record<string, unknown>, localMetadata?: Record<string, unknown>, options?: CallbackManagerOptions): CallbackManager | undefined;
|
|
2638
|
-
static _configureSync(inheritableHandlers?: Callbacks, localHandlers?: Callbacks, inheritableTags?: string[], localTags?: string[], inheritableMetadata?: Record<string, unknown>, localMetadata?: Record<string, unknown>, options?: CallbackManagerOptions): CallbackManager | undefined;
|
|
2639
|
-
}
|
|
2640
|
-
|
|
2641
|
-
interface BaseDataContentBlock {
|
|
2642
|
-
mime_type?: string;
|
|
2643
|
-
metadata?: Record<string, unknown>;
|
|
2644
|
-
}
|
|
2645
|
-
interface URLContentBlock extends BaseDataContentBlock {
|
|
2646
|
-
type: "image" | "audio" | "file";
|
|
2647
|
-
source_type: "url";
|
|
2648
|
-
url: string;
|
|
2649
|
-
}
|
|
2650
|
-
interface Base64ContentBlock extends BaseDataContentBlock {
|
|
2651
|
-
type: "image" | "audio" | "file";
|
|
2652
|
-
source_type: "base64";
|
|
2653
|
-
data: string;
|
|
2654
|
-
}
|
|
2655
|
-
interface PlainTextContentBlock extends BaseDataContentBlock {
|
|
2656
|
-
type: "file" | "text";
|
|
2657
|
-
source_type: "text";
|
|
2658
|
-
text: string;
|
|
2659
|
-
}
|
|
2660
|
-
interface IDContentBlock extends BaseDataContentBlock {
|
|
2661
|
-
type: "image" | "audio" | "file";
|
|
2662
|
-
source_type: "id";
|
|
2663
|
-
id: string;
|
|
2664
|
-
}
|
|
2665
|
-
type DataContentBlock = URLContentBlock | Base64ContentBlock | PlainTextContentBlock | IDContentBlock;
|
|
2666
|
-
|
|
2667
|
-
interface ToolMessageFields extends BaseMessageFields {
|
|
2668
|
-
content: string | (MessageContentComplex | DataContentBlock)[];
|
|
2669
|
-
}
|
|
2670
|
-
interface ToolMessageFieldsWithToolCallId extends ToolMessageFields {
|
|
2671
|
-
/**
|
|
2672
|
-
* Artifact of the Tool execution which is not meant to be sent to the model.
|
|
2673
|
-
*
|
|
2674
|
-
* Should only be specified if it is different from the message content, e.g. if only
|
|
2675
|
-
* a subset of the full tool output is being passed as message content but the full
|
|
2676
|
-
* output is needed in other parts of the code.
|
|
2677
|
-
*/
|
|
2678
|
-
artifact?: any;
|
|
2679
|
-
tool_call_id: string;
|
|
2680
|
-
/**
|
|
2681
|
-
* Status of the tool invocation.
|
|
2682
|
-
* @version 0.2.19
|
|
2683
|
-
*/
|
|
2684
|
-
status?: "success" | "error";
|
|
2685
|
-
}
|
|
2686
|
-
/**
|
|
2687
|
-
* Marker parameter for objects that tools can return directly.
|
|
2688
|
-
*
|
|
2689
|
-
* If a custom BaseTool is invoked with a ToolCall and the output of custom code is
|
|
2690
|
-
* not an instance of DirectToolOutput, the output will automatically be coerced to
|
|
2691
|
-
* a string and wrapped in a ToolMessage.
|
|
2692
|
-
*/
|
|
2693
|
-
interface DirectToolOutput {
|
|
2694
|
-
readonly lc_direct_tool_output: true;
|
|
2695
|
-
}
|
|
2696
|
-
/**
|
|
2697
|
-
* Represents a tool message in a conversation.
|
|
2698
|
-
*/
|
|
2699
|
-
declare class ToolMessage extends BaseMessage implements DirectToolOutput {
|
|
2700
|
-
content: string | (MessageContentComplex | DataContentBlock)[];
|
|
2701
|
-
static lc_name(): string;
|
|
2702
|
-
get lc_aliases(): Record<string, string>;
|
|
2703
|
-
lc_direct_tool_output: true;
|
|
2704
|
-
/**
|
|
2705
|
-
* Status of the tool invocation.
|
|
2706
|
-
* @version 0.2.19
|
|
2707
|
-
*/
|
|
2708
|
-
status?: "success" | "error";
|
|
2709
|
-
tool_call_id: string;
|
|
2710
|
-
/**
|
|
2711
|
-
* Artifact of the Tool execution which is not meant to be sent to the model.
|
|
2712
|
-
*
|
|
2713
|
-
* Should only be specified if it is different from the message content, e.g. if only
|
|
2714
|
-
* a subset of the full tool output is being passed as message content but the full
|
|
2715
|
-
* output is needed in other parts of the code.
|
|
2716
|
-
*/
|
|
2717
|
-
artifact?: any;
|
|
2718
|
-
constructor(fields: ToolMessageFieldsWithToolCallId);
|
|
2719
|
-
constructor(fields: string | ToolMessageFields, tool_call_id: string, name?: string);
|
|
2720
|
-
_getType(): MessageType;
|
|
2721
|
-
static isInstance(message: BaseMessage): message is ToolMessage;
|
|
2722
|
-
get _printableFields(): Record<string, unknown>;
|
|
2723
|
-
}
|
|
2724
|
-
/**
|
|
2725
|
-
* A call to a tool.
|
|
2726
|
-
* @property {string} name - The name of the tool to be called
|
|
2727
|
-
* @property {Record<string, any>} args - The arguments to the tool call
|
|
2728
|
-
* @property {string} [id] - If provided, an identifier associated with the tool call
|
|
2729
|
-
*/
|
|
2730
|
-
type ToolCall = {
|
|
2731
|
-
name: string;
|
|
2732
|
-
args: Record<string, any>;
|
|
2733
|
-
id?: string;
|
|
2734
|
-
type?: "tool_call";
|
|
2735
|
-
};
|
|
2736
|
-
|
|
2737
|
-
type IterableReadableStreamInterface<T> = ReadableStream<T> & AsyncIterable<T>;
|
|
2738
|
-
|
|
2739
|
-
type RunnableBatchOptions = {
|
|
2740
|
-
/** @deprecated Pass in via the standard runnable config object instead */
|
|
2741
|
-
maxConcurrency?: number;
|
|
2742
|
-
returnExceptions?: boolean;
|
|
2743
|
-
};
|
|
2744
|
-
type RunnableIOSchema = {
|
|
2745
|
-
name?: string;
|
|
2746
|
-
schema: InteropZodType;
|
|
2747
|
-
};
|
|
2748
|
-
/**
|
|
2749
|
-
* Base interface implemented by all runnables.
|
|
2750
|
-
* Used for cross-compatibility between different versions of LangChain core.
|
|
2751
|
-
*
|
|
2752
|
-
* Should not change on patch releases.
|
|
2753
|
-
*/
|
|
2754
|
-
interface RunnableInterface<RunInput = any, RunOutput = any, CallOptions extends RunnableConfig = RunnableConfig> extends SerializableInterface {
|
|
2755
|
-
lc_serializable: boolean;
|
|
2756
|
-
invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
|
|
2757
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
2758
|
-
returnExceptions?: false;
|
|
2759
|
-
}): Promise<RunOutput[]>;
|
|
2760
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
2761
|
-
returnExceptions: true;
|
|
2762
|
-
}): Promise<(RunOutput | Error)[]>;
|
|
2763
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
2764
|
-
stream(input: RunInput, options?: Partial<CallOptions>): Promise<IterableReadableStreamInterface<RunOutput>>;
|
|
2765
|
-
transform(generator: AsyncGenerator<RunInput>, options: Partial<CallOptions>): AsyncGenerator<RunOutput>;
|
|
2766
|
-
getName(suffix?: string): string;
|
|
2767
|
-
}
|
|
2768
|
-
interface Edge {
|
|
2769
|
-
source: string;
|
|
2770
|
-
target: string;
|
|
2771
|
-
data?: string;
|
|
2772
|
-
conditional?: boolean;
|
|
2773
|
-
}
|
|
2774
|
-
interface Node {
|
|
2775
|
-
id: string;
|
|
2776
|
-
name: string;
|
|
2777
|
-
data: RunnableIOSchema | RunnableInterface;
|
|
2778
|
-
metadata?: Record<string, any>;
|
|
2779
|
-
}
|
|
2780
|
-
interface RunnableConfig<ConfigurableFieldType extends Record<string, any> = Record<string, any>> extends BaseCallbackConfig {
|
|
2781
|
-
/**
|
|
2782
|
-
* Runtime values for attributes previously made configurable on this Runnable,
|
|
2783
|
-
* or sub-Runnables.
|
|
2784
|
-
*/
|
|
2785
|
-
configurable?: ConfigurableFieldType;
|
|
2786
|
-
/**
|
|
2787
|
-
* Maximum number of times a call can recurse. If not provided, defaults to 25.
|
|
2788
|
-
*/
|
|
2789
|
-
recursionLimit?: number;
|
|
2790
|
-
/** Maximum number of parallel calls to make. */
|
|
2791
|
-
maxConcurrency?: number;
|
|
2792
|
-
/**
|
|
2793
|
-
* Timeout for this call in milliseconds.
|
|
2794
|
-
*/
|
|
2795
|
-
timeout?: number;
|
|
2796
|
-
/**
|
|
2797
|
-
* Abort signal for this call.
|
|
2798
|
-
* If provided, the call will be aborted when the signal is aborted.
|
|
2799
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
2800
|
-
*/
|
|
2801
|
-
signal?: AbortSignal;
|
|
2802
|
-
}
|
|
2803
|
-
|
|
2804
|
-
type Operation = AddOperation<any> | RemoveOperation | ReplaceOperation<any> | MoveOperation | CopyOperation | TestOperation<any> | GetOperation<any>;
|
|
2805
|
-
interface BaseOperation {
|
|
2806
|
-
path: string;
|
|
2807
|
-
}
|
|
2808
|
-
interface AddOperation<T> extends BaseOperation {
|
|
2809
|
-
op: "add";
|
|
2810
|
-
value: T;
|
|
2811
|
-
}
|
|
2812
|
-
interface RemoveOperation extends BaseOperation {
|
|
2813
|
-
op: "remove";
|
|
2814
|
-
}
|
|
2815
|
-
interface ReplaceOperation<T> extends BaseOperation {
|
|
2816
|
-
op: "replace";
|
|
2817
|
-
value: T;
|
|
2818
|
-
}
|
|
2819
|
-
interface MoveOperation extends BaseOperation {
|
|
2820
|
-
op: "move";
|
|
2821
|
-
from: string;
|
|
2822
|
-
}
|
|
2823
|
-
interface CopyOperation extends BaseOperation {
|
|
2824
|
-
op: "copy";
|
|
2825
|
-
from: string;
|
|
2826
|
-
}
|
|
2827
|
-
interface TestOperation<T> extends BaseOperation {
|
|
2828
|
-
op: "test";
|
|
2829
|
-
value: T;
|
|
2830
|
-
}
|
|
2831
|
-
interface GetOperation<T> extends BaseOperation {
|
|
2832
|
-
op: "_get";
|
|
2833
|
-
value: T;
|
|
2834
|
-
}
|
|
2835
|
-
|
|
2836
|
-
declare class IterableReadableStream<T> extends ReadableStream<T> implements IterableReadableStreamInterface<T> {
|
|
2837
|
-
reader: ReadableStreamDefaultReader<T>;
|
|
2838
|
-
ensureReader(): void;
|
|
2839
|
-
next(): Promise<IteratorResult<T>>;
|
|
2840
|
-
return(): Promise<IteratorResult<T>>;
|
|
2841
|
-
throw(e: any): Promise<IteratorResult<T>>;
|
|
2842
|
-
[Symbol.asyncIterator](): this;
|
|
2843
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
2844
|
-
static fromReadableStream<T>(stream: ReadableStream<T>): IterableReadableStream<T>;
|
|
2845
|
-
static fromAsyncGenerator<T>(generator: AsyncGenerator<T>): IterableReadableStream<T>;
|
|
2846
|
-
}
|
|
2847
|
-
|
|
2848
|
-
/**
|
|
2849
|
-
* Data associated with a StreamEvent.
|
|
2850
|
-
*/
|
|
2851
|
-
type StreamEventData = {
|
|
2852
|
-
/**
|
|
2853
|
-
* The input passed to the runnable that generated the event.
|
|
2854
|
-
* Inputs will sometimes be available at the *START* of the runnable, and
|
|
2855
|
-
* sometimes at the *END* of the runnable.
|
|
2856
|
-
* If a runnable is able to stream its inputs, then its input by definition
|
|
2857
|
-
* won't be known until the *END* of the runnable when it has finished streaming
|
|
2858
|
-
* its inputs.
|
|
2859
|
-
*/
|
|
2860
|
-
input?: any;
|
|
2861
|
-
/**
|
|
2862
|
-
* The output of the runnable that generated the event.
|
|
2863
|
-
* Outputs will only be available at the *END* of the runnable.
|
|
2864
|
-
* For most runnables, this field can be inferred from the `chunk` field,
|
|
2865
|
-
* though there might be some exceptions for special cased runnables (e.g., like
|
|
2866
|
-
* chat models), which may return more information.
|
|
2867
|
-
*/
|
|
2868
|
-
output?: any;
|
|
2869
|
-
/**
|
|
2870
|
-
* A streaming chunk from the output that generated the event.
|
|
2871
|
-
* chunks support addition in general, and adding them up should result
|
|
2872
|
-
* in the output of the runnable that generated the event.
|
|
2873
|
-
*/
|
|
2874
|
-
chunk?: any;
|
|
2875
|
-
};
|
|
2876
|
-
/**
|
|
2877
|
-
* A streaming event.
|
|
2878
|
-
*
|
|
2879
|
-
* Schema of a streaming event which is produced from the streamEvents method.
|
|
2880
|
-
*/
|
|
2881
|
-
type StreamEvent = {
|
|
2882
|
-
/**
|
|
2883
|
-
* Event names are of the format: on_[runnable_type]_(start|stream|end).
|
|
2884
|
-
*
|
|
2885
|
-
* Runnable types are one of:
|
|
2886
|
-
* - llm - used by non chat models
|
|
2887
|
-
* - chat_model - used by chat models
|
|
2888
|
-
* - prompt -- e.g., ChatPromptTemplate
|
|
2889
|
-
* - tool -- LangChain tools
|
|
2890
|
-
* - chain - most Runnables are of this type
|
|
2891
|
-
*
|
|
2892
|
-
* Further, the events are categorized as one of:
|
|
2893
|
-
* - start - when the runnable starts
|
|
2894
|
-
* - stream - when the runnable is streaming
|
|
2895
|
-
* - end - when the runnable ends
|
|
2896
|
-
*
|
|
2897
|
-
* start, stream and end are associated with slightly different `data` payload.
|
|
2898
|
-
*
|
|
2899
|
-
* Please see the documentation for `EventData` for more details.
|
|
2900
|
-
*/
|
|
2901
|
-
event: string;
|
|
2902
|
-
/** The name of the runnable that generated the event. */
|
|
2903
|
-
name: string;
|
|
2904
|
-
/**
|
|
2905
|
-
* An randomly generated ID to keep track of the execution of the given runnable.
|
|
2906
|
-
*
|
|
2907
|
-
* Each child runnable that gets invoked as part of the execution of a parent runnable
|
|
2908
|
-
* is assigned its own unique ID.
|
|
2909
|
-
*/
|
|
2910
|
-
run_id: string;
|
|
2911
|
-
/**
|
|
2912
|
-
* Tags associated with the runnable that generated this event.
|
|
2913
|
-
* Tags are always inherited from parent runnables.
|
|
2914
|
-
*/
|
|
2915
|
-
tags?: string[];
|
|
2916
|
-
/** Metadata associated with the runnable that generated this event. */
|
|
2917
|
-
metadata: Record<string, any>;
|
|
2918
|
-
/**
|
|
2919
|
-
* Event data.
|
|
2920
|
-
*
|
|
2921
|
-
* The contents of the event data depend on the event type.
|
|
2922
|
-
*/
|
|
2923
|
-
data: StreamEventData;
|
|
2924
|
-
};
|
|
2925
|
-
interface EventStreamCallbackHandlerInput extends BaseCallbackHandlerInput {
|
|
2926
|
-
autoClose?: boolean;
|
|
2927
|
-
includeNames?: string[];
|
|
2928
|
-
includeTypes?: string[];
|
|
2929
|
-
includeTags?: string[];
|
|
2930
|
-
excludeNames?: string[];
|
|
2931
|
-
excludeTypes?: string[];
|
|
2932
|
-
excludeTags?: string[];
|
|
2933
|
-
}
|
|
2934
|
-
|
|
2935
|
-
/**
|
|
2936
|
-
* Interface that represents the structure of a log entry in the
|
|
2937
|
-
* `LogStreamCallbackHandler`.
|
|
2938
|
-
*/
|
|
2939
|
-
type LogEntry = {
|
|
2940
|
-
/** ID of the sub-run. */
|
|
2941
|
-
id: string;
|
|
2942
|
-
/** Name of the object being run. */
|
|
2943
|
-
name: string;
|
|
2944
|
-
/** Type of the object being run, eg. prompt, chain, llm, etc. */
|
|
2945
|
-
type: string;
|
|
2946
|
-
/** List of tags for the run. */
|
|
2947
|
-
tags: string[];
|
|
2948
|
-
/** Key-value pairs of metadata for the run. */
|
|
2949
|
-
metadata: Record<string, any>;
|
|
2950
|
-
/** ISO-8601 timestamp of when the run started. */
|
|
2951
|
-
start_time: string;
|
|
2952
|
-
/** List of general output chunks streamed by this run. */
|
|
2953
|
-
streamed_output: any[];
|
|
2954
|
-
/** List of LLM tokens streamed by this run, if applicable. */
|
|
2955
|
-
streamed_output_str: string[];
|
|
2956
|
-
/** Inputs to this run. Not available currently via streamLog. */
|
|
2957
|
-
inputs?: any;
|
|
2958
|
-
/** Final output of this run. Only available after the run has finished successfully. */
|
|
2959
|
-
final_output?: any;
|
|
2960
|
-
/** ISO-8601 timestamp of when the run ended. Only available after the run has finished. */
|
|
2961
|
-
end_time?: string;
|
|
2962
|
-
};
|
|
2963
|
-
type RunState = {
|
|
2964
|
-
/** ID of the sub-run. */
|
|
2965
|
-
id: string;
|
|
2966
|
-
/** List of output chunks streamed by Runnable.stream() */
|
|
2967
|
-
streamed_output: any[];
|
|
2968
|
-
/** Final output of the run, usually the result of aggregating streamed_output. Only available after the run has finished successfully. */
|
|
2969
|
-
final_output?: any;
|
|
2970
|
-
/**
|
|
2971
|
-
* List of sub-runs contained in this run, if any, in the order they were started.
|
|
2972
|
-
* If filters were supplied, this list will contain only the runs that matched the filters.
|
|
2973
|
-
*/
|
|
2974
|
-
logs: Record<string, LogEntry>;
|
|
2975
|
-
/** Name of the object being run. */
|
|
2976
|
-
name: string;
|
|
2977
|
-
/** Type of the object being run, eg. prompt, chain, llm, etc. */
|
|
2978
|
-
type: string;
|
|
2979
|
-
};
|
|
2980
|
-
/**
|
|
2981
|
-
* List of jsonpatch JSONPatchOperations, which describe how to create the run state
|
|
2982
|
-
* from an empty dict. This is the minimal representation of the log, designed to
|
|
2983
|
-
* be serialized as JSON and sent over the wire to reconstruct the log on the other
|
|
2984
|
-
* side. Reconstruction of the state can be done with any jsonpatch-compliant library,
|
|
2985
|
-
* see https://jsonpatch.com for more information.
|
|
2986
|
-
*/
|
|
2987
|
-
declare class RunLogPatch {
|
|
2988
|
-
ops: Operation[];
|
|
2989
|
-
constructor(fields: {
|
|
2990
|
-
ops?: Operation[];
|
|
2991
|
-
});
|
|
2992
|
-
concat(other: RunLogPatch): RunLog;
|
|
2993
|
-
}
|
|
2994
|
-
declare class RunLog extends RunLogPatch {
|
|
2995
|
-
state: RunState;
|
|
2996
|
-
constructor(fields: {
|
|
2997
|
-
ops?: Operation[];
|
|
2998
|
-
state: RunState;
|
|
2999
|
-
});
|
|
3000
|
-
concat(other: RunLogPatch): RunLog;
|
|
3001
|
-
static fromRunLogPatch(patch: RunLogPatch): RunLog;
|
|
3002
|
-
}
|
|
3003
|
-
type SchemaFormat = "original" | "streaming_events";
|
|
3004
|
-
interface LogStreamCallbackHandlerInput extends BaseCallbackHandlerInput {
|
|
3005
|
-
autoClose?: boolean;
|
|
3006
|
-
includeNames?: string[];
|
|
3007
|
-
includeTypes?: string[];
|
|
3008
|
-
includeTags?: string[];
|
|
3009
|
-
excludeNames?: string[];
|
|
3010
|
-
excludeTypes?: string[];
|
|
3011
|
-
excludeTags?: string[];
|
|
3012
|
-
_schemaFormat?: SchemaFormat;
|
|
3013
|
-
}
|
|
3014
|
-
/**
|
|
3015
|
-
* Class that extends the `BaseTracer` class from the
|
|
3016
|
-
* `langchain.callbacks.tracers.base` module. It represents a callback
|
|
3017
|
-
* handler that logs the execution of runs and emits `RunLog` instances to a
|
|
3018
|
-
* `RunLogStream`.
|
|
3019
|
-
*/
|
|
3020
|
-
declare class LogStreamCallbackHandler extends BaseTracer implements CallbackHandlerPrefersStreaming {
|
|
3021
|
-
protected autoClose: boolean;
|
|
3022
|
-
protected includeNames?: string[];
|
|
3023
|
-
protected includeTypes?: string[];
|
|
3024
|
-
protected includeTags?: string[];
|
|
3025
|
-
protected excludeNames?: string[];
|
|
3026
|
-
protected excludeTypes?: string[];
|
|
3027
|
-
protected excludeTags?: string[];
|
|
3028
|
-
protected _schemaFormat: SchemaFormat;
|
|
3029
|
-
protected rootId?: string;
|
|
3030
|
-
private keyMapByRunId;
|
|
3031
|
-
private counterMapByRunName;
|
|
3032
|
-
protected transformStream: TransformStream;
|
|
3033
|
-
writer: WritableStreamDefaultWriter;
|
|
3034
|
-
receiveStream: IterableReadableStream<RunLogPatch>;
|
|
3035
|
-
name: string;
|
|
3036
|
-
lc_prefer_streaming: boolean;
|
|
3037
|
-
constructor(fields?: LogStreamCallbackHandlerInput);
|
|
3038
|
-
[Symbol.asyncIterator](): IterableReadableStream<RunLogPatch>;
|
|
3039
|
-
protected persistRun(_run: Run): Promise<void>;
|
|
3040
|
-
_includeRun(run: Run): boolean;
|
|
3041
|
-
tapOutputIterable<T>(runId: string, output: AsyncGenerator<T>): AsyncGenerator<T>;
|
|
3042
|
-
onRunCreate(run: Run): Promise<void>;
|
|
3043
|
-
onRunUpdate(run: Run): Promise<void>;
|
|
3044
|
-
onLLMNewToken(run: Run, token: string, kwargs?: HandleLLMNewTokenCallbackFields): Promise<void>;
|
|
3045
|
-
}
|
|
3046
|
-
|
|
3047
|
-
declare class Graph {
|
|
3048
|
-
nodes: Record<string, Node>;
|
|
3049
|
-
edges: Edge[];
|
|
3050
|
-
constructor(params?: {
|
|
3051
|
-
nodes: Record<string, Node>;
|
|
3052
|
-
edges: Edge[];
|
|
3053
|
-
});
|
|
3054
|
-
toJSON(): Record<string, any>;
|
|
3055
|
-
addNode(data: RunnableInterface | RunnableIOSchema, id?: string, metadata?: Record<string, any>): Node;
|
|
3056
|
-
removeNode(node: Node): void;
|
|
3057
|
-
addEdge(source: Node, target: Node, data?: string, conditional?: boolean): Edge;
|
|
3058
|
-
firstNode(): Node | undefined;
|
|
3059
|
-
lastNode(): Node | undefined;
|
|
3060
|
-
/**
|
|
3061
|
-
* Add all nodes and edges from another graph.
|
|
3062
|
-
* Note this doesn't check for duplicates, nor does it connect the graphs.
|
|
3063
|
-
*/
|
|
3064
|
-
extend(graph: Graph, prefix?: string): ({
|
|
3065
|
-
id: string;
|
|
3066
|
-
data: RunnableIOSchema | RunnableInterface<any, any, RunnableConfig<Record<string, any>>>;
|
|
3067
|
-
} | undefined)[];
|
|
3068
|
-
trimFirstNode(): void;
|
|
3069
|
-
trimLastNode(): void;
|
|
3070
|
-
/**
|
|
3071
|
-
* Return a new graph with all nodes re-identified,
|
|
3072
|
-
* using their unique, readable names where possible.
|
|
3073
|
-
*/
|
|
3074
|
-
reid(): Graph;
|
|
3075
|
-
drawMermaid(params?: {
|
|
3076
|
-
withStyles?: boolean;
|
|
3077
|
-
curveStyle?: string;
|
|
3078
|
-
nodeColors?: Record<string, string>;
|
|
3079
|
-
wrapLabelNWords?: number;
|
|
3080
|
-
}): string;
|
|
3081
|
-
drawMermaidPng(params?: {
|
|
3082
|
-
withStyles?: boolean;
|
|
3083
|
-
curveStyle?: string;
|
|
3084
|
-
nodeColors?: Record<string, string>;
|
|
3085
|
-
wrapLabelNWords?: number;
|
|
3086
|
-
backgroundColor?: string;
|
|
3087
|
-
}): Promise<Blob>;
|
|
3088
|
-
}
|
|
3089
|
-
|
|
3090
|
-
type RunnableFunc<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = (input: RunInput, options: CallOptions | Record<string, any> | (Record<string, any> & CallOptions)) => RunOutput | Promise<RunOutput>;
|
|
3091
|
-
type RunnableMapLike<RunInput, RunOutput> = {
|
|
3092
|
-
[K in keyof RunOutput]: RunnableLike<RunInput, RunOutput[K]>;
|
|
3093
|
-
};
|
|
3094
|
-
type RunnableLike<RunInput = any, RunOutput = any, CallOptions extends RunnableConfig = RunnableConfig> = RunnableInterface<RunInput, RunOutput, CallOptions> | RunnableFunc<RunInput, RunOutput, CallOptions> | RunnableMapLike<RunInput, RunOutput>;
|
|
3095
|
-
type RunnableRetryFailedAttemptHandler = (error: any, input: any) => any;
|
|
3096
|
-
/**
|
|
3097
|
-
* A Runnable is a generic unit of work that can be invoked, batched, streamed, and/or
|
|
3098
|
-
* transformed.
|
|
3099
|
-
*/
|
|
3100
|
-
declare abstract class Runnable<RunInput = any, RunOutput = any, CallOptions extends RunnableConfig = RunnableConfig> extends Serializable implements RunnableInterface<RunInput, RunOutput, CallOptions> {
|
|
3101
|
-
protected lc_runnable: boolean;
|
|
3102
|
-
name?: string;
|
|
3103
|
-
getName(suffix?: string): string;
|
|
3104
|
-
abstract invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
|
|
3105
|
-
/**
|
|
3106
|
-
* Bind arguments to a Runnable, returning a new Runnable.
|
|
3107
|
-
* @param kwargs
|
|
3108
|
-
* @returns A new RunnableBinding that, when invoked, will apply the bound args.
|
|
3109
|
-
*
|
|
3110
|
-
* @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
|
|
3111
|
-
*/
|
|
3112
|
-
bind(kwargs: Partial<CallOptions>): Runnable<RunInput, RunOutput, CallOptions>;
|
|
3113
|
-
/**
|
|
3114
|
-
* Return a new Runnable that maps a list of inputs to a list of outputs,
|
|
3115
|
-
* by calling invoke() with each input.
|
|
3116
|
-
*
|
|
3117
|
-
* @deprecated This will be removed in the next breaking release.
|
|
3118
|
-
*/
|
|
3119
|
-
map(): Runnable<RunInput[], RunOutput[], CallOptions>;
|
|
3120
|
-
/**
|
|
3121
|
-
* Add retry logic to an existing runnable.
|
|
3122
|
-
* @param fields.stopAfterAttempt The number of attempts to retry.
|
|
3123
|
-
* @param fields.onFailedAttempt A function that is called when a retry fails.
|
|
3124
|
-
* @returns A new RunnableRetry that, when invoked, will retry according to the parameters.
|
|
3125
|
-
*/
|
|
3126
|
-
withRetry(fields?: {
|
|
3127
|
-
stopAfterAttempt?: number;
|
|
3128
|
-
onFailedAttempt?: RunnableRetryFailedAttemptHandler;
|
|
3129
|
-
}): RunnableRetry<RunInput, RunOutput, CallOptions>;
|
|
3130
|
-
/**
|
|
3131
|
-
* Bind config to a Runnable, returning a new Runnable.
|
|
3132
|
-
* @param config New configuration parameters to attach to the new runnable.
|
|
3133
|
-
* @returns A new RunnableBinding with a config matching what's passed.
|
|
3134
|
-
*/
|
|
3135
|
-
withConfig(config: Partial<CallOptions>): Runnable<RunInput, RunOutput, CallOptions>;
|
|
3136
|
-
/**
|
|
3137
|
-
* Create a new runnable from the current one that will try invoking
|
|
3138
|
-
* other passed fallback runnables if the initial invocation fails.
|
|
3139
|
-
* @param fields.fallbacks Other runnables to call if the runnable errors.
|
|
3140
|
-
* @returns A new RunnableWithFallbacks.
|
|
3141
|
-
*/
|
|
3142
|
-
withFallbacks(fields: {
|
|
3143
|
-
fallbacks: Runnable<RunInput, RunOutput>[];
|
|
3144
|
-
} | Runnable<RunInput, RunOutput>[]): RunnableWithFallbacks<RunInput, RunOutput>;
|
|
3145
|
-
protected _getOptionsList<O extends CallOptions & {
|
|
3146
|
-
runType?: string;
|
|
3147
|
-
}>(options: Partial<O> | Partial<O>[], length?: number): Partial<O>[];
|
|
3148
|
-
/**
|
|
3149
|
-
* Default implementation of batch, which calls invoke N times.
|
|
3150
|
-
* Subclasses should override this method if they can batch more efficiently.
|
|
3151
|
-
* @param inputs Array of inputs to each batch call.
|
|
3152
|
-
* @param options Either a single call options object to apply to each batch call or an array for each call.
|
|
3153
|
-
* @param batchOptions.returnExceptions Whether to return errors rather than throwing on the first one
|
|
3154
|
-
* @returns An array of RunOutputs, or mixed RunOutputs and errors if batchOptions.returnExceptions is set
|
|
3155
|
-
*/
|
|
3156
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
3157
|
-
returnExceptions?: false;
|
|
3158
|
-
}): Promise<RunOutput[]>;
|
|
3159
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
3160
|
-
returnExceptions: true;
|
|
3161
|
-
}): Promise<(RunOutput | Error)[]>;
|
|
3162
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
3163
|
-
/**
|
|
3164
|
-
* Default streaming implementation.
|
|
3165
|
-
* Subclasses should override this method if they support streaming output.
|
|
3166
|
-
* @param input
|
|
3167
|
-
* @param options
|
|
3168
|
-
*/
|
|
3169
|
-
_streamIterator(input: RunInput, options?: Partial<CallOptions>): AsyncGenerator<RunOutput>;
|
|
3170
|
-
/**
|
|
3171
|
-
* Stream output in chunks.
|
|
3172
|
-
* @param input
|
|
3173
|
-
* @param options
|
|
3174
|
-
* @returns A readable stream that is also an iterable.
|
|
3175
|
-
*/
|
|
3176
|
-
stream(input: RunInput, options?: Partial<CallOptions>): Promise<IterableReadableStream<RunOutput>>;
|
|
3177
|
-
protected _separateRunnableConfigFromCallOptions(options?: Partial<CallOptions>): [RunnableConfig, Omit<Partial<CallOptions>, keyof RunnableConfig>];
|
|
3178
|
-
protected _callWithConfig<T extends RunInput>(func: ((input: T) => Promise<RunOutput>) | ((input: T, config?: Partial<CallOptions>, runManager?: CallbackManagerForChainRun) => Promise<RunOutput>), input: T, options?: Partial<CallOptions> & {
|
|
3179
|
-
runType?: string;
|
|
3180
|
-
}): Promise<RunOutput>;
|
|
3181
|
-
/**
|
|
3182
|
-
* Internal method that handles batching and configuration for a runnable
|
|
3183
|
-
* It takes a function, input values, and optional configuration, and
|
|
3184
|
-
* returns a promise that resolves to the output values.
|
|
3185
|
-
* @param func The function to be executed for each input value.
|
|
3186
|
-
* @param input The input values to be processed.
|
|
3187
|
-
* @param config Optional configuration for the function execution.
|
|
3188
|
-
* @returns A promise that resolves to the output values.
|
|
3189
|
-
*/
|
|
3190
|
-
_batchWithConfig<T extends RunInput>(func: (inputs: T[], options?: Partial<CallOptions>[], runManagers?: (CallbackManagerForChainRun | undefined)[], batchOptions?: RunnableBatchOptions) => Promise<(RunOutput | Error)[]>, inputs: T[], options?: Partial<CallOptions & {
|
|
3191
|
-
runType?: string;
|
|
3192
|
-
}> | Partial<CallOptions & {
|
|
3193
|
-
runType?: string;
|
|
3194
|
-
}>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
3195
|
-
/**
|
|
3196
|
-
* Helper method to transform an Iterator of Input values into an Iterator of
|
|
3197
|
-
* Output values, with callbacks.
|
|
3198
|
-
* Use this to implement `stream()` or `transform()` in Runnable subclasses.
|
|
3199
|
-
*/
|
|
3200
|
-
protected _transformStreamWithConfig<I extends RunInput, O extends RunOutput>(inputGenerator: AsyncGenerator<I>, transformer: (generator: AsyncGenerator<I>, runManager?: CallbackManagerForChainRun, options?: Partial<CallOptions>) => AsyncGenerator<O>, options?: Partial<CallOptions> & {
|
|
3201
|
-
runType?: string;
|
|
3202
|
-
}): AsyncGenerator<O>;
|
|
3203
|
-
getGraph(_?: RunnableConfig): Graph;
|
|
3204
|
-
/**
|
|
3205
|
-
* Create a new runnable sequence that runs each individual runnable in series,
|
|
3206
|
-
* piping the output of one runnable into another runnable or runnable-like.
|
|
3207
|
-
* @param coerceable A runnable, function, or object whose values are functions or runnables.
|
|
3208
|
-
* @returns A new runnable sequence.
|
|
3209
|
-
*/
|
|
3210
|
-
pipe<NewRunOutput>(coerceable: RunnableLike<RunOutput, NewRunOutput>): Runnable<RunInput, Exclude<NewRunOutput, Error>>;
|
|
3211
|
-
/**
|
|
3212
|
-
* Pick keys from the dict output of this runnable. Returns a new runnable.
|
|
3213
|
-
*/
|
|
3214
|
-
pick(keys: string | string[]): Runnable;
|
|
3215
|
-
/**
|
|
3216
|
-
* Assigns new fields to the dict output of this runnable. Returns a new runnable.
|
|
3217
|
-
*/
|
|
3218
|
-
assign(mapping: RunnableMapLike<Record<string, unknown>, Record<string, unknown>>): Runnable;
|
|
3219
|
-
/**
|
|
3220
|
-
* Default implementation of transform, which buffers input and then calls stream.
|
|
3221
|
-
* Subclasses should override this method if they can start producing output while
|
|
3222
|
-
* input is still being generated.
|
|
3223
|
-
* @param generator
|
|
3224
|
-
* @param options
|
|
3225
|
-
*/
|
|
3226
|
-
transform(generator: AsyncGenerator<RunInput>, options: Partial<CallOptions>): AsyncGenerator<RunOutput>;
|
|
3227
|
-
/**
|
|
3228
|
-
* Stream all output from a runnable, as reported to the callback system.
|
|
3229
|
-
* This includes all inner runs of LLMs, Retrievers, Tools, etc.
|
|
3230
|
-
* Output is streamed as Log objects, which include a list of
|
|
3231
|
-
* jsonpatch ops that describe how the state of the run has changed in each
|
|
3232
|
-
* step, and the final state of the run.
|
|
3233
|
-
* The jsonpatch ops can be applied in order to construct state.
|
|
3234
|
-
* @param input
|
|
3235
|
-
* @param options
|
|
3236
|
-
* @param streamOptions
|
|
3237
|
-
*/
|
|
3238
|
-
streamLog(input: RunInput, options?: Partial<CallOptions>, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose">): AsyncGenerator<RunLogPatch>;
|
|
3239
|
-
protected _streamLog(input: RunInput, logStreamCallbackHandler: LogStreamCallbackHandler, config: Partial<CallOptions>): AsyncGenerator<RunLogPatch>;
|
|
3240
|
-
/**
|
|
3241
|
-
* Generate a stream of events emitted by the internal steps of the runnable.
|
|
3242
|
-
*
|
|
3243
|
-
* Use to create an iterator over StreamEvents that provide real-time information
|
|
3244
|
-
* about the progress of the runnable, including StreamEvents from intermediate
|
|
3245
|
-
* results.
|
|
3246
|
-
*
|
|
3247
|
-
* A StreamEvent is a dictionary with the following schema:
|
|
3248
|
-
*
|
|
3249
|
-
* - `event`: string - Event names are of the format: on_[runnable_type]_(start|stream|end).
|
|
3250
|
-
* - `name`: string - The name of the runnable that generated the event.
|
|
3251
|
-
* - `run_id`: string - Randomly generated ID associated with the given execution of
|
|
3252
|
-
* the runnable that emitted the event. A child runnable that gets invoked as part of the execution of a
|
|
3253
|
-
* parent runnable is assigned its own unique ID.
|
|
3254
|
-
* - `tags`: string[] - The tags of the runnable that generated the event.
|
|
3255
|
-
* - `metadata`: Record<string, any> - The metadata of the runnable that generated the event.
|
|
3256
|
-
* - `data`: Record<string, any>
|
|
3257
|
-
*
|
|
3258
|
-
* Below is a table that illustrates some events that might be emitted by various
|
|
3259
|
-
* chains. Metadata fields have been omitted from the table for brevity.
|
|
3260
|
-
* Chain definitions have been included after the table.
|
|
3261
|
-
*
|
|
3262
|
-
* **ATTENTION** This reference table is for the V2 version of the schema.
|
|
3263
|
-
*
|
|
3264
|
-
* ```md
|
|
3265
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3266
|
-
* | event | input | output/chunk |
|
|
3267
|
-
* +======================+=============================+==========================================+
|
|
3268
|
-
* | on_chat_model_start | {"messages": BaseMessage[]} | |
|
|
3269
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3270
|
-
* | on_chat_model_stream | | AIMessageChunk("hello") |
|
|
3271
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3272
|
-
* | on_chat_model_end | {"messages": BaseMessage[]} | AIMessageChunk("hello world") |
|
|
3273
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3274
|
-
* | on_llm_start | {'input': 'hello'} | |
|
|
3275
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3276
|
-
* | on_llm_stream | | 'Hello' |
|
|
3277
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3278
|
-
* | on_llm_end | 'Hello human!' | |
|
|
3279
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3280
|
-
* | on_chain_start | | |
|
|
3281
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3282
|
-
* | on_chain_stream | | "hello world!" |
|
|
3283
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3284
|
-
* | on_chain_end | [Document(...)] | "hello world!, goodbye world!" |
|
|
3285
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3286
|
-
* | on_tool_start | {"x": 1, "y": "2"} | |
|
|
3287
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3288
|
-
* | on_tool_end | | {"x": 1, "y": "2"} |
|
|
3289
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3290
|
-
* | on_retriever_start | {"query": "hello"} | |
|
|
3291
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3292
|
-
* | on_retriever_end | {"query": "hello"} | [Document(...), ..] |
|
|
3293
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3294
|
-
* | on_prompt_start | {"question": "hello"} | |
|
|
3295
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3296
|
-
* | on_prompt_end | {"question": "hello"} | ChatPromptValue(messages: BaseMessage[]) |
|
|
3297
|
-
* +----------------------+-----------------------------+------------------------------------------+
|
|
3298
|
-
* ```
|
|
3299
|
-
*
|
|
3300
|
-
* The "on_chain_*" events are the default for Runnables that don't fit one of the above categories.
|
|
3301
|
-
*
|
|
3302
|
-
* In addition to the standard events above, users can also dispatch custom events.
|
|
3303
|
-
*
|
|
3304
|
-
* Custom events will be only be surfaced with in the `v2` version of the API!
|
|
3305
|
-
*
|
|
3306
|
-
* A custom event has following format:
|
|
3307
|
-
*
|
|
3308
|
-
* ```md
|
|
3309
|
-
* +-----------+------+------------------------------------------------------------+
|
|
3310
|
-
* | Attribute | Type | Description |
|
|
3311
|
-
* +===========+======+============================================================+
|
|
3312
|
-
* | name | str | A user defined name for the event. |
|
|
3313
|
-
* +-----------+------+------------------------------------------------------------+
|
|
3314
|
-
* | data | Any | The data associated with the event. This can be anything. |
|
|
3315
|
-
* +-----------+------+------------------------------------------------------------+
|
|
3316
|
-
* ```
|
|
3317
|
-
*
|
|
3318
|
-
* Here's an example:
|
|
3319
|
-
*
|
|
3320
|
-
* ```ts
|
|
3321
|
-
* import { RunnableLambda } from "@langchain/core/runnables";
|
|
3322
|
-
* import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch";
|
|
3323
|
-
* // Use this import for web environments that don't support "async_hooks"
|
|
3324
|
-
* // and manually pass config to child runs.
|
|
3325
|
-
* // import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch/web";
|
|
3326
|
-
*
|
|
3327
|
-
* const slowThing = RunnableLambda.from(async (someInput: string) => {
|
|
3328
|
-
* // Placeholder for some slow operation
|
|
3329
|
-
* await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3330
|
-
* await dispatchCustomEvent("progress_event", {
|
|
3331
|
-
* message: "Finished step 1 of 2",
|
|
3332
|
-
* });
|
|
3333
|
-
* await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3334
|
-
* return "Done";
|
|
3335
|
-
* });
|
|
3336
|
-
*
|
|
3337
|
-
* const eventStream = await slowThing.streamEvents("hello world", {
|
|
3338
|
-
* version: "v2",
|
|
3339
|
-
* });
|
|
3340
|
-
*
|
|
3341
|
-
* for await (const event of eventStream) {
|
|
3342
|
-
* if (event.event === "on_custom_event") {
|
|
3343
|
-
* console.log(event);
|
|
3344
|
-
* }
|
|
3345
|
-
* }
|
|
3346
|
-
* ```
|
|
3347
|
-
*/
|
|
3348
|
-
streamEvents(input: RunInput, options: Partial<CallOptions> & {
|
|
3349
|
-
version: "v1" | "v2";
|
|
3350
|
-
}, streamOptions?: Omit<EventStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<StreamEvent>;
|
|
3351
|
-
streamEvents(input: RunInput, options: Partial<CallOptions> & {
|
|
3352
|
-
version: "v1" | "v2";
|
|
3353
|
-
encoding: "text/event-stream";
|
|
3354
|
-
}, streamOptions?: Omit<EventStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<Uint8Array>;
|
|
3355
|
-
private _streamEventsV2;
|
|
3356
|
-
private _streamEventsV1;
|
|
3357
|
-
static isRunnable(thing: any): thing is Runnable;
|
|
3358
|
-
/**
|
|
3359
|
-
* Bind lifecycle listeners to a Runnable, returning a new Runnable.
|
|
3360
|
-
* The Run object contains information about the run, including its id,
|
|
3361
|
-
* type, input, output, error, startTime, endTime, and any tags or metadata
|
|
3362
|
-
* added to the run.
|
|
3363
|
-
*
|
|
3364
|
-
* @param {Object} params - The object containing the callback functions.
|
|
3365
|
-
* @param {(run: Run) => void} params.onStart - Called before the runnable starts running, with the Run object.
|
|
3366
|
-
* @param {(run: Run) => void} params.onEnd - Called after the runnable finishes running, with the Run object.
|
|
3367
|
-
* @param {(run: Run) => void} params.onError - Called if the runnable throws an error, with the Run object.
|
|
3368
|
-
*/
|
|
3369
|
-
withListeners({ onStart, onEnd, onError, }: {
|
|
3370
|
-
onStart?: (run: Run, config?: RunnableConfig) => void | Promise<void>;
|
|
3371
|
-
onEnd?: (run: Run, config?: RunnableConfig) => void | Promise<void>;
|
|
3372
|
-
onError?: (run: Run, config?: RunnableConfig) => void | Promise<void>;
|
|
3373
|
-
}): Runnable<RunInput, RunOutput, CallOptions>;
|
|
3374
|
-
/**
|
|
3375
|
-
* Convert a runnable to a tool. Return a new instance of `RunnableToolLike`
|
|
3376
|
-
* which contains the runnable, name, description and schema.
|
|
3377
|
-
*
|
|
3378
|
-
* @template {T extends RunInput = RunInput} RunInput - The input type of the runnable. Should be the same as the `RunInput` type of the runnable.
|
|
3379
|
-
*
|
|
3380
|
-
* @param fields
|
|
3381
|
-
* @param {string | undefined} [fields.name] The name of the tool. If not provided, it will default to the name of the runnable.
|
|
3382
|
-
* @param {string | undefined} [fields.description] The description of the tool. Falls back to the description on the Zod schema if not provided, or undefined if neither are provided.
|
|
3383
|
-
* @param {z.ZodType<T>} [fields.schema] The Zod schema for the input of the tool. Infers the Zod type from the input type of the runnable.
|
|
3384
|
-
* @returns {RunnableToolLike<z.ZodType<T>, RunOutput>} An instance of `RunnableToolLike` which is a runnable that can be used as a tool.
|
|
3385
|
-
*/
|
|
3386
|
-
asTool<T extends RunInput = RunInput>(fields: {
|
|
3387
|
-
name?: string;
|
|
3388
|
-
description?: string;
|
|
3389
|
-
schema: InteropZodType<T>;
|
|
3390
|
-
}): RunnableToolLike<InteropZodType<T | ToolCall>, RunOutput>;
|
|
3391
|
-
}
|
|
3392
|
-
type RunnableBindingArgs<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = {
|
|
3393
|
-
bound: Runnable<RunInput, RunOutput, CallOptions>;
|
|
3394
|
-
/**
|
|
3395
|
-
* @deprecated use {@link config} instead
|
|
3396
|
-
*/
|
|
3397
|
-
kwargs?: Partial<CallOptions>;
|
|
3398
|
-
config: RunnableConfig;
|
|
3399
|
-
configFactories?: Array<(config: RunnableConfig) => RunnableConfig | Promise<RunnableConfig>>;
|
|
3400
|
-
};
|
|
3401
|
-
/**
|
|
3402
|
-
* Wraps a runnable and applies partial config upon invocation.
|
|
3403
|
-
*
|
|
3404
|
-
* @example
|
|
3405
|
-
* ```typescript
|
|
3406
|
-
* import {
|
|
3407
|
-
* type RunnableConfig,
|
|
3408
|
-
* RunnableLambda,
|
|
3409
|
-
* } from "@langchain/core/runnables";
|
|
3410
|
-
*
|
|
3411
|
-
* const enhanceProfile = (
|
|
3412
|
-
* profile: Record<string, any>,
|
|
3413
|
-
* config?: RunnableConfig
|
|
3414
|
-
* ) => {
|
|
3415
|
-
* if (config?.configurable?.role) {
|
|
3416
|
-
* return { ...profile, role: config.configurable.role };
|
|
3417
|
-
* }
|
|
3418
|
-
* return profile;
|
|
3419
|
-
* };
|
|
3420
|
-
*
|
|
3421
|
-
* const runnable = RunnableLambda.from(enhanceProfile);
|
|
3422
|
-
*
|
|
3423
|
-
* // Bind configuration to the runnable to set the user's role dynamically
|
|
3424
|
-
* const adminRunnable = runnable.bind({ configurable: { role: "Admin" } });
|
|
3425
|
-
* const userRunnable = runnable.bind({ configurable: { role: "User" } });
|
|
3426
|
-
*
|
|
3427
|
-
* const result1 = await adminRunnable.invoke({
|
|
3428
|
-
* name: "Alice",
|
|
3429
|
-
* email: "alice@example.com"
|
|
3430
|
-
* });
|
|
3431
|
-
*
|
|
3432
|
-
* // { name: "Alice", email: "alice@example.com", role: "Admin" }
|
|
3433
|
-
*
|
|
3434
|
-
* const result2 = await userRunnable.invoke({
|
|
3435
|
-
* name: "Bob",
|
|
3436
|
-
* email: "bob@example.com"
|
|
3437
|
-
* });
|
|
3438
|
-
*
|
|
3439
|
-
* // { name: "Bob", email: "bob@example.com", role: "User" }
|
|
3440
|
-
* ```
|
|
3441
|
-
*/
|
|
3442
|
-
declare class RunnableBinding<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> extends Runnable<RunInput, RunOutput, CallOptions> {
|
|
3443
|
-
static lc_name(): string;
|
|
3444
|
-
lc_namespace: string[];
|
|
3445
|
-
lc_serializable: boolean;
|
|
3446
|
-
bound: Runnable<RunInput, RunOutput, CallOptions>;
|
|
3447
|
-
config: RunnableConfig;
|
|
3448
|
-
kwargs?: Partial<CallOptions>;
|
|
3449
|
-
configFactories?: Array<(config: RunnableConfig) => RunnableConfig | Promise<RunnableConfig>>;
|
|
3450
|
-
constructor(fields: RunnableBindingArgs<RunInput, RunOutput, CallOptions>);
|
|
3451
|
-
getName(suffix?: string | undefined): string;
|
|
3452
|
-
_mergeConfig(...options: (Partial<CallOptions> | RunnableConfig | undefined)[]): Promise<Partial<CallOptions>>;
|
|
3453
|
-
/**
|
|
3454
|
-
* Binds the runnable with the specified arguments.
|
|
3455
|
-
* @param kwargs The arguments to bind the runnable with.
|
|
3456
|
-
* @returns A new instance of the `RunnableBinding` class that is bound with the specified arguments.
|
|
3457
|
-
*
|
|
3458
|
-
* @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
|
|
3459
|
-
*/
|
|
3460
|
-
bind(kwargs: Partial<CallOptions>): RunnableBinding<RunInput, RunOutput, CallOptions>;
|
|
3461
|
-
withConfig(config: Partial<CallOptions>): Runnable<RunInput, RunOutput, CallOptions>;
|
|
3462
|
-
withRetry(fields?: {
|
|
3463
|
-
stopAfterAttempt?: number;
|
|
3464
|
-
onFailedAttempt?: RunnableRetryFailedAttemptHandler;
|
|
3465
|
-
}): RunnableRetry<RunInput, RunOutput, CallOptions>;
|
|
3466
|
-
invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
|
|
3467
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
3468
|
-
returnExceptions?: false;
|
|
3469
|
-
}): Promise<RunOutput[]>;
|
|
3470
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
3471
|
-
returnExceptions: true;
|
|
3472
|
-
}): Promise<(RunOutput | Error)[]>;
|
|
3473
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
3474
|
-
_streamIterator(input: RunInput, options?: Partial<CallOptions> | undefined): AsyncGenerator<Awaited<RunOutput>, void, any>;
|
|
3475
|
-
stream(input: RunInput, options?: Partial<CallOptions> | undefined): Promise<IterableReadableStream<RunOutput>>;
|
|
3476
|
-
transform(generator: AsyncGenerator<RunInput>, options?: Partial<CallOptions>): AsyncGenerator<RunOutput>;
|
|
3477
|
-
streamEvents(input: RunInput, options: Partial<CallOptions> & {
|
|
3478
|
-
version: "v1" | "v2";
|
|
3479
|
-
}, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<StreamEvent>;
|
|
3480
|
-
streamEvents(input: RunInput, options: Partial<CallOptions> & {
|
|
3481
|
-
version: "v1" | "v2";
|
|
3482
|
-
encoding: "text/event-stream";
|
|
3483
|
-
}, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<Uint8Array>;
|
|
3484
|
-
static isRunnableBinding(thing: any): thing is RunnableBinding<any, any, any>;
|
|
3485
|
-
/**
|
|
3486
|
-
* Bind lifecycle listeners to a Runnable, returning a new Runnable.
|
|
3487
|
-
* The Run object contains information about the run, including its id,
|
|
3488
|
-
* type, input, output, error, startTime, endTime, and any tags or metadata
|
|
3489
|
-
* added to the run.
|
|
3490
|
-
*
|
|
3491
|
-
* @param {Object} params - The object containing the callback functions.
|
|
3492
|
-
* @param {(run: Run) => void} params.onStart - Called before the runnable starts running, with the Run object.
|
|
3493
|
-
* @param {(run: Run) => void} params.onEnd - Called after the runnable finishes running, with the Run object.
|
|
3494
|
-
* @param {(run: Run) => void} params.onError - Called if the runnable throws an error, with the Run object.
|
|
3495
|
-
*/
|
|
3496
|
-
withListeners({ onStart, onEnd, onError, }: {
|
|
3497
|
-
onStart?: (run: Run, config?: RunnableConfig) => void | Promise<void>;
|
|
3498
|
-
onEnd?: (run: Run, config?: RunnableConfig) => void | Promise<void>;
|
|
3499
|
-
onError?: (run: Run, config?: RunnableConfig) => void | Promise<void>;
|
|
3500
|
-
}): Runnable<RunInput, RunOutput, CallOptions>;
|
|
3501
|
-
}
|
|
3502
|
-
/**
|
|
3503
|
-
* Base class for runnables that can be retried a
|
|
3504
|
-
* specified number of times.
|
|
3505
|
-
* @example
|
|
3506
|
-
* ```typescript
|
|
3507
|
-
* import {
|
|
3508
|
-
* RunnableLambda,
|
|
3509
|
-
* RunnableRetry,
|
|
3510
|
-
* } from "@langchain/core/runnables";
|
|
3511
|
-
*
|
|
3512
|
-
* // Simulate an API call that fails
|
|
3513
|
-
* const simulateApiCall = (input: string): string => {
|
|
3514
|
-
* console.log(`Attempting API call with input: ${input}`);
|
|
3515
|
-
* throw new Error("API call failed due to network issue");
|
|
3516
|
-
* };
|
|
3517
|
-
*
|
|
3518
|
-
* const apiCallLambda = RunnableLambda.from(simulateApiCall);
|
|
3519
|
-
*
|
|
3520
|
-
* // Apply retry logic using the .withRetry() method
|
|
3521
|
-
* const apiCallWithRetry = apiCallLambda.withRetry({ stopAfterAttempt: 3 });
|
|
3522
|
-
*
|
|
3523
|
-
* // Alternatively, create a RunnableRetry instance manually
|
|
3524
|
-
* const manualRetry = new RunnableRetry({
|
|
3525
|
-
* bound: apiCallLambda,
|
|
3526
|
-
* maxAttemptNumber: 3,
|
|
3527
|
-
* config: {},
|
|
3528
|
-
* });
|
|
3529
|
-
*
|
|
3530
|
-
* // Example invocation using the .withRetry() method
|
|
3531
|
-
* const res = await apiCallWithRetry
|
|
3532
|
-
* .invoke("Request 1")
|
|
3533
|
-
* .catch((error) => {
|
|
3534
|
-
* console.error("Failed after multiple retries:", error.message);
|
|
3535
|
-
* });
|
|
3536
|
-
*
|
|
3537
|
-
* // Example invocation using the manual retry instance
|
|
3538
|
-
* const res2 = await manualRetry
|
|
3539
|
-
* .invoke("Request 2")
|
|
3540
|
-
* .catch((error) => {
|
|
3541
|
-
* console.error("Failed after multiple retries:", error.message);
|
|
3542
|
-
* });
|
|
3543
|
-
* ```
|
|
3544
|
-
*/
|
|
3545
|
-
declare class RunnableRetry<RunInput = any, RunOutput = any, CallOptions extends RunnableConfig = RunnableConfig> extends RunnableBinding<RunInput, RunOutput, CallOptions> {
|
|
3546
|
-
static lc_name(): string;
|
|
3547
|
-
lc_namespace: string[];
|
|
3548
|
-
protected maxAttemptNumber: number;
|
|
3549
|
-
onFailedAttempt: RunnableRetryFailedAttemptHandler;
|
|
3550
|
-
constructor(fields: RunnableBindingArgs<RunInput, RunOutput, CallOptions> & {
|
|
3551
|
-
maxAttemptNumber?: number;
|
|
3552
|
-
onFailedAttempt?: RunnableRetryFailedAttemptHandler;
|
|
3553
|
-
});
|
|
3554
|
-
_patchConfigForRetry(attempt: number, config?: Partial<CallOptions>, runManager?: CallbackManagerForChainRun): Partial<CallOptions>;
|
|
3555
|
-
protected _invoke(input: RunInput, config?: CallOptions, runManager?: CallbackManagerForChainRun): Promise<RunOutput>;
|
|
3556
|
-
/**
|
|
3557
|
-
* Method that invokes the runnable with the specified input, run manager,
|
|
3558
|
-
* and config. It handles the retry logic by catching any errors and
|
|
3559
|
-
* recursively invoking itself with the updated config for the next retry
|
|
3560
|
-
* attempt.
|
|
3561
|
-
* @param input The input for the runnable.
|
|
3562
|
-
* @param runManager The run manager for the runnable.
|
|
3563
|
-
* @param config The config for the runnable.
|
|
3564
|
-
* @returns A promise that resolves to the output of the runnable.
|
|
3565
|
-
*/
|
|
3566
|
-
invoke(input: RunInput, config?: CallOptions): Promise<RunOutput>;
|
|
3567
|
-
_batch<ReturnExceptions extends boolean = false>(inputs: RunInput[], configs?: RunnableConfig[], runManagers?: (CallbackManagerForChainRun | undefined)[], batchOptions?: RunnableBatchOptions): Promise<ReturnExceptions extends false ? RunOutput[] : (Error | RunOutput)[]>;
|
|
3568
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
3569
|
-
returnExceptions?: false;
|
|
3570
|
-
}): Promise<RunOutput[]>;
|
|
3571
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
3572
|
-
returnExceptions: true;
|
|
3573
|
-
}): Promise<(RunOutput | Error)[]>;
|
|
3574
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
3575
|
-
}
|
|
3576
|
-
/**
|
|
3577
|
-
* A Runnable that can fallback to other Runnables if it fails.
|
|
3578
|
-
* External APIs (e.g., APIs for a language model) may at times experience
|
|
3579
|
-
* degraded performance or even downtime.
|
|
3580
|
-
*
|
|
3581
|
-
* In these cases, it can be useful to have a fallback Runnable that can be
|
|
3582
|
-
* used in place of the original Runnable (e.g., fallback to another LLM provider).
|
|
3583
|
-
*
|
|
3584
|
-
* Fallbacks can be defined at the level of a single Runnable, or at the level
|
|
3585
|
-
* of a chain of Runnables. Fallbacks are tried in order until one succeeds or
|
|
3586
|
-
* all fail.
|
|
3587
|
-
*
|
|
3588
|
-
* While you can instantiate a `RunnableWithFallbacks` directly, it is usually
|
|
3589
|
-
* more convenient to use the `withFallbacks` method on an existing Runnable.
|
|
3590
|
-
*
|
|
3591
|
-
* When streaming, fallbacks will only be called on failures during the initial
|
|
3592
|
-
* stream creation. Errors that occur after a stream starts will not fallback
|
|
3593
|
-
* to the next Runnable.
|
|
3594
|
-
*
|
|
3595
|
-
* @example
|
|
3596
|
-
* ```typescript
|
|
3597
|
-
* import {
|
|
3598
|
-
* RunnableLambda,
|
|
3599
|
-
* RunnableWithFallbacks,
|
|
3600
|
-
* } from "@langchain/core/runnables";
|
|
3601
|
-
*
|
|
3602
|
-
* const primaryOperation = (input: string): string => {
|
|
3603
|
-
* if (input !== "safe") {
|
|
3604
|
-
* throw new Error("Primary operation failed due to unsafe input");
|
|
3605
|
-
* }
|
|
3606
|
-
* return `Processed: ${input}`;
|
|
3607
|
-
* };
|
|
3608
|
-
*
|
|
3609
|
-
* // Define a fallback operation that processes the input differently
|
|
3610
|
-
* const fallbackOperation = (input: string): string =>
|
|
3611
|
-
* `Fallback processed: ${input}`;
|
|
3612
|
-
*
|
|
3613
|
-
* const primaryRunnable = RunnableLambda.from(primaryOperation);
|
|
3614
|
-
* const fallbackRunnable = RunnableLambda.from(fallbackOperation);
|
|
3615
|
-
*
|
|
3616
|
-
* // Apply the fallback logic using the .withFallbacks() method
|
|
3617
|
-
* const runnableWithFallback = primaryRunnable.withFallbacks([fallbackRunnable]);
|
|
3618
|
-
*
|
|
3619
|
-
* // Alternatively, create a RunnableWithFallbacks instance manually
|
|
3620
|
-
* const manualFallbackChain = new RunnableWithFallbacks({
|
|
3621
|
-
* runnable: primaryRunnable,
|
|
3622
|
-
* fallbacks: [fallbackRunnable],
|
|
3623
|
-
* });
|
|
3624
|
-
*
|
|
3625
|
-
* // Example invocation using .withFallbacks()
|
|
3626
|
-
* const res = await runnableWithFallback
|
|
3627
|
-
* .invoke("unsafe input")
|
|
3628
|
-
* .catch((error) => {
|
|
3629
|
-
* console.error("Failed after all attempts:", error.message);
|
|
3630
|
-
* });
|
|
3631
|
-
*
|
|
3632
|
-
* // "Fallback processed: unsafe input"
|
|
3633
|
-
*
|
|
3634
|
-
* // Example invocation using manual instantiation
|
|
3635
|
-
* const res = await manualFallbackChain
|
|
3636
|
-
* .invoke("safe")
|
|
3637
|
-
* .catch((error) => {
|
|
3638
|
-
* console.error("Failed after all attempts:", error.message);
|
|
3639
|
-
* });
|
|
3640
|
-
*
|
|
3641
|
-
* // "Processed: safe"
|
|
3642
|
-
* ```
|
|
3643
|
-
*/
|
|
3644
|
-
declare class RunnableWithFallbacks<RunInput, RunOutput> extends Runnable<RunInput, RunOutput> {
|
|
3645
|
-
static lc_name(): string;
|
|
3646
|
-
lc_namespace: string[];
|
|
3647
|
-
lc_serializable: boolean;
|
|
3648
|
-
runnable: Runnable<RunInput, RunOutput>;
|
|
3649
|
-
fallbacks: Runnable<RunInput, RunOutput>[];
|
|
3650
|
-
constructor(fields: {
|
|
3651
|
-
runnable: Runnable<RunInput, RunOutput>;
|
|
3652
|
-
fallbacks: Runnable<RunInput, RunOutput>[];
|
|
3653
|
-
});
|
|
3654
|
-
runnables(): Generator<Runnable<RunInput, RunOutput, RunnableConfig<Record<string, any>>>, void, unknown>;
|
|
3655
|
-
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunOutput>;
|
|
3656
|
-
_streamIterator(input: RunInput, options?: Partial<RunnableConfig> | undefined): AsyncGenerator<RunOutput>;
|
|
3657
|
-
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
3658
|
-
returnExceptions?: false;
|
|
3659
|
-
}): Promise<RunOutput[]>;
|
|
3660
|
-
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
3661
|
-
returnExceptions: true;
|
|
3662
|
-
}): Promise<(RunOutput | Error)[]>;
|
|
3663
|
-
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
3664
|
-
}
|
|
3665
|
-
interface RunnableToolLikeArgs<RunInput extends InteropZodType = InteropZodType, RunOutput = unknown> extends Omit<RunnableBindingArgs<InferInteropZodOutput<RunInput>, RunOutput>, "config"> {
|
|
3666
|
-
name: string;
|
|
3667
|
-
description?: string;
|
|
3668
|
-
schema: RunInput;
|
|
3669
|
-
config?: RunnableConfig;
|
|
3670
|
-
}
|
|
3671
|
-
declare class RunnableToolLike<RunInput extends InteropZodType = InteropZodType, RunOutput = unknown> extends RunnableBinding<InferInteropZodOutput<RunInput>, RunOutput> {
|
|
3672
|
-
name: string;
|
|
3673
|
-
description?: string;
|
|
3674
|
-
schema: RunInput;
|
|
3675
|
-
constructor(fields: RunnableToolLikeArgs<RunInput, RunOutput>);
|
|
3676
|
-
static lc_name(): string;
|
|
3677
|
-
}
|
|
3678
|
-
|
|
3679
|
-
type JsonSchema7AnyType = {};
|
|
3680
|
-
|
|
3681
|
-
type ErrorMessages<T extends JsonSchema7TypeUnion, OmitProperties extends string = ""> = Partial<Omit<{
|
|
3682
|
-
[key in keyof T]: string;
|
|
3683
|
-
}, OmitProperties | "type" | "errorMessages">>;
|
|
3684
|
-
|
|
3685
|
-
type JsonSchema7ArrayType = {
|
|
3686
|
-
type: "array";
|
|
3687
|
-
items?: JsonSchema7Type;
|
|
3688
|
-
minItems?: number;
|
|
3689
|
-
maxItems?: number;
|
|
3690
|
-
errorMessages?: ErrorMessages<JsonSchema7ArrayType, "items">;
|
|
3691
|
-
};
|
|
3692
|
-
|
|
3693
|
-
type JsonSchema7BigintType = {
|
|
3694
|
-
type: "integer";
|
|
3695
|
-
format: "int64";
|
|
3696
|
-
minimum?: BigInt;
|
|
3697
|
-
exclusiveMinimum?: BigInt;
|
|
3698
|
-
maximum?: BigInt;
|
|
3699
|
-
exclusiveMaximum?: BigInt;
|
|
3700
|
-
multipleOf?: BigInt;
|
|
3701
|
-
errorMessage?: ErrorMessages<JsonSchema7BigintType>;
|
|
3702
|
-
};
|
|
3703
|
-
|
|
3704
|
-
type JsonSchema7BooleanType = {
|
|
3705
|
-
type: "boolean";
|
|
3706
|
-
};
|
|
3707
|
-
|
|
3708
|
-
type JsonSchema7NumberType = {
|
|
3709
|
-
type: "number" | "integer";
|
|
3710
|
-
minimum?: number;
|
|
3711
|
-
exclusiveMinimum?: number;
|
|
3712
|
-
maximum?: number;
|
|
3713
|
-
exclusiveMaximum?: number;
|
|
3714
|
-
multipleOf?: number;
|
|
3715
|
-
errorMessage?: ErrorMessages<JsonSchema7NumberType>;
|
|
3716
|
-
};
|
|
3717
|
-
|
|
3718
|
-
type JsonSchema7DateType = {
|
|
3719
|
-
type: "integer" | "string";
|
|
3720
|
-
format: "unix-time" | "date-time" | "date";
|
|
3721
|
-
minimum?: number;
|
|
3722
|
-
maximum?: number;
|
|
3723
|
-
errorMessage?: ErrorMessages<JsonSchema7NumberType>;
|
|
3724
|
-
} | {
|
|
3725
|
-
anyOf: JsonSchema7DateType[];
|
|
3726
|
-
};
|
|
3727
|
-
|
|
3728
|
-
type JsonSchema7EnumType = {
|
|
3729
|
-
type: "string";
|
|
3730
|
-
enum: string[];
|
|
3731
|
-
};
|
|
3732
|
-
|
|
3733
|
-
type JsonSchema7AllOfType = {
|
|
3734
|
-
allOf: JsonSchema7Type[];
|
|
3735
|
-
unevaluatedProperties?: boolean;
|
|
3736
|
-
};
|
|
3737
|
-
|
|
3738
|
-
type JsonSchema7LiteralType = {
|
|
3739
|
-
type: "string" | "number" | "integer" | "boolean";
|
|
3740
|
-
const: string | number | boolean;
|
|
3741
|
-
} | {
|
|
3742
|
-
type: "object" | "array";
|
|
3743
|
-
};
|
|
3744
|
-
|
|
3745
|
-
type JsonSchema7StringType = {
|
|
3746
|
-
type: "string";
|
|
3747
|
-
minLength?: number;
|
|
3748
|
-
maxLength?: number;
|
|
3749
|
-
format?: "email" | "idn-email" | "uri" | "uuid" | "date-time" | "ipv4" | "ipv6" | "date" | "time" | "duration";
|
|
3750
|
-
pattern?: string;
|
|
3751
|
-
allOf?: {
|
|
3752
|
-
pattern: string;
|
|
3753
|
-
errorMessage?: ErrorMessages<{
|
|
3754
|
-
pattern: string;
|
|
3755
|
-
}>;
|
|
3756
|
-
}[];
|
|
3757
|
-
anyOf?: {
|
|
3758
|
-
format: string;
|
|
3759
|
-
errorMessage?: ErrorMessages<{
|
|
3760
|
-
format: string;
|
|
3761
|
-
}>;
|
|
3762
|
-
}[];
|
|
3763
|
-
errorMessage?: ErrorMessages<JsonSchema7StringType>;
|
|
3764
|
-
contentEncoding?: string;
|
|
3765
|
-
};
|
|
3766
|
-
|
|
3767
|
-
type JsonSchema7RecordPropertyNamesType = Omit<JsonSchema7StringType, "type"> | Omit<JsonSchema7EnumType, "type">;
|
|
3768
|
-
type JsonSchema7RecordType = {
|
|
3769
|
-
type: "object";
|
|
3770
|
-
additionalProperties?: JsonSchema7Type | true;
|
|
3771
|
-
propertyNames?: JsonSchema7RecordPropertyNamesType;
|
|
3772
|
-
};
|
|
3773
|
-
|
|
3774
|
-
type JsonSchema7MapType = {
|
|
3775
|
-
type: "array";
|
|
3776
|
-
maxItems: 125;
|
|
3777
|
-
items: {
|
|
3778
|
-
type: "array";
|
|
3779
|
-
items: [JsonSchema7Type, JsonSchema7Type];
|
|
3780
|
-
minItems: 2;
|
|
3781
|
-
maxItems: 2;
|
|
3782
|
-
};
|
|
3783
|
-
};
|
|
3784
|
-
|
|
3785
|
-
type JsonSchema7NativeEnumType = {
|
|
3786
|
-
type: "string" | "number" | ["string", "number"];
|
|
3787
|
-
enum: (string | number)[];
|
|
3788
|
-
};
|
|
3789
|
-
|
|
3790
|
-
type JsonSchema7NeverType = {
|
|
3791
|
-
not: {};
|
|
3792
|
-
};
|
|
3793
|
-
|
|
3794
|
-
type JsonSchema7NullType = {
|
|
3795
|
-
type: "null";
|
|
3796
|
-
};
|
|
3797
|
-
|
|
3798
|
-
type JsonSchema7NullableType = {
|
|
3799
|
-
anyOf: [JsonSchema7Type, JsonSchema7NullType];
|
|
3800
|
-
} | {
|
|
3801
|
-
type: [string, "null"];
|
|
3802
|
-
};
|
|
3803
|
-
|
|
3804
|
-
type JsonSchema7ObjectType = {
|
|
3805
|
-
type: "object";
|
|
3806
|
-
properties: Record<string, JsonSchema7Type>;
|
|
3807
|
-
additionalProperties?: boolean | JsonSchema7Type;
|
|
3808
|
-
required?: string[];
|
|
3809
|
-
};
|
|
3810
|
-
|
|
3811
|
-
type JsonSchema7SetType = {
|
|
3812
|
-
type: "array";
|
|
3813
|
-
uniqueItems: true;
|
|
3814
|
-
items?: JsonSchema7Type;
|
|
3815
|
-
minItems?: number;
|
|
3816
|
-
maxItems?: number;
|
|
3817
|
-
errorMessage?: ErrorMessages<JsonSchema7SetType>;
|
|
3818
|
-
};
|
|
3819
|
-
|
|
3820
|
-
type JsonSchema7TupleType = {
|
|
3821
|
-
type: "array";
|
|
3822
|
-
minItems: number;
|
|
3823
|
-
items: JsonSchema7Type[];
|
|
3824
|
-
} & ({
|
|
3825
|
-
maxItems: number;
|
|
3826
|
-
} | {
|
|
3827
|
-
additionalItems?: JsonSchema7Type;
|
|
3828
|
-
});
|
|
3829
|
-
|
|
3830
|
-
type JsonSchema7UndefinedType = {
|
|
3831
|
-
not: {};
|
|
3832
|
-
};
|
|
3833
|
-
|
|
3834
|
-
declare const primitiveMappings: {
|
|
3835
|
-
readonly ZodString: "string";
|
|
3836
|
-
readonly ZodNumber: "number";
|
|
3837
|
-
readonly ZodBigInt: "integer";
|
|
3838
|
-
readonly ZodBoolean: "boolean";
|
|
3839
|
-
readonly ZodNull: "null";
|
|
3840
|
-
};
|
|
3841
|
-
type JsonSchema7Primitive = (typeof primitiveMappings)[keyof typeof primitiveMappings];
|
|
3842
|
-
type JsonSchema7UnionType = JsonSchema7PrimitiveUnionType | JsonSchema7AnyOfType;
|
|
3843
|
-
type JsonSchema7PrimitiveUnionType = {
|
|
3844
|
-
type: JsonSchema7Primitive | JsonSchema7Primitive[];
|
|
3845
|
-
} | {
|
|
3846
|
-
type: JsonSchema7Primitive | JsonSchema7Primitive[];
|
|
3847
|
-
enum: (string | number | bigint | boolean | null)[];
|
|
3848
|
-
};
|
|
3849
|
-
type JsonSchema7AnyOfType = {
|
|
3850
|
-
anyOf: JsonSchema7Type[];
|
|
3851
|
-
};
|
|
3852
|
-
|
|
3853
|
-
type JsonSchema7UnknownType = {};
|
|
3854
|
-
|
|
3855
|
-
type JsonSchema7RefType = {
|
|
3856
|
-
$ref: string;
|
|
3857
|
-
};
|
|
3858
|
-
type JsonSchema7Meta = {
|
|
3859
|
-
title?: string;
|
|
3860
|
-
default?: any;
|
|
3861
|
-
description?: string;
|
|
3862
|
-
markdownDescription?: string;
|
|
3863
|
-
};
|
|
3864
|
-
type JsonSchema7TypeUnion = JsonSchema7StringType | JsonSchema7ArrayType | JsonSchema7NumberType | JsonSchema7BigintType | JsonSchema7BooleanType | JsonSchema7DateType | JsonSchema7EnumType | JsonSchema7LiteralType | JsonSchema7NativeEnumType | JsonSchema7NullType | JsonSchema7NumberType | JsonSchema7ObjectType | JsonSchema7RecordType | JsonSchema7TupleType | JsonSchema7UnionType | JsonSchema7UndefinedType | JsonSchema7RefType | JsonSchema7NeverType | JsonSchema7MapType | JsonSchema7AnyType | JsonSchema7NullableType | JsonSchema7AllOfType | JsonSchema7UnknownType | JsonSchema7SetType;
|
|
3865
|
-
type JsonSchema7Type = JsonSchema7TypeUnion & JsonSchema7Meta;
|
|
3866
|
-
|
|
3867
|
-
type JSONSchema = JsonSchema7Type;
|
|
3868
|
-
|
|
3869
|
-
interface BaseLangChainParams {
|
|
3870
|
-
verbose?: boolean;
|
|
3871
|
-
callbacks?: Callbacks;
|
|
3872
|
-
tags?: string[];
|
|
3873
|
-
metadata?: Record<string, unknown>;
|
|
3874
|
-
}
|
|
3875
|
-
/**
|
|
3876
|
-
* Base class for language models, chains, tools.
|
|
3877
|
-
*/
|
|
3878
|
-
declare abstract class BaseLangChain<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> extends Runnable<RunInput, RunOutput, CallOptions> implements BaseLangChainParams {
|
|
3879
|
-
/**
|
|
3880
|
-
* Whether to print out response text.
|
|
3881
|
-
*/
|
|
3882
|
-
verbose: boolean;
|
|
3883
|
-
callbacks?: Callbacks;
|
|
3884
|
-
tags?: string[];
|
|
3885
|
-
metadata?: Record<string, unknown>;
|
|
3886
|
-
get lc_attributes(): {
|
|
3887
|
-
[key: string]: undefined;
|
|
3888
|
-
} | undefined;
|
|
3889
|
-
constructor(params: BaseLangChainParams);
|
|
3890
|
-
}
|
|
3891
|
-
|
|
3892
|
-
type ResponseFormat = "content" | "content_and_artifact" | string;
|
|
3893
|
-
type ToolOutputType = any;
|
|
3894
|
-
/**
|
|
3895
|
-
* Conditional type that determines the return type of the {@link StructuredTool.invoke} method.
|
|
3896
|
-
* - If the input is a ToolCall, it returns a ToolMessage
|
|
3897
|
-
* - If the config is a runnable config and contains a toolCall property, it returns a ToolMessage
|
|
3898
|
-
* - Otherwise, it returns the original output type
|
|
3899
|
-
*/
|
|
3900
|
-
type ToolReturnType<TInput, TConfig, TOutput> = TOutput extends DirectToolOutput ? TOutput : TConfig extends {
|
|
3901
|
-
toolCall: {
|
|
3902
|
-
id: string;
|
|
3903
|
-
};
|
|
3904
|
-
} ? ToolMessage : TConfig extends {
|
|
3905
|
-
toolCall: {
|
|
3906
|
-
id: undefined;
|
|
3907
|
-
};
|
|
3908
|
-
} ? TOutput : TConfig extends {
|
|
3909
|
-
toolCall: {
|
|
3910
|
-
id?: string;
|
|
3911
|
-
};
|
|
3912
|
-
} ? TOutput | ToolMessage : TInput extends ToolCall ? ToolMessage : TOutput;
|
|
3913
|
-
/**
|
|
3914
|
-
* Base type that establishes the types of input schemas that can be used for LangChain tool
|
|
3915
|
-
* definitions.
|
|
3916
|
-
*/
|
|
3917
|
-
type ToolInputSchemaBase = z.ZodTypeAny | JSONSchema;
|
|
3918
|
-
/**
|
|
3919
|
-
* Parameters for the Tool classes.
|
|
3920
|
-
*/
|
|
3921
|
-
interface ToolParams extends BaseLangChainParams {
|
|
3922
|
-
/**
|
|
3923
|
-
* The tool response format.
|
|
3924
|
-
*
|
|
3925
|
-
* If "content" then the output of the tool is interpreted as the contents of a
|
|
3926
|
-
* ToolMessage. If "content_and_artifact" then the output is expected to be a
|
|
3927
|
-
* two-tuple corresponding to the (content, artifact) of a ToolMessage.
|
|
3928
|
-
*
|
|
3929
|
-
* @default "content"
|
|
3930
|
-
*/
|
|
3931
|
-
responseFormat?: ResponseFormat;
|
|
3932
|
-
/**
|
|
3933
|
-
* Default config object for the tool runnable.
|
|
3934
|
-
*/
|
|
3935
|
-
defaultConfig?: ToolRunnableConfig;
|
|
3936
|
-
/**
|
|
3937
|
-
* Whether to show full details in the thrown parsing errors.
|
|
3938
|
-
*
|
|
3939
|
-
* @default false
|
|
3940
|
-
*/
|
|
3941
|
-
verboseParsingErrors?: boolean;
|
|
3942
|
-
}
|
|
3943
|
-
type ToolRunnableConfig<ConfigurableFieldType extends Record<string, any> = Record<string, any>> = RunnableConfig<ConfigurableFieldType> & {
|
|
3944
|
-
toolCall?: ToolCall;
|
|
3945
|
-
};
|
|
3946
|
-
/**
|
|
3947
|
-
* Utility type that resolves the output type of a tool input schema.
|
|
3948
|
-
*
|
|
3949
|
-
* Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur
|
|
3950
|
-
* during parsing. When using JSONSchema, input and output types are the same.
|
|
3951
|
-
*
|
|
3952
|
-
* The input type for a given schema should match the structure of the arguments that the LLM
|
|
3953
|
-
* generates as part of its {@link ToolCall}. The output type will be the type that results from
|
|
3954
|
-
* applying any transforms defined in your schema. If there are no transforms, the input and output
|
|
3955
|
-
* types will be the same.
|
|
3956
|
-
*/
|
|
3957
|
-
type ToolInputSchemaOutputType<T> = T extends InteropZodType ? InferInteropZodOutput<T> : T extends JSONSchema ? unknown : never;
|
|
3958
|
-
/**
|
|
3959
|
-
* Utility type that resolves the input type of a tool input schema.
|
|
3960
|
-
*
|
|
3961
|
-
* Input & Output types are a concept used with Zod schema, as Zod allows for transforms to occur
|
|
3962
|
-
* during parsing. When using JSONSchema, input and output types are the same.
|
|
3963
|
-
*
|
|
3964
|
-
* The input type for a given schema should match the structure of the arguments that the LLM
|
|
3965
|
-
* generates as part of its {@link ToolCall}. The output type will be the type that results from
|
|
3966
|
-
* applying any transforms defined in your schema. If there are no transforms, the input and output
|
|
3967
|
-
* types will be the same.
|
|
3968
|
-
*/
|
|
3969
|
-
type ToolInputSchemaInputType<T> = T extends InteropZodType ? InferInteropZodInput<T> : T extends JSONSchema ? unknown : never;
|
|
3970
|
-
/**
|
|
3971
|
-
* Defines the type that will be passed into a tool handler function as a result of a tool call.
|
|
3972
|
-
*
|
|
3973
|
-
* @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.
|
|
3974
|
-
* @param SchemaInputT - The TypeScript type representing the structure of the tool arguments generated by the LLM. Useful for type checking tool handler functions when using JSONSchema.
|
|
3975
|
-
*/
|
|
3976
|
-
type StructuredToolCallInput<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>> = (ToolInputSchemaOutputType<SchemaT> extends string ? string : never) | SchemaInputT | ToolCall;
|
|
3977
|
-
/**
|
|
3978
|
-
* An input schema type for tools that accept a single string input.
|
|
3979
|
-
*
|
|
3980
|
-
* This schema defines a tool that takes an optional string parameter named "input".
|
|
3981
|
-
* It uses Zod's effects to transform the input and strip any extra properties.
|
|
3982
|
-
*
|
|
3983
|
-
* This is primarily used for creating simple string-based tools where the LLM
|
|
3984
|
-
* only needs to provide a single text value as input to the tool.
|
|
3985
|
-
*/
|
|
3986
|
-
type StringInputToolSchema = z.ZodType<string | undefined, z.ZodTypeDef, any>;
|
|
3987
|
-
/**
|
|
3988
|
-
* Interface that defines the shape of a LangChain structured tool.
|
|
3989
|
-
*
|
|
3990
|
-
* A structured tool is a tool that uses a schema to define the structure of the arguments that the
|
|
3991
|
-
* LLM generates as part of its {@link ToolCall}.
|
|
3992
|
-
*
|
|
3993
|
-
* @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.
|
|
3994
|
-
* @param SchemaInputT - The TypeScript type representing the structure of the tool arguments generated by the LLM. Useful for type checking tool handler functions when using JSONSchema.
|
|
3995
|
-
*/
|
|
3996
|
-
interface StructuredToolInterface<SchemaT = ToolInputSchemaBase, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends RunnableInterface<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> {
|
|
3997
|
-
lc_namespace: string[];
|
|
3998
|
-
/**
|
|
3999
|
-
* A Zod schema representing the parameters of the tool.
|
|
4000
|
-
*/
|
|
4001
|
-
schema: SchemaT;
|
|
4002
|
-
/**
|
|
4003
|
-
* Invokes the tool with the provided argument and configuration.
|
|
4004
|
-
* @param arg The input argument for the tool.
|
|
4005
|
-
* @param configArg Optional configuration for the tool call.
|
|
4006
|
-
* @returns A Promise that resolves with the tool's output.
|
|
4007
|
-
*/
|
|
4008
|
-
invoke<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;
|
|
4009
|
-
/**
|
|
4010
|
-
* @deprecated Use .invoke() instead. Will be removed in 0.3.0.
|
|
4011
|
-
*
|
|
4012
|
-
* Calls the tool with the provided argument, configuration, and tags. It
|
|
4013
|
-
* parses the input according to the schema, handles any errors, and
|
|
4014
|
-
* manages callbacks.
|
|
4015
|
-
* @param arg The input argument for the tool.
|
|
4016
|
-
* @param configArg Optional configuration or callbacks for the tool.
|
|
4017
|
-
* @param tags Optional tags for the tool.
|
|
4018
|
-
* @returns A Promise that resolves with a string.
|
|
4019
|
-
*/
|
|
4020
|
-
call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig,
|
|
4021
|
-
/** @deprecated */
|
|
4022
|
-
tags?: string[]): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;
|
|
4023
|
-
/**
|
|
4024
|
-
* The name of the tool.
|
|
4025
|
-
*/
|
|
4026
|
-
name: string;
|
|
4027
|
-
/**
|
|
4028
|
-
* A description of the tool.
|
|
4029
|
-
*/
|
|
4030
|
-
description: string;
|
|
4031
|
-
/**
|
|
4032
|
-
* Whether to return the tool's output directly.
|
|
4033
|
-
*
|
|
4034
|
-
* Setting this to true means that after the tool is called,
|
|
4035
|
-
* an agent should stop looping.
|
|
4036
|
-
*/
|
|
4037
|
-
returnDirect: boolean;
|
|
4038
|
-
}
|
|
4039
|
-
/**
|
|
4040
|
-
* A special interface for tools that accept a string input, usually defined with the {@link Tool} class.
|
|
4041
|
-
*
|
|
4042
|
-
* @param SchemaT - The type of the tool input schema. Usually you don't need to specify this.
|
|
4043
|
-
* @param SchemaInputT - The TypeScript type representing the structure of the tool arguments generated by the LLM. Useful for type checking tool handler functions when using JSONSchema.
|
|
4044
|
-
*/
|
|
4045
|
-
interface ToolInterface<SchemaT = StringInputToolSchema, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {
|
|
4046
|
-
/**
|
|
4047
|
-
* @deprecated Use .invoke() instead. Will be removed in 0.3.0.
|
|
4048
|
-
*
|
|
4049
|
-
* Calls the tool with the provided argument and callbacks. It handles
|
|
4050
|
-
* string inputs specifically.
|
|
4051
|
-
* @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.
|
|
4052
|
-
* @param callbacks Optional callbacks for the tool.
|
|
4053
|
-
* @returns A Promise that resolves with a string.
|
|
4054
|
-
*/
|
|
4055
|
-
call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, callbacks?: TConfig): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;
|
|
4056
|
-
}
|
|
4057
|
-
/**
|
|
4058
|
-
* Base interface for the input parameters of the {@link DynamicTool} and
|
|
4059
|
-
* {@link DynamicStructuredTool} classes.
|
|
4060
|
-
*/
|
|
4061
|
-
interface BaseDynamicToolInput extends ToolParams {
|
|
4062
|
-
name: string;
|
|
4063
|
-
description: string;
|
|
4064
|
-
/**
|
|
4065
|
-
* Whether to return the tool's output directly.
|
|
4066
|
-
*
|
|
4067
|
-
* Setting this to true means that after the tool is called,
|
|
4068
|
-
* an agent should stop looping.
|
|
4069
|
-
*/
|
|
4070
|
-
returnDirect?: boolean;
|
|
4071
|
-
}
|
|
4072
|
-
/**
|
|
4073
|
-
* Interface for the input parameters of the DynamicTool class.
|
|
4074
|
-
*/
|
|
4075
|
-
interface DynamicToolInput<ToolOutputT = ToolOutputType> extends BaseDynamicToolInput {
|
|
4076
|
-
func: (input: string, runManager?: CallbackManagerForToolRun, config?: ToolRunnableConfig) => Promise<ToolOutputT>;
|
|
4077
|
-
}
|
|
4078
|
-
|
|
4079
|
-
/**
|
|
4080
|
-
* Base class for Tools that accept input of any shape defined by a Zod schema.
|
|
4081
|
-
*/
|
|
4082
|
-
declare abstract class StructuredTool<SchemaT = ToolInputSchemaBase, SchemaOutputT = ToolInputSchemaOutputType<SchemaT>, SchemaInputT = ToolInputSchemaInputType<SchemaT>, ToolOutputT = ToolOutputType> extends BaseLangChain<StructuredToolCallInput<SchemaT, SchemaInputT>, ToolOutputT | ToolMessage> implements StructuredToolInterface<SchemaT, SchemaInputT, ToolOutputT> {
|
|
4083
|
-
abstract name: string;
|
|
4084
|
-
abstract description: string;
|
|
4085
|
-
abstract schema: SchemaT;
|
|
4086
|
-
/**
|
|
4087
|
-
* Whether to return the tool's output directly.
|
|
4088
|
-
*
|
|
4089
|
-
* Setting this to true means that after the tool is called,
|
|
4090
|
-
* an agent should stop looping.
|
|
4091
|
-
*/
|
|
4092
|
-
returnDirect: boolean;
|
|
4093
|
-
verboseParsingErrors: boolean;
|
|
4094
|
-
get lc_namespace(): string[];
|
|
4095
|
-
/**
|
|
4096
|
-
* The tool response format.
|
|
4097
|
-
*
|
|
4098
|
-
* If "content" then the output of the tool is interpreted as the contents of a
|
|
4099
|
-
* ToolMessage. If "content_and_artifact" then the output is expected to be a
|
|
4100
|
-
* two-tuple corresponding to the (content, artifact) of a ToolMessage.
|
|
4101
|
-
*
|
|
4102
|
-
* @default "content"
|
|
4103
|
-
*/
|
|
4104
|
-
responseFormat?: ResponseFormat;
|
|
4105
|
-
/**
|
|
4106
|
-
* Default config object for the tool runnable.
|
|
4107
|
-
*/
|
|
4108
|
-
defaultConfig?: ToolRunnableConfig;
|
|
4109
|
-
constructor(fields?: ToolParams);
|
|
4110
|
-
protected abstract _call(arg: SchemaOutputT, runManager?: CallbackManagerForToolRun, parentConfig?: ToolRunnableConfig): Promise<ToolOutputT>;
|
|
4111
|
-
/**
|
|
4112
|
-
* Invokes the tool with the provided input and configuration.
|
|
4113
|
-
* @param input The input for the tool.
|
|
4114
|
-
* @param config Optional configuration for the tool.
|
|
4115
|
-
* @returns A Promise that resolves with the tool's output.
|
|
4116
|
-
*/
|
|
4117
|
-
invoke<TInput extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(input: TInput, config?: TConfig): Promise<ToolReturnType<TInput, TConfig, ToolOutputT>>;
|
|
4118
|
-
/**
|
|
4119
|
-
* @deprecated Use .invoke() instead. Will be removed in 0.3.0.
|
|
4120
|
-
*
|
|
4121
|
-
* Calls the tool with the provided argument, configuration, and tags. It
|
|
4122
|
-
* parses the input according to the schema, handles any errors, and
|
|
4123
|
-
* manages callbacks.
|
|
4124
|
-
* @param arg The input argument for the tool.
|
|
4125
|
-
* @param configArg Optional configuration or callbacks for the tool.
|
|
4126
|
-
* @param tags Optional tags for the tool.
|
|
4127
|
-
* @returns A Promise that resolves with a string.
|
|
4128
|
-
*/
|
|
4129
|
-
call<TArg extends StructuredToolCallInput<SchemaT, SchemaInputT>, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig,
|
|
4130
|
-
/** @deprecated */
|
|
4131
|
-
tags?: string[]): Promise<ToolReturnType<TArg, TConfig, ToolOutputT>>;
|
|
4132
|
-
}
|
|
4133
|
-
/**
|
|
4134
|
-
* Base class for Tools that accept input as a string.
|
|
4135
|
-
*/
|
|
4136
|
-
declare abstract class Tool<ToolOutputT = ToolOutputType> extends StructuredTool<StringInputToolSchema, ToolInputSchemaOutputType<StringInputToolSchema>, ToolInputSchemaInputType<StringInputToolSchema>, ToolOutputT> implements ToolInterface<StringInputToolSchema, ToolInputSchemaInputType<StringInputToolSchema>, ToolOutputT> {
|
|
4137
|
-
schema: z.ZodEffects<z.ZodObject<{
|
|
4138
|
-
input: z.ZodOptional<z.ZodString>;
|
|
4139
|
-
}, "strip", z.ZodTypeAny, {
|
|
4140
|
-
input?: string | undefined;
|
|
4141
|
-
}, {
|
|
4142
|
-
input?: string | undefined;
|
|
4143
|
-
}>, string | undefined, {
|
|
4144
|
-
input?: string | undefined;
|
|
4145
|
-
}>;
|
|
4146
|
-
constructor(fields?: ToolParams);
|
|
4147
|
-
/**
|
|
4148
|
-
* @deprecated Use .invoke() instead. Will be removed in 0.3.0.
|
|
4149
|
-
*
|
|
4150
|
-
* Calls the tool with the provided argument and callbacks. It handles
|
|
4151
|
-
* string inputs specifically.
|
|
4152
|
-
* @param arg The input argument for the tool, which can be a string, undefined, or an input of the tool's schema.
|
|
4153
|
-
* @param callbacks Optional callbacks for the tool.
|
|
4154
|
-
* @returns A Promise that resolves with a string.
|
|
4155
|
-
*/
|
|
4156
|
-
call<TArg extends string | undefined | z.input<this["schema"]> | ToolCall, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, callbacks?: TConfig): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;
|
|
4157
|
-
}
|
|
4158
|
-
/**
|
|
4159
|
-
* A tool that can be created dynamically from a function, name, and description.
|
|
4160
|
-
*/
|
|
4161
|
-
declare class DynamicTool<ToolOutputT = ToolOutputType> extends Tool<ToolOutputT> {
|
|
4162
|
-
static lc_name(): string;
|
|
4163
|
-
name: string;
|
|
4164
|
-
description: string;
|
|
4165
|
-
func: DynamicToolInput<ToolOutputT>["func"];
|
|
4166
|
-
constructor(fields: DynamicToolInput<ToolOutputT>);
|
|
4167
|
-
/**
|
|
4168
|
-
* @deprecated Use .invoke() instead. Will be removed in 0.3.0.
|
|
4169
|
-
*/
|
|
4170
|
-
call<TArg extends string | undefined | z.input<this["schema"]> | ToolCall, TConfig extends ToolRunnableConfig | undefined>(arg: TArg, configArg?: TConfig): Promise<ToolReturnType<NonNullable<TArg>, TConfig, ToolOutputT>>;
|
|
4171
|
-
/** @ignore */
|
|
4172
|
-
_call(input: string, // DynamicTool's _call specifically expects a string after schema transformation
|
|
4173
|
-
runManager?: CallbackManagerForToolRun, parentConfig?: ToolRunnableConfig): Promise<ToolOutputT>;
|
|
4174
|
-
}
|
|
4175
|
-
|
|
4176
|
-
declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration & {
|
|
4177
|
-
apiKey: string;
|
|
4178
|
-
}) => DynamicTool;
|
|
4179
|
-
|
|
4180
|
-
export { executeTool };
|