@langchain/core 0.1.40 → 0.1.42

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.
@@ -106,6 +106,13 @@ export interface BaseFunctionCallOptions extends BaseLanguageModelCallOptions {
106
106
  functions?: FunctionDefinition[];
107
107
  }
108
108
  export type BaseLanguageModelInput = BasePromptValueInterface | string | BaseMessageLike[];
109
+ export type StructuredOutputType = z.infer<z.ZodObject<any, any, any, any>>;
110
+ export type StructuredOutputMethodParams<RunOutput extends Record<string, any> = Record<string, any>, IncludeRaw extends boolean = false> = {
111
+ schema: z.ZodType<RunOutput> | Record<string, any>;
112
+ name?: string;
113
+ method?: "functionCalling" | "jsonMode";
114
+ includeRaw?: IncludeRaw;
115
+ };
109
116
  export interface BaseLanguageModelInterface<RunOutput = any, CallOptions extends BaseLanguageModelCallOptions = BaseLanguageModelCallOptions> extends RunnableInterface<BaseLanguageModelInput, RunOutput, CallOptions> {
110
117
  get callKeys(): string[];
111
118
  generatePrompt(promptValues: BasePromptValueInterface[], options?: string[] | CallOptions, callbacks?: Callbacks): Promise<LLMResult>;
@@ -177,26 +184,16 @@ export declare abstract class BaseLanguageModel<RunOutput = any, CallOptions ext
177
184
  * Load an LLM from a json-like object describing it.
178
185
  */
179
186
  static deserialize(_data: SerializedLLM): Promise<BaseLanguageModel>;
180
- withStructuredOutput?<RunInput = BaseLanguageModelInput, RunOutput extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any>>({ schema, name, method, includeRaw, }: {
181
- schema: z.ZodEffects<RunOutput> | Record<string, any>;
182
- name: string;
183
- method?: "functionCalling" | "jsonMode";
184
- includeRaw: true;
185
- }): Runnable<RunInput, {
187
+ withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>({ schema, name, method, includeRaw, }: StructuredOutputMethodParams<RunOutput, false>): Runnable<BaseLanguageModelInput, RunOutput>;
188
+ withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>({ schema, name, method, includeRaw, }: StructuredOutputMethodParams<RunOutput, true>): Runnable<BaseLanguageModelInput, {
186
189
  raw: BaseMessage;
187
190
  parsed: RunOutput;
188
191
  }>;
189
- withStructuredOutput?<RunInput = BaseLanguageModelInput, RunOutput extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any>>({ schema, name, method, includeRaw, }: {
190
- schema: z.ZodEffects<RunOutput> | Record<string, any>;
191
- name: string;
192
- method?: "functionCalling" | "jsonMode";
193
- includeRaw?: false;
194
- }): Runnable<RunInput, RunOutput>;
195
192
  /**
196
193
  * Model wrapper that returns outputs formatted to match the given schema.
197
194
  *
198
195
  * @template {BaseLanguageModelInput} RunInput The input type for the Runnable, expected to be the same input for the LLM.
199
- * @template {z.ZodObject<any, any, any, any>} RunOutput The output type for the Runnable, expected to be a Zod schema object for structured output validation.
196
+ * @template {Record<string, any>} RunOutput The output type for the Runnable, expected to be a Zod schema object for structured output validation.
200
197
  *
201
198
  * @param {z.ZodEffects<RunOutput>} schema The schema for the structured output. Either as a Zod schema or a valid JSON schema object.
202
199
  * @param {string} name The name of the function to call.
@@ -204,7 +201,7 @@ export declare abstract class BaseLanguageModel<RunOutput = any, CallOptions ext
204
201
  * @param {boolean | undefined} [includeRaw=false] Whether to include the raw output in the result. Defaults to false.
205
202
  * @returns {Runnable<RunInput, RunOutput> | Runnable<RunInput, { raw: BaseMessage; parsed: RunOutput }>} A new runnable that calls the LLM with structured output.
206
203
  */
207
- withStructuredOutput?<RunInput extends BaseLanguageModelInput = BaseLanguageModelInput, RunOutput extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any>>({ schema, name,
204
+ withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>({ schema, name,
208
205
  /**
209
206
  * @default functionCalling
210
207
  */
@@ -212,12 +209,7 @@ export declare abstract class BaseLanguageModel<RunOutput = any, CallOptions ext
212
209
  /**
213
210
  * @default false
214
211
  */
215
- includeRaw, }: {
216
- schema: z.ZodEffects<RunOutput> | Record<string, any>;
217
- name: string;
218
- method?: "functionCalling" | "jsonMode";
219
- includeRaw?: boolean;
220
- }): Runnable<RunInput, RunOutput> | Runnable<RunInput, {
212
+ includeRaw, }: StructuredOutputMethodParams<RunOutput>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {
221
213
  raw: BaseMessage;
222
214
  parsed: RunOutput;
223
215
  }>;
@@ -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;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.betaWarning = void 0;
4
+ /**
5
+ * Util function for logging a warning when a method is called.
6
+ * @param {string} func The name of the function that is in beta.
7
+ */
8
+ function betaWarning(func) {
9
+ console.warn(`The function '${func}' is in beta. It is actively being worked on, so the API may change.`);
10
+ }
11
+ exports.betaWarning = betaWarning;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Util function for logging a warning when a method is called.
3
+ * @param {string} func The name of the function that is in beta.
4
+ */
5
+ export declare function betaWarning(func: string): void;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Util function for logging a warning when a method is called.
3
+ * @param {string} func The name of the function that is in beta.
4
+ */
5
+ export function betaWarning(func) {
6
+ console.warn(`The function '${func}' is in beta. It is actively being worked on, so the API may change.`);
7
+ }
@@ -311,6 +311,12 @@ class FakeListChatModel extends chat_models_js_1.BaseChatModel {
311
311
  this.i = 0;
312
312
  }
313
313
  }
314
+ withStructuredOutput(_params) {
315
+ return base_js_2.RunnableLambda.from(async (input) => {
316
+ const message = await this.invoke(input);
317
+ return JSON.parse(message.content);
318
+ });
319
+ }
314
320
  }
315
321
  exports.FakeListChatModel = FakeListChatModel;
316
322
  class FakeChatMessageHistory extends chat_history_js_1.BaseChatMessageHistory {
@@ -12,6 +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
16
  /**
16
17
  * Parser for comma-separated values. It splits the input text by commas
17
18
  * and trims the resulting values.
@@ -113,6 +114,11 @@ export declare class FakeListChatModel extends BaseChatModel {
113
114
  _createResponseChunk(text: string): ChatGenerationChunk;
114
115
  _currentResponse(): string;
115
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, {
119
+ raw: BaseMessage;
120
+ parsed: RunOutput;
121
+ }>;
116
122
  }
117
123
  export declare class FakeChatMessageHistory extends BaseChatMessageHistory {
118
124
  lc_namespace: string[];
@@ -6,7 +6,7 @@ import { AIMessage, AIMessageChunk, HumanMessage, } from "../../messages/index.j
6
6
  import { BaseOutputParser } from "../../output_parsers/base.js";
7
7
  import { ChatGenerationChunk, } from "../../outputs.js";
8
8
  import { BaseRetriever } from "../../retrievers.js";
9
- import { Runnable } from "../../runnables/base.js";
9
+ import { Runnable, RunnableLambda } from "../../runnables/base.js";
10
10
  import { StructuredTool } from "../../tools.js";
11
11
  import { BaseTracer } from "../../tracers/base.js";
12
12
  import { Embeddings } from "../../embeddings.js";
@@ -302,6 +302,12 @@ export class FakeListChatModel extends BaseChatModel {
302
302
  this.i = 0;
303
303
  }
304
304
  }
305
+ withStructuredOutput(_params) {
306
+ return RunnableLambda.from(async (input) => {
307
+ const message = await this.invoke(input);
308
+ return JSON.parse(message.content);
309
+ });
310
+ }
305
311
  }
306
312
  export class FakeChatMessageHistory extends BaseChatMessageHistory {
307
313
  constructor() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.1.40",
3
+ "version": "0.1.42",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {
@@ -524,6 +524,15 @@
524
524
  "import": "./utils/types.js",
525
525
  "require": "./utils/types.cjs"
526
526
  },
527
+ "./utils/beta_warning": {
528
+ "types": {
529
+ "import": "./utils/beta_warning.d.ts",
530
+ "require": "./utils/beta_warning.d.cts",
531
+ "default": "./utils/beta_warning.d.ts"
532
+ },
533
+ "import": "./utils/beta_warning.js",
534
+ "require": "./utils/beta_warning.cjs"
535
+ },
527
536
  "./vectorstores": {
528
537
  "types": {
529
538
  "import": "./vectorstores.d.ts",
@@ -729,6 +738,10 @@
729
738
  "utils/types.js",
730
739
  "utils/types.d.ts",
731
740
  "utils/types.d.cts",
741
+ "utils/beta_warning.cjs",
742
+ "utils/beta_warning.js",
743
+ "utils/beta_warning.d.ts",
744
+ "utils/beta_warning.d.cts",
732
745
  "vectorstores.cjs",
733
746
  "vectorstores.js",
734
747
  "vectorstores.d.ts",
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/utils/beta_warning.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/utils/beta_warning.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/utils/beta_warning.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/utils/beta_warning.js'