@langchain/core 0.1.41 → 0.1.43
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.
|
@@ -107,7 +107,14 @@ export interface BaseFunctionCallOptions extends BaseLanguageModelCallOptions {
|
|
|
107
107
|
}
|
|
108
108
|
export type BaseLanguageModelInput = BasePromptValueInterface | string | BaseMessageLike[];
|
|
109
109
|
export type StructuredOutputType = z.infer<z.ZodObject<any, any, any, any>>;
|
|
110
|
-
export type
|
|
110
|
+
export type StructuredOutputMethodOptions<IncludeRaw extends boolean = false> = {
|
|
111
|
+
name?: string;
|
|
112
|
+
method?: "functionCalling" | "jsonMode";
|
|
113
|
+
includeRaw?: IncludeRaw;
|
|
114
|
+
};
|
|
115
|
+
/** @deprecated Use StructuredOutputMethodOptions instead */
|
|
116
|
+
export type StructuredOutputMethodParams<RunOutput, IncludeRaw extends boolean = false> = {
|
|
117
|
+
/** @deprecated Pass schema in as the first argument */
|
|
111
118
|
schema: z.ZodType<RunOutput> | Record<string, any>;
|
|
112
119
|
name?: string;
|
|
113
120
|
method?: "functionCalling" | "jsonMode";
|
|
@@ -184,8 +191,8 @@ export declare abstract class BaseLanguageModel<RunOutput = any, CallOptions ext
|
|
|
184
191
|
* Load an LLM from a json-like object describing it.
|
|
185
192
|
*/
|
|
186
193
|
static deserialize(_data: SerializedLLM): Promise<BaseLanguageModel>;
|
|
187
|
-
withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>(
|
|
188
|
-
withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>(
|
|
194
|
+
withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>(schema: z.ZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
195
|
+
withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>(schema: z.ZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
189
196
|
raw: BaseMessage;
|
|
190
197
|
parsed: RunOutput;
|
|
191
198
|
}>;
|
|
@@ -201,15 +208,7 @@ export declare abstract class BaseLanguageModel<RunOutput = any, CallOptions ext
|
|
|
201
208
|
* @param {boolean | undefined} [includeRaw=false] Whether to include the raw output in the result. Defaults to false.
|
|
202
209
|
* @returns {Runnable<RunInput, RunOutput> | Runnable<RunInput, { raw: BaseMessage; parsed: RunOutput }>} A new runnable that calls the LLM with structured output.
|
|
203
210
|
*/
|
|
204
|
-
withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>(
|
|
205
|
-
/**
|
|
206
|
-
* @default functionCalling
|
|
207
|
-
*/
|
|
208
|
-
method,
|
|
209
|
-
/**
|
|
210
|
-
* @default false
|
|
211
|
-
*/
|
|
212
|
-
includeRaw, }: StructuredOutputMethodParams<RunOutput>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
211
|
+
withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>(schema: z.ZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
|
|
213
212
|
raw: BaseMessage;
|
|
214
213
|
parsed: RunOutput;
|
|
215
214
|
}>;
|
|
@@ -15,14 +15,11 @@ const STATUS_NO_RETRY = [
|
|
|
15
15
|
405,
|
|
16
16
|
406,
|
|
17
17
|
407,
|
|
18
|
-
408,
|
|
19
18
|
409, // Conflict
|
|
20
19
|
];
|
|
21
20
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
21
|
const defaultFailedAttemptHandler = (error) => {
|
|
23
22
|
if (error.message.startsWith("Cancel") ||
|
|
24
|
-
error.message.startsWith("TimeoutError") ||
|
|
25
|
-
error.name === "TimeoutError" ||
|
|
26
23
|
error.message.startsWith("AbortError") ||
|
|
27
24
|
error.name === "AbortError") {
|
|
28
25
|
throw error;
|
|
@@ -9,14 +9,11 @@ const STATUS_NO_RETRY = [
|
|
|
9
9
|
405,
|
|
10
10
|
406,
|
|
11
11
|
407,
|
|
12
|
-
408,
|
|
13
12
|
409, // Conflict
|
|
14
13
|
];
|
|
15
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
15
|
const defaultFailedAttemptHandler = (error) => {
|
|
17
16
|
if (error.message.startsWith("Cancel") ||
|
|
18
|
-
error.message.startsWith("TimeoutError") ||
|
|
19
|
-
error.name === "TimeoutError" ||
|
|
20
17
|
error.message.startsWith("AbortError") ||
|
|
21
18
|
error.name === "AbortError") {
|
|
22
19
|
throw error;
|
|
@@ -311,7 +311,7 @@ class FakeListChatModel extends chat_models_js_1.BaseChatModel {
|
|
|
311
311
|
this.i = 0;
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
|
-
withStructuredOutput(_params) {
|
|
314
|
+
withStructuredOutput(_params, _config) {
|
|
315
315
|
return base_js_2.RunnableLambda.from(async (input) => {
|
|
316
316
|
const message = await this.invoke(input);
|
|
317
317
|
return JSON.parse(message.content);
|
|
@@ -12,7 +12,7 @@ import { Runnable } from "../../runnables/base.js";
|
|
|
12
12
|
import { StructuredTool, ToolParams } from "../../tools.js";
|
|
13
13
|
import { BaseTracer, Run } from "../../tracers/base.js";
|
|
14
14
|
import { Embeddings, EmbeddingsParams } from "../../embeddings.js";
|
|
15
|
-
import { StructuredOutputMethodParams, BaseLanguageModelInput } from "../../language_models/base.js";
|
|
15
|
+
import { StructuredOutputMethodParams, BaseLanguageModelInput, StructuredOutputMethodOptions } from "../../language_models/base.js";
|
|
16
16
|
/**
|
|
17
17
|
* Parser for comma-separated values. It splits the input text by commas
|
|
18
18
|
* and trims the resulting values.
|
|
@@ -114,8 +114,8 @@ export declare class FakeListChatModel extends BaseChatModel {
|
|
|
114
114
|
_createResponseChunk(text: string): ChatGenerationChunk;
|
|
115
115
|
_currentResponse(): string;
|
|
116
116
|
_incrementResponse(): void;
|
|
117
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
118
|
-
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true>): Runnable<BaseLanguageModelInput, {
|
|
117
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false> | z.ZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
|
|
118
|
+
withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true> | z.ZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
|
|
119
119
|
raw: BaseMessage;
|
|
120
120
|
parsed: RunOutput;
|
|
121
121
|
}>;
|
|
@@ -302,7 +302,7 @@ export class FakeListChatModel extends BaseChatModel {
|
|
|
302
302
|
this.i = 0;
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
|
-
withStructuredOutput(_params) {
|
|
305
|
+
withStructuredOutput(_params, _config) {
|
|
306
306
|
return RunnableLambda.from(async (input) => {
|
|
307
307
|
const message = await this.invoke(input);
|
|
308
308
|
return JSON.parse(message.content);
|