langchain 0.3.27 → 0.3.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/agent.cjs +36 -3
- package/dist/agents/format_scratchpad/log.cjs +1 -2
- package/dist/agents/format_scratchpad/log_to_message.cjs +1 -2
- package/dist/agents/format_scratchpad/openai_functions.cjs +2 -3
- package/dist/agents/format_scratchpad/tool_calling.cjs +2 -3
- package/dist/agents/format_scratchpad/xml.cjs +1 -2
- package/dist/agents/initialize.cjs +2 -2
- package/dist/agents/openai_functions/index.cjs +3 -3
- package/dist/agents/openai_tools/index.cjs +2 -2
- package/dist/agents/react/index.cjs +1 -2
- package/dist/agents/structured_chat/index.cjs +6 -4
- package/dist/agents/structured_chat/index.js +5 -3
- package/dist/agents/structured_chat/prompt.d.ts +1 -1
- package/dist/agents/tool_calling/index.cjs +1 -2
- package/dist/agents/tool_calling/output_parser.cjs +2 -2
- package/dist/agents/toolkits/conversational_retrieval/openai_functions.cjs +1 -2
- package/dist/agents/toolkits/conversational_retrieval/tool.cjs +1 -2
- package/dist/agents/toolkits/json/json.cjs +2 -2
- package/dist/agents/toolkits/openapi/openapi.cjs +2 -2
- package/dist/agents/toolkits/sql/sql.cjs +2 -2
- package/dist/agents/toolkits/vectorstore/vectorstore.cjs +3 -3
- package/dist/agents/xml/index.cjs +2 -2
- package/dist/chains/api/prompts.d.ts +1 -1
- package/dist/chains/base.cjs +42 -9
- package/dist/chains/base.d.ts +2 -2
- package/dist/chains/base.js +1 -1
- package/dist/chains/combine_documents/base.cjs +2 -2
- package/dist/chains/combine_documents/reduce.cjs +2 -3
- package/dist/chains/combine_documents/stuff.cjs +1 -2
- package/dist/chains/history_aware_retriever.cjs +1 -2
- package/dist/chains/openai_functions/base.cjs +5 -6
- package/dist/chains/openai_functions/base.d.ts +3 -4
- package/dist/chains/openai_functions/base.js +4 -4
- package/dist/chains/openai_functions/extraction.cjs +6 -7
- package/dist/chains/openai_functions/extraction.d.ts +4 -4
- package/dist/chains/openai_functions/extraction.js +4 -4
- package/dist/chains/openai_functions/openapi.cjs +4 -5
- package/dist/chains/openai_functions/openapi.d.ts +1 -1
- package/dist/chains/openai_functions/openapi.js +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +7 -7
- package/dist/chains/openai_functions/structured_output.d.ts +7 -8
- package/dist/chains/openai_functions/structured_output.js +5 -5
- package/dist/chains/openai_functions/tagging.cjs +4 -5
- package/dist/chains/openai_functions/tagging.d.ts +2 -2
- package/dist/chains/openai_functions/tagging.js +2 -2
- package/dist/chains/query_constructor/index.cjs +3 -3
- package/dist/chains/query_constructor/index.d.ts +2 -2
- package/dist/chains/question_answering/load.cjs +4 -4
- package/dist/chains/retrieval.cjs +1 -2
- package/dist/chains/router/utils.cjs +1 -2
- package/dist/chains/sequential_chain.cjs +2 -1
- package/dist/chains/sequential_chain.js +2 -1
- package/dist/chains/sql_db/sql_db_chain.cjs +2 -2
- package/dist/chat_models/universal.cjs +54 -21
- package/dist/document_loaders/fs/buffer.cjs +34 -1
- package/dist/document_loaders/fs/buffer.d.ts +0 -3
- package/dist/document_loaders/fs/directory.cjs +35 -2
- package/dist/document_loaders/fs/directory.d.ts +0 -2
- package/dist/document_loaders/fs/text.cjs +34 -1
- package/dist/document_loaders/fs/text.d.ts +0 -1
- package/dist/document_transformers/openai_functions.cjs +5 -5
- package/dist/document_transformers/openai_functions.d.ts +3 -3
- package/dist/document_transformers/openai_functions.js +2 -2
- package/dist/evaluation/embedding_distance/base.cjs +3 -3
- package/dist/evaluation/loader.cjs +1 -2
- package/dist/experimental/autogpt/output_parser.cjs +2 -2
- package/dist/experimental/autogpt/prompt_generator.cjs +4 -4
- package/dist/experimental/autogpt/prompt_generator.js +3 -3
- package/dist/experimental/generative_agents/generative_agent.cjs +1 -1
- package/dist/experimental/generative_agents/generative_agent.js +1 -1
- package/dist/experimental/openai_assistant/index.cjs +8 -4
- package/dist/experimental/openai_assistant/index.d.ts +6 -6
- package/dist/experimental/openai_assistant/index.js +9 -5
- package/dist/experimental/openai_files/index.cjs +2 -2
- package/dist/experimental/openai_files/index.d.ts +6 -4
- package/dist/experimental/openai_files/index.js +2 -2
- package/dist/experimental/plan_and_execute/agent_executor.cjs +2 -2
- package/dist/hub/base.cjs +4 -5
- package/dist/hub/index.cjs +2 -2
- package/dist/hub/node.cjs +43 -10
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -1
- package/dist/load/import_map.cjs +17 -7
- package/dist/load/index.cjs +18 -9
- package/dist/output_parsers/expression_type_handlers/base.cjs +34 -1
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/router.d.ts +3 -3
- package/dist/output_parsers/structured.cjs +6 -5
- package/dist/output_parsers/structured.d.ts +9 -8
- package/dist/output_parsers/structured.js +6 -5
- package/dist/prompts/index.cjs +0 -1
- package/dist/prompts/index.d.ts +0 -1
- package/dist/prompts/index.js +1 -1
- package/dist/retrievers/hyde.cjs +2 -2
- package/dist/retrievers/parent_document.cjs +17 -7
- package/dist/smith/config.cjs +5 -6
- package/dist/smith/name_generation.cjs +1 -2
- package/dist/smith/runner_utils.cjs +1 -2
- package/dist/sql_db.cjs +35 -2
- package/dist/storage/encoder_backed.cjs +2 -2
- package/dist/storage/encoder_backed.d.ts +1 -1
- package/dist/storage/file_system.cjs +17 -7
- package/dist/storage/file_system.d.ts +1 -1
- package/dist/stores/file/node.cjs +17 -7
- package/dist/tools/convert_to_openai.cjs +5 -5
- package/dist/tools/convert_to_openai.js +4 -4
- package/dist/tools/fs.d.ts +3 -2
- package/dist/tools/render.cjs +6 -5
- package/dist/tools/render.js +5 -3
- package/dist/tools/retriever.cjs +1 -2
- package/dist/tools/webbrowser.cjs +17 -7
- package/dist/util/axios-fetch-adapter.cjs +1 -1
- package/dist/util/azure.cjs +1 -2
- package/dist/util/entrypoint_deprecation.cjs +2 -3
- package/dist/util/load.cjs +34 -1
- package/dist/util/ml-distance/distances.cjs +3 -4
- package/dist/util/ml-distance/similarities.cjs +1 -2
- package/dist/util/ml-distance-euclidean/euclidean.cjs +2 -3
- package/dist/util/openapi.cjs +17 -7
- package/dist/util/openapi.d.ts +32 -32
- package/dist/util/parse.cjs +17 -7
- package/dist/util/prompt-layer.d.ts +1 -1
- package/dist/util/set.cjs +3 -4
- package/dist/util/time.cjs +1 -2
- package/package.json +8 -9
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createOpenAIFnRunnable = createOpenAIFnRunnable;
|
|
4
|
+
exports.createStructuredOutputRunnable = createStructuredOutputRunnable;
|
|
4
5
|
const types_1 = require("@langchain/core/utils/types");
|
|
5
|
-
const
|
|
6
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
6
7
|
const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
|
|
7
8
|
/**
|
|
8
9
|
* Creates a runnable sequence that calls OpenAI functions.
|
|
@@ -67,7 +68,6 @@ function createOpenAIFnRunnable(config) {
|
|
|
67
68
|
const llmWithKwargs = llm.withConfig(llmKwargs);
|
|
68
69
|
return prompt.pipe(llmWithKwargs).pipe(outputParser);
|
|
69
70
|
}
|
|
70
|
-
exports.createOpenAIFnRunnable = createOpenAIFnRunnable;
|
|
71
71
|
/**
|
|
72
72
|
* @deprecated Prefer the `.withStructuredOutput` method on chat model classes.
|
|
73
73
|
*
|
|
@@ -125,8 +125,8 @@ exports.createOpenAIFnRunnable = createOpenAIFnRunnable;
|
|
|
125
125
|
*/
|
|
126
126
|
function createStructuredOutputRunnable(config) {
|
|
127
127
|
const { outputSchema, llm, prompt, outputParser } = config;
|
|
128
|
-
const jsonSchema = (0, types_1.
|
|
129
|
-
? (0,
|
|
128
|
+
const jsonSchema = (0, types_1.isInteropZodSchema)(outputSchema)
|
|
129
|
+
? (0, json_schema_1.toJsonSchema)(outputSchema)
|
|
130
130
|
: outputSchema;
|
|
131
131
|
const oaiFunction = {
|
|
132
132
|
name: "outputFormatter",
|
|
@@ -141,4 +141,3 @@ function createStructuredOutputRunnable(config) {
|
|
|
141
141
|
outputParser,
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
-
exports.createStructuredOutputRunnable = createStructuredOutputRunnable;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
1
|
import type { BaseOutputParser } from "@langchain/core/output_parsers";
|
|
3
2
|
import type { BasePromptTemplate } from "@langchain/core/prompts";
|
|
4
3
|
import type { Runnable, RunnableInterface } from "@langchain/core/runnables";
|
|
5
4
|
import type { BaseFunctionCallOptions, BaseLanguageModelInput, FunctionDefinition } from "@langchain/core/language_models/base";
|
|
6
|
-
import { type InputValues } from "@langchain/core/utils/types";
|
|
5
|
+
import { type InputValues, InteropZodObject } from "@langchain/core/utils/types";
|
|
7
6
|
import type { BaseMessage } from "@langchain/core/messages";
|
|
8
|
-
import { type JsonSchema7Type } from "
|
|
7
|
+
import { type JsonSchema7Type } from "@langchain/core/utils/json_schema";
|
|
9
8
|
/**
|
|
10
9
|
* Configuration params for the createOpenAIFnRunnable method.
|
|
11
10
|
*/
|
|
@@ -85,7 +84,7 @@ export type CreateStructuredOutputRunnableConfig<RunInput extends Record<string,
|
|
|
85
84
|
/**
|
|
86
85
|
* Schema to output. Must be either valid JSONSchema or a Zod schema.
|
|
87
86
|
*/
|
|
88
|
-
outputSchema:
|
|
87
|
+
outputSchema: InteropZodObject | JsonSchema7Type;
|
|
89
88
|
/**
|
|
90
89
|
* Language model to use, assumed to support the OpenAI function-calling API.
|
|
91
90
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isInteropZodSchema, } from "@langchain/core/utils/types";
|
|
2
|
+
import { toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
3
3
|
import { JsonOutputFunctionsParser } from "../../output_parsers/openai_functions.js";
|
|
4
4
|
/**
|
|
5
5
|
* Creates a runnable sequence that calls OpenAI functions.
|
|
@@ -121,8 +121,8 @@ export function createOpenAIFnRunnable(config) {
|
|
|
121
121
|
*/
|
|
122
122
|
export function createStructuredOutputRunnable(config) {
|
|
123
123
|
const { outputSchema, llm, prompt, outputParser } = config;
|
|
124
|
-
const jsonSchema =
|
|
125
|
-
?
|
|
124
|
+
const jsonSchema = isInteropZodSchema(outputSchema)
|
|
125
|
+
? toJsonSchema(outputSchema)
|
|
126
126
|
: outputSchema;
|
|
127
127
|
const oaiFunction = {
|
|
128
128
|
name: "outputFormatter",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.createExtractionChain = createExtractionChain;
|
|
4
|
+
exports.createExtractionChainFromZod = createExtractionChainFromZod;
|
|
5
5
|
const prompts_1 = require("@langchain/core/prompts");
|
|
6
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
6
7
|
const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
|
|
7
8
|
const llm_chain_js_1 = require("../llm_chain.cjs");
|
|
8
9
|
/**
|
|
@@ -57,11 +58,10 @@ function createExtractionChain(schema, llm) {
|
|
|
57
58
|
tags: ["openai_functions", "extraction"],
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
|
-
exports.createExtractionChain = createExtractionChain;
|
|
61
61
|
/**
|
|
62
62
|
* Function that creates an extraction chain from a Zod schema. It
|
|
63
|
-
* converts the Zod schema to a JSON schema using
|
|
64
|
-
*
|
|
63
|
+
* converts the Zod schema to a JSON schema using before creating
|
|
64
|
+
* the extraction chain.
|
|
65
65
|
* @param schema The Zod schema which extracted data should match
|
|
66
66
|
* @param llm Must be a ChatOpenAI or AnthropicFunctions model that supports function calling.
|
|
67
67
|
* @returns A LLMChain instance configured to return data matching the schema.
|
|
@@ -69,6 +69,5 @@ exports.createExtractionChain = createExtractionChain;
|
|
|
69
69
|
function createExtractionChainFromZod(
|
|
70
70
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
71
|
schema, llm) {
|
|
72
|
-
return createExtractionChain((0,
|
|
72
|
+
return createExtractionChain((0, json_schema_1.toJsonSchema)(schema), llm);
|
|
73
73
|
}
|
|
74
|
-
exports.createExtractionChainFromZod = createExtractionChainFromZod;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
3
2
|
import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
|
|
3
|
+
import { InteropZodObject } from "@langchain/core/utils/types";
|
|
4
4
|
import { FunctionParameters } from "../../output_parsers/openai_functions.js";
|
|
5
5
|
import { LLMChain } from "../llm_chain.js";
|
|
6
6
|
/**
|
|
@@ -13,10 +13,10 @@ import { LLMChain } from "../llm_chain.js";
|
|
|
13
13
|
export declare function createExtractionChain(schema: FunctionParameters, llm: BaseChatModel<BaseFunctionCallOptions>): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk>>;
|
|
14
14
|
/**
|
|
15
15
|
* Function that creates an extraction chain from a Zod schema. It
|
|
16
|
-
* converts the Zod schema to a JSON schema using
|
|
17
|
-
*
|
|
16
|
+
* converts the Zod schema to a JSON schema using before creating
|
|
17
|
+
* the extraction chain.
|
|
18
18
|
* @param schema The Zod schema which extracted data should match
|
|
19
19
|
* @param llm Must be a ChatOpenAI or AnthropicFunctions model that supports function calling.
|
|
20
20
|
* @returns A LLMChain instance configured to return data matching the schema.
|
|
21
21
|
*/
|
|
22
|
-
export declare function createExtractionChainFromZod(schema:
|
|
22
|
+
export declare function createExtractionChainFromZod(schema: InteropZodObject, llm: BaseChatModel<BaseFunctionCallOptions>): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
1
|
import { PromptTemplate } from "@langchain/core/prompts";
|
|
2
|
+
import { toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
3
3
|
import { JsonKeyOutputFunctionsParser, } from "../../output_parsers/openai_functions.js";
|
|
4
4
|
import { LLMChain } from "../llm_chain.js";
|
|
5
5
|
/**
|
|
@@ -56,8 +56,8 @@ export function createExtractionChain(schema, llm) {
|
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Function that creates an extraction chain from a Zod schema. It
|
|
59
|
-
* converts the Zod schema to a JSON schema using
|
|
60
|
-
*
|
|
59
|
+
* converts the Zod schema to a JSON schema using before creating
|
|
60
|
+
* the extraction chain.
|
|
61
61
|
* @param schema The Zod schema which extracted data should match
|
|
62
62
|
* @param llm Must be a ChatOpenAI or AnthropicFunctions model that supports function calling.
|
|
63
63
|
* @returns A LLMChain instance configured to return data matching the schema.
|
|
@@ -65,5 +65,5 @@ export function createExtractionChain(schema, llm) {
|
|
|
65
65
|
export function createExtractionChainFromZod(
|
|
66
66
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
67
|
schema, llm) {
|
|
68
|
-
return createExtractionChain(
|
|
68
|
+
return createExtractionChain(toJsonSchema(schema), llm);
|
|
69
69
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.convertOpenAPISchemaToJSONSchema = convertOpenAPISchemaToJSONSchema;
|
|
4
|
+
exports.convertOpenAPISpecToOpenAIFunctions = convertOpenAPISpecToOpenAIFunctions;
|
|
5
|
+
exports.createOpenAPIChain = createOpenAPIChain;
|
|
4
6
|
const openai_1 = require("@langchain/openai");
|
|
5
7
|
const prompts_1 = require("@langchain/core/prompts");
|
|
6
8
|
const openapi_js_1 = require("../../util/openapi.cjs");
|
|
@@ -158,7 +160,6 @@ function convertOpenAPISchemaToJSONSchema(schema, spec) {
|
|
|
158
160
|
type: schema.type ?? "string",
|
|
159
161
|
};
|
|
160
162
|
}
|
|
161
|
-
exports.convertOpenAPISchemaToJSONSchema = convertOpenAPISchemaToJSONSchema;
|
|
162
163
|
/**
|
|
163
164
|
* Converts an OpenAPI specification to OpenAI functions.
|
|
164
165
|
* @param spec The OpenAPI specification to convert.
|
|
@@ -302,7 +303,6 @@ function convertOpenAPISpecToOpenAIFunctions(spec) {
|
|
|
302
303
|
},
|
|
303
304
|
};
|
|
304
305
|
}
|
|
305
|
-
exports.convertOpenAPISpecToOpenAIFunctions = convertOpenAPISpecToOpenAIFunctions;
|
|
306
306
|
/**
|
|
307
307
|
* A chain for making simple API requests.
|
|
308
308
|
*/
|
|
@@ -378,7 +378,7 @@ async function createOpenAPIChain(spec, options = {}) {
|
|
|
378
378
|
if (defaultExecutionMethod === undefined) {
|
|
379
379
|
throw new Error(`Could not parse any valid operations from the provided spec.`);
|
|
380
380
|
}
|
|
381
|
-
const { llm = new openai_1.ChatOpenAI({
|
|
381
|
+
const { llm = new openai_1.ChatOpenAI({ model: "gpt-3.5-turbo-0613" }), prompt = prompts_1.ChatPromptTemplate.fromMessages([
|
|
382
382
|
prompts_1.HumanMessagePromptTemplate.fromTemplate("Use the provided API's to respond to this user query:\n\n{query}"),
|
|
383
383
|
]), requestChain = new SimpleRequestChain({
|
|
384
384
|
requestMethod: async (name, args) => defaultExecutionMethod(name, args, {
|
|
@@ -402,4 +402,3 @@ async function createOpenAPIChain(spec, options = {}) {
|
|
|
402
402
|
...rest,
|
|
403
403
|
});
|
|
404
404
|
}
|
|
405
|
-
exports.createOpenAPIChain = createOpenAPIChain;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OpenAIClient } from "@langchain/openai";
|
|
2
|
-
import { JsonSchema7Type } from "
|
|
2
|
+
import { type JsonSchema7Type } from "@langchain/core/utils/json_schema";
|
|
3
3
|
import type { OpenAPIV3_1 } from "openapi-types";
|
|
4
4
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
5
5
|
import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
|
|
@@ -373,7 +373,7 @@ export async function createOpenAPIChain(spec, options = {}) {
|
|
|
373
373
|
if (defaultExecutionMethod === undefined) {
|
|
374
374
|
throw new Error(`Could not parse any valid operations from the provided spec.`);
|
|
375
375
|
}
|
|
376
|
-
const { llm = new ChatOpenAI({
|
|
376
|
+
const { llm = new ChatOpenAI({ model: "gpt-3.5-turbo-0613" }), prompt = ChatPromptTemplate.fromMessages([
|
|
377
377
|
HumanMessagePromptTemplate.fromTemplate("Use the provided API's to respond to this user query:\n\n{query}"),
|
|
378
378
|
]), requestChain = new SimpleRequestChain({
|
|
379
379
|
requestMethod: async (name, args) => defaultExecutionMethod(name, args, {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.FunctionCallStructuredOutputParser = void 0;
|
|
4
|
+
exports.createStructuredOutputChain = createStructuredOutputChain;
|
|
5
|
+
exports.createStructuredOutputChainFromZod = createStructuredOutputChainFromZod;
|
|
5
6
|
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
6
7
|
const openai_1 = require("@langchain/openai");
|
|
7
8
|
const output_parsers_1 = require("@langchain/core/output_parsers");
|
|
9
|
+
const types_1 = require("@langchain/core/utils/types");
|
|
8
10
|
const llm_chain_js_1 = require("../llm_chain.cjs");
|
|
9
11
|
const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
|
|
10
12
|
function isJsonSchema7Type(x) {
|
|
@@ -78,12 +80,12 @@ class FunctionCallStructuredOutputParser extends output_parsers_1.BaseLLMOutputP
|
|
|
78
80
|
return value;
|
|
79
81
|
});
|
|
80
82
|
if (this.zodSchema) {
|
|
81
|
-
const zodParsedResult = this.zodSchema
|
|
83
|
+
const zodParsedResult = await (0, types_1.interopSafeParseAsync)(this.zodSchema, parsedResult);
|
|
82
84
|
if (zodParsedResult.success) {
|
|
83
85
|
return zodParsedResult.data;
|
|
84
86
|
}
|
|
85
87
|
else {
|
|
86
|
-
throw new output_parsers_1.OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.
|
|
88
|
+
throw new output_parsers_1.OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.issues)}`, initialResult);
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
else if (this.jsonSchemaValidator !== undefined) {
|
|
@@ -137,13 +139,11 @@ function createStructuredOutputChain(input) {
|
|
|
137
139
|
...rest,
|
|
138
140
|
});
|
|
139
141
|
}
|
|
140
|
-
exports.createStructuredOutputChain = createStructuredOutputChain;
|
|
141
142
|
/** @deprecated Use {@link https://api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
|
|
142
143
|
function createStructuredOutputChainFromZod(zodSchema, input) {
|
|
143
144
|
return createStructuredOutputChain({
|
|
144
145
|
...input,
|
|
145
|
-
outputSchema: (0,
|
|
146
|
+
outputSchema: (0, json_schema_1.toJsonSchema)(zodSchema),
|
|
146
147
|
zodSchema,
|
|
147
148
|
});
|
|
148
149
|
}
|
|
149
|
-
exports.createStructuredOutputChainFromZod = createStructuredOutputChainFromZod;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { JsonSchema7Type } from "zod-to-json-schema";
|
|
3
|
-
import { Validator } from "@langchain/core/utils/json_schema";
|
|
1
|
+
import { type JsonSchema7Type, Validator } from "@langchain/core/utils/json_schema";
|
|
4
2
|
import { ChatOpenAI } from "@langchain/openai";
|
|
5
3
|
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
6
4
|
import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
7
5
|
import { ChatGeneration } from "@langchain/core/outputs";
|
|
8
6
|
import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
9
7
|
import type { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
|
|
8
|
+
import { InferInteropZodOutput, InteropZodObject } from "@langchain/core/utils/types";
|
|
10
9
|
import { LLMChain, type LLMChainInput } from "../llm_chain.js";
|
|
11
10
|
import { OutputFunctionsParser } from "../../output_parsers/openai_functions.js";
|
|
12
11
|
/**
|
|
@@ -15,13 +14,13 @@ import { OutputFunctionsParser } from "../../output_parsers/openai_functions.js"
|
|
|
15
14
|
* 'outputSchema' field representing the JSON schema for the expected
|
|
16
15
|
* output.
|
|
17
16
|
*/
|
|
18
|
-
export type StructuredOutputChainInput<T extends
|
|
17
|
+
export type StructuredOutputChainInput<T extends InteropZodObject = InteropZodObject> = Omit<LLMChainInput, "outputParser" | "llm"> & {
|
|
19
18
|
outputSchema?: JsonSchema7Type;
|
|
20
19
|
prompt: BasePromptTemplate;
|
|
21
20
|
llm?: BaseChatModel<BaseFunctionCallOptions>;
|
|
22
21
|
zodSchema?: T;
|
|
23
22
|
};
|
|
24
|
-
export type FunctionCallStructuredOutputParserFields<T extends
|
|
23
|
+
export type FunctionCallStructuredOutputParserFields<T extends InteropZodObject = InteropZodObject> = {
|
|
25
24
|
jsonSchema?: JsonSchema7Type;
|
|
26
25
|
zodSchema?: T;
|
|
27
26
|
};
|
|
@@ -29,7 +28,7 @@ export type FunctionCallStructuredOutputParserFields<T extends z.AnyZodObject =
|
|
|
29
28
|
* Class that extends the BaseLLMOutputParser class. It provides
|
|
30
29
|
* functionality for parsing the structured output based on a JSON schema.
|
|
31
30
|
*/
|
|
32
|
-
export declare class FunctionCallStructuredOutputParser<T extends
|
|
31
|
+
export declare class FunctionCallStructuredOutputParser<T extends InteropZodObject> extends BaseLLMOutputParser<InferInteropZodOutput<T>> {
|
|
33
32
|
lc_namespace: string[];
|
|
34
33
|
protected functionOutputParser: OutputFunctionsParser;
|
|
35
34
|
protected jsonSchemaValidator?: Validator;
|
|
@@ -55,6 +54,6 @@ export declare class FunctionCallStructuredOutputParser<T extends z.AnyZodObject
|
|
|
55
54
|
* as well as an additional required "outputSchema" JSON Schema object.
|
|
56
55
|
* @returns OpenAPIChain
|
|
57
56
|
*/
|
|
58
|
-
export declare function createStructuredOutputChain<T extends
|
|
57
|
+
export declare function createStructuredOutputChain<T extends InteropZodObject = InteropZodObject>(input: StructuredOutputChainInput<T>): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
|
|
59
58
|
/** @deprecated Use {@link https://api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
|
|
60
|
-
export declare function createStructuredOutputChainFromZod<T extends
|
|
59
|
+
export declare function createStructuredOutputChainFromZod<T extends InteropZodObject>(zodSchema: T, input: Omit<StructuredOutputChainInput<T>, "outputSchema">): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Validator } from "@langchain/core/utils/json_schema";
|
|
1
|
+
import { Validator, toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
3
2
|
import { ChatOpenAI } from "@langchain/openai";
|
|
4
3
|
import { BaseLLMOutputParser, OutputParserException, } from "@langchain/core/output_parsers";
|
|
4
|
+
import { interopSafeParseAsync, } from "@langchain/core/utils/types";
|
|
5
5
|
import { LLMChain } from "../llm_chain.js";
|
|
6
6
|
import { OutputFunctionsParser } from "../../output_parsers/openai_functions.js";
|
|
7
7
|
function isJsonSchema7Type(x) {
|
|
@@ -75,12 +75,12 @@ export class FunctionCallStructuredOutputParser extends BaseLLMOutputParser {
|
|
|
75
75
|
return value;
|
|
76
76
|
});
|
|
77
77
|
if (this.zodSchema) {
|
|
78
|
-
const zodParsedResult = this.zodSchema
|
|
78
|
+
const zodParsedResult = await interopSafeParseAsync(this.zodSchema, parsedResult);
|
|
79
79
|
if (zodParsedResult.success) {
|
|
80
80
|
return zodParsedResult.data;
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
|
-
throw new OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.
|
|
83
|
+
throw new OutputParserException(`Failed to parse. Text: "${initialResult}". Error: ${JSON.stringify(zodParsedResult.error.issues)}`, initialResult);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
else if (this.jsonSchemaValidator !== undefined) {
|
|
@@ -137,7 +137,7 @@ export function createStructuredOutputChain(input) {
|
|
|
137
137
|
export function createStructuredOutputChainFromZod(zodSchema, input) {
|
|
138
138
|
return createStructuredOutputChain({
|
|
139
139
|
...input,
|
|
140
|
-
outputSchema:
|
|
140
|
+
outputSchema: toJsonSchema(zodSchema),
|
|
141
141
|
zodSchema,
|
|
142
142
|
});
|
|
143
143
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.createTaggingChain = createTaggingChain;
|
|
4
|
+
exports.createTaggingChainFromZod = createTaggingChainFromZod;
|
|
5
5
|
const prompts_1 = require("@langchain/core/prompts");
|
|
6
|
+
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
6
7
|
const openai_functions_js_1 = require("../../output_parsers/openai_functions.cjs");
|
|
7
8
|
const llm_chain_js_1 = require("../llm_chain.cjs");
|
|
8
9
|
/**
|
|
@@ -51,7 +52,6 @@ function createTaggingChain(schema, llm, options = {}) {
|
|
|
51
52
|
...rest,
|
|
52
53
|
});
|
|
53
54
|
}
|
|
54
|
-
exports.createTaggingChain = createTaggingChain;
|
|
55
55
|
/**
|
|
56
56
|
* Function that creates a tagging chain from a Zod schema. It converts
|
|
57
57
|
* the Zod schema to a JSON schema using the zodToJsonSchema function and
|
|
@@ -68,6 +68,5 @@ exports.createTaggingChain = createTaggingChain;
|
|
|
68
68
|
function createTaggingChainFromZod(
|
|
69
69
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
70
|
schema, llm, options) {
|
|
71
|
-
return createTaggingChain((0,
|
|
71
|
+
return createTaggingChain((0, json_schema_1.toJsonSchema)(schema), llm, options);
|
|
72
72
|
}
|
|
73
|
-
exports.createTaggingChainFromZod = createTaggingChainFromZod;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
3
2
|
import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
|
|
4
3
|
import { PromptTemplate } from "@langchain/core/prompts";
|
|
4
|
+
import { InteropZodObject } from "@langchain/core/utils/types";
|
|
5
5
|
import { FunctionParameters } from "../../output_parsers/openai_functions.js";
|
|
6
6
|
import { LLMChain, LLMChainInput } from "../llm_chain.js";
|
|
7
7
|
/**
|
|
@@ -37,4 +37,4 @@ export declare function createTaggingChain(schema: FunctionParameters, llm: Base
|
|
|
37
37
|
* Switch to expression language: https://js.langchain.com/docs/expression_language/
|
|
38
38
|
* Will be removed in 0.2.0
|
|
39
39
|
*/
|
|
40
|
-
export declare function createTaggingChainFromZod(schema:
|
|
40
|
+
export declare function createTaggingChainFromZod(schema: InteropZodObject, llm: BaseChatModel<BaseFunctionCallOptions>, options?: TaggingChainOptions): LLMChain<object, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").AIMessageChunk>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
1
|
import { PromptTemplate } from "@langchain/core/prompts";
|
|
2
|
+
import { toJsonSchema, } from "@langchain/core/utils/json_schema";
|
|
3
3
|
import { JsonOutputFunctionsParser, } from "../../output_parsers/openai_functions.js";
|
|
4
4
|
import { LLMChain } from "../llm_chain.js";
|
|
5
5
|
/**
|
|
@@ -64,5 +64,5 @@ export function createTaggingChain(schema, llm, options = {}) {
|
|
|
64
64
|
export function createTaggingChainFromZod(
|
|
65
65
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
66
|
schema, llm, options) {
|
|
67
|
-
return createTaggingChain(
|
|
67
|
+
return createTaggingChain(toJsonSchema(schema), llm, options);
|
|
68
68
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.StructuredQueryOutputParser = exports.EXAMPLE_PROMPT = exports.DEFAULT_SUFFIX = exports.DEFAULT_SCHEMA = exports.DEFAULT_PREFIX = exports.DEFAULT_EXAMPLES = exports.QueryTransformer = exports.AttributeInfo = void 0;
|
|
4
|
+
exports.formatAttributeInfo = formatAttributeInfo;
|
|
5
|
+
exports.loadQueryConstructorRunnable = loadQueryConstructorRunnable;
|
|
4
6
|
const zod_1 = require("zod");
|
|
5
7
|
const prompts_1 = require("@langchain/core/prompts");
|
|
6
8
|
const parser_js_1 = require("./parser.cjs");
|
|
@@ -118,7 +120,6 @@ function formatAttributeInfo(info) {
|
|
|
118
120
|
.replaceAll("{", "{{")
|
|
119
121
|
.replaceAll("}", "}}");
|
|
120
122
|
}
|
|
121
|
-
exports.formatAttributeInfo = formatAttributeInfo;
|
|
122
123
|
const defaultExample = prompt_js_1.DEFAULT_EXAMPLES.map((EXAMPLE) => EXAMPLE);
|
|
123
124
|
function _getPrompt(documentContents, attributeInfo, allowedComparators, allowedOperators, examples = defaultExample) {
|
|
124
125
|
const myAllowedComparators = allowedComparators ?? Object.values(ir_js_1.Comparators);
|
|
@@ -151,4 +152,3 @@ function loadQueryConstructorRunnable(opts) {
|
|
|
151
152
|
const outputParser = StructuredQueryOutputParser.fromComponents(opts.allowedComparators, opts.allowedOperators);
|
|
152
153
|
return prompt.pipe(opts.llm).pipe(outputParser);
|
|
153
154
|
}
|
|
154
|
-
exports.loadQueryConstructorRunnable = loadQueryConstructorRunnable;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base";
|
|
3
|
-
import { InputValues } from "@langchain/core/utils/types";
|
|
3
|
+
import { InferInteropZodOutput, InputValues } from "@langchain/core/utils/types";
|
|
4
4
|
import { QueryTransformer, TraverseType } from "./parser.js";
|
|
5
5
|
import { Comparator, Operator, StructuredQuery } from "./ir.js";
|
|
6
6
|
import { DEFAULT_EXAMPLES, DEFAULT_PREFIX, DEFAULT_SCHEMA, DEFAULT_SUFFIX, EXAMPLE_PROMPT } from "./prompt.js";
|
|
@@ -45,7 +45,7 @@ export declare class StructuredQueryOutputParser extends AsymmetricStructuredOut
|
|
|
45
45
|
* @param filter The filter condition.
|
|
46
46
|
* @returns A Promise that resolves to a StructuredQuery instance.
|
|
47
47
|
*/
|
|
48
|
-
outputProcessor({ query, filter, }:
|
|
48
|
+
outputProcessor({ query, filter, }: InferInteropZodOutput<typeof queryInputSchema>): Promise<StructuredQuery>;
|
|
49
49
|
/**
|
|
50
50
|
* Creates a new StructuredQueryOutputParser instance from the provided
|
|
51
51
|
* components.
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.loadQAChain = void 0;
|
|
4
|
+
exports.loadQAStuffChain = loadQAStuffChain;
|
|
5
|
+
exports.loadQAMapReduceChain = loadQAMapReduceChain;
|
|
6
|
+
exports.loadQARefineChain = loadQARefineChain;
|
|
4
7
|
const llm_chain_js_1 = require("../llm_chain.cjs");
|
|
5
8
|
const combine_docs_chain_js_1 = require("../combine_docs_chain.cjs");
|
|
6
9
|
const stuff_prompts_js_1 = require("./stuff_prompts.cjs");
|
|
@@ -33,7 +36,6 @@ function loadQAStuffChain(llm, params = {}) {
|
|
|
33
36
|
const chain = new combine_docs_chain_js_1.StuffDocumentsChain({ llmChain, verbose });
|
|
34
37
|
return chain;
|
|
35
38
|
}
|
|
36
|
-
exports.loadQAStuffChain = loadQAStuffChain;
|
|
37
39
|
/**
|
|
38
40
|
* Loads a MapReduceQAChain based on the provided parameters. It takes an
|
|
39
41
|
* LLM instance and MapReduceQAChainParams as parameters.
|
|
@@ -62,7 +64,6 @@ function loadQAMapReduceChain(llm, params = {}) {
|
|
|
62
64
|
});
|
|
63
65
|
return chain;
|
|
64
66
|
}
|
|
65
|
-
exports.loadQAMapReduceChain = loadQAMapReduceChain;
|
|
66
67
|
/**
|
|
67
68
|
* Loads a RefineQAChain based on the provided parameters. It takes an LLM
|
|
68
69
|
* instance and RefineQAChainParams as parameters.
|
|
@@ -85,4 +86,3 @@ function loadQARefineChain(llm, params = {}) {
|
|
|
85
86
|
});
|
|
86
87
|
return chain;
|
|
87
88
|
}
|
|
88
|
-
exports.loadQARefineChain = loadQARefineChain;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createRetrievalChain =
|
|
3
|
+
exports.createRetrievalChain = createRetrievalChain;
|
|
4
4
|
const runnables_1 = require("@langchain/core/runnables");
|
|
5
5
|
function isBaseRetriever(x) {
|
|
6
6
|
return (!!x &&
|
|
@@ -57,4 +57,3 @@ async function createRetrievalChain({ retriever, combineDocsChain, }) {
|
|
|
57
57
|
]).withConfig({ runName: "retrieval_chain" });
|
|
58
58
|
return retrievalChain;
|
|
59
59
|
}
|
|
60
|
-
exports.createRetrievalChain = createRetrievalChain;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.zipEntries =
|
|
3
|
+
exports.zipEntries = zipEntries;
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
5
|
function zipEntries(...arrays) {
|
|
6
6
|
// Check for empty input
|
|
@@ -31,4 +31,3 @@ function zipEntries(...arrays) {
|
|
|
31
31
|
}
|
|
32
32
|
return zipped;
|
|
33
33
|
}
|
|
34
|
-
exports.zipEntries = zipEntries;
|
|
@@ -275,7 +275,8 @@ class SimpleSequentialChain extends base_js_1.BaseChain {
|
|
|
275
275
|
/** @ignore */
|
|
276
276
|
_validateChains() {
|
|
277
277
|
for (const chain of this.chains) {
|
|
278
|
-
if (chain.inputKeys.filter((k) => !chain.memory?.memoryKeys.includes(k)
|
|
278
|
+
if (chain.inputKeys.filter((k) => !chain.memory?.memoryKeys.includes(k))
|
|
279
|
+
.length !== 1) {
|
|
279
280
|
throw new Error(`Chains used in SimpleSequentialChain should all have one input, got ${chain.inputKeys.length} for ${chain._chainType()}.`);
|
|
280
281
|
}
|
|
281
282
|
if (chain.outputKeys.length !== 1) {
|
|
@@ -271,7 +271,8 @@ export class SimpleSequentialChain extends BaseChain {
|
|
|
271
271
|
/** @ignore */
|
|
272
272
|
_validateChains() {
|
|
273
273
|
for (const chain of this.chains) {
|
|
274
|
-
if (chain.inputKeys.filter((k) => !chain.memory?.memoryKeys.includes(k)
|
|
274
|
+
if (chain.inputKeys.filter((k) => !chain.memory?.memoryKeys.includes(k))
|
|
275
|
+
.length !== 1) {
|
|
275
276
|
throw new Error(`Chains used in SimpleSequentialChain should all have one input, got ${chain.inputKeys.length} for ${chain._chainType()}.`);
|
|
276
277
|
}
|
|
277
278
|
if (chain.outputKeys.length !== 1) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SqlDatabaseChain = void 0;
|
|
4
|
+
exports.createSqlQueryChain = createSqlQueryChain;
|
|
4
5
|
const base_1 = require("@langchain/core/language_models/base");
|
|
5
6
|
const runnables_1 = require("@langchain/core/runnables");
|
|
6
7
|
const output_parsers_1 = require("@langchain/core/output_parsers");
|
|
@@ -267,4 +268,3 @@ async function createSqlQueryChain({ llm, db, prompt, k = 5, dialect, }) {
|
|
|
267
268
|
strip,
|
|
268
269
|
]);
|
|
269
270
|
}
|
|
270
|
-
exports.createSqlQueryChain = createSqlQueryChain;
|