@langchain/core 0.1.34-rc.0 → 0.1.35
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/language_models/base.cjs +16 -0
- package/dist/language_models/base.d.ts +16 -0
- package/dist/language_models/base.js +16 -0
- package/dist/output_parsers/openai_tools/index.cjs +17 -0
- package/dist/output_parsers/openai_tools/index.d.ts +1 -0
- package/dist/output_parsers/openai_tools/index.js +1 -0
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +144 -0
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +55 -0
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.js +139 -0
- package/output_parsers/openai_tools.cjs +1 -0
- package/output_parsers/openai_tools.d.cts +1 -0
- package/output_parsers/openai_tools.d.ts +1 -0
- package/output_parsers/openai_tools.js +1 -0
- package/package.json +14 -1
|
@@ -253,5 +253,21 @@ class BaseLanguageModel extends BaseLangChain {
|
|
|
253
253
|
static async deserialize(_data) {
|
|
254
254
|
throw new Error("Use .toJSON() instead");
|
|
255
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Return a new runnable which calls an LLM with structured output.
|
|
258
|
+
* Only available for LLMs that support structured output.
|
|
259
|
+
*
|
|
260
|
+
* @template {any} RunInput The input type for the Runnable.
|
|
261
|
+
* @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.
|
|
262
|
+
*
|
|
263
|
+
* @param {z.ZodEffects<RunOutput> | Record<string, any>} schema The schema for the structured output. Either as a ZOD class or a valid JSON schema object.
|
|
264
|
+
* @param {string} name The name of the function to call.
|
|
265
|
+
* @returns {Runnable<RunInput, RunOutput>} A new runnable that calls the LLM with structured output.
|
|
266
|
+
*/
|
|
267
|
+
withStructuredOutput(
|
|
268
|
+
// @ts-expect-error Var is unused in this base method implementation.
|
|
269
|
+
{ schema, name, }) {
|
|
270
|
+
throw new Error("Method not implemented.");
|
|
271
|
+
}
|
|
256
272
|
}
|
|
257
273
|
exports.BaseLanguageModel = BaseLanguageModel;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TiktokenModel } from "js-tiktoken/lite";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import { type BaseCache } from "../caches.js";
|
|
3
4
|
import { type BasePromptValueInterface } from "../prompt_values.js";
|
|
4
5
|
import { type BaseMessage, type BaseMessageLike, type MessageContent } from "../messages/index.js";
|
|
@@ -176,6 +177,21 @@ export declare abstract class BaseLanguageModel<RunOutput = any, CallOptions ext
|
|
|
176
177
|
* Load an LLM from a json-like object describing it.
|
|
177
178
|
*/
|
|
178
179
|
static deserialize(_data: SerializedLLM): Promise<BaseLanguageModel>;
|
|
180
|
+
/**
|
|
181
|
+
* Return a new runnable which calls an LLM with structured output.
|
|
182
|
+
* Only available for LLMs that support structured output.
|
|
183
|
+
*
|
|
184
|
+
* @template {any} RunInput The input type for the Runnable.
|
|
185
|
+
* @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.
|
|
186
|
+
*
|
|
187
|
+
* @param {z.ZodEffects<RunOutput> | Record<string, any>} schema The schema for the structured output. Either as a ZOD class or a valid JSON schema object.
|
|
188
|
+
* @param {string} name The name of the function to call.
|
|
189
|
+
* @returns {Runnable<RunInput, RunOutput>} A new runnable that calls the LLM with structured output.
|
|
190
|
+
*/
|
|
191
|
+
withStructuredOutput<RunInput = any, RunOutput extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any>>({ schema, name, }: {
|
|
192
|
+
schema: z.ZodEffects<RunOutput> | Record<string, any>;
|
|
193
|
+
name: string;
|
|
194
|
+
}): Runnable<RunInput, RunOutput>;
|
|
179
195
|
}
|
|
180
196
|
/**
|
|
181
197
|
* Shared interface for token usage
|
|
@@ -245,4 +245,20 @@ export class BaseLanguageModel extends BaseLangChain {
|
|
|
245
245
|
static async deserialize(_data) {
|
|
246
246
|
throw new Error("Use .toJSON() instead");
|
|
247
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Return a new runnable which calls an LLM with structured output.
|
|
250
|
+
* Only available for LLMs that support structured output.
|
|
251
|
+
*
|
|
252
|
+
* @template {any} RunInput The input type for the Runnable.
|
|
253
|
+
* @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.
|
|
254
|
+
*
|
|
255
|
+
* @param {z.ZodEffects<RunOutput> | Record<string, any>} schema The schema for the structured output. Either as a ZOD class or a valid JSON schema object.
|
|
256
|
+
* @param {string} name The name of the function to call.
|
|
257
|
+
* @returns {Runnable<RunInput, RunOutput>} A new runnable that calls the LLM with structured output.
|
|
258
|
+
*/
|
|
259
|
+
withStructuredOutput(
|
|
260
|
+
// @ts-expect-error Var is unused in this base method implementation.
|
|
261
|
+
{ schema, name, }) {
|
|
262
|
+
throw new Error("Method not implemented.");
|
|
263
|
+
}
|
|
248
264
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./json_output_tools_parsers.cjs"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./json_output_tools_parsers.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./json_output_tools_parsers.js";
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonOutputKeyToolsParser = exports.JsonOutputToolsParser = void 0;
|
|
4
|
+
const base_js_1 = require("../base.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object.
|
|
7
|
+
*/
|
|
8
|
+
class JsonOutputToolsParser extends base_js_1.BaseLLMOutputParser {
|
|
9
|
+
static lc_name() {
|
|
10
|
+
return "JsonOutputToolsParser";
|
|
11
|
+
}
|
|
12
|
+
constructor(fields) {
|
|
13
|
+
super(fields);
|
|
14
|
+
Object.defineProperty(this, "returnId", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: false
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: ["langchain", "output_parsers", "openai_tools"]
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: true
|
|
31
|
+
});
|
|
32
|
+
this.returnId = fields?.returnId ?? this.returnId;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parses the output and returns a JSON object. If `argsOnly` is true,
|
|
36
|
+
* only the arguments of the function call are returned.
|
|
37
|
+
* @param generations The output of the LLM to parse.
|
|
38
|
+
* @returns A JSON object representation of the function call or its arguments.
|
|
39
|
+
*/
|
|
40
|
+
async parseResult(generations) {
|
|
41
|
+
const toolCalls = generations[0].message.additional_kwargs.tool_calls;
|
|
42
|
+
if (!toolCalls) {
|
|
43
|
+
throw new Error(`No tools_call in message ${JSON.stringify(generations)}`);
|
|
44
|
+
}
|
|
45
|
+
const clonedToolCalls = JSON.parse(JSON.stringify(toolCalls));
|
|
46
|
+
const parsedToolCalls = [];
|
|
47
|
+
for (const toolCall of clonedToolCalls) {
|
|
48
|
+
if (toolCall.function !== undefined) {
|
|
49
|
+
// @ts-expect-error name and arguemnts are defined by Object.defineProperty
|
|
50
|
+
const parsedToolCall = {
|
|
51
|
+
type: toolCall.function.name,
|
|
52
|
+
args: JSON.parse(toolCall.function.arguments),
|
|
53
|
+
};
|
|
54
|
+
if (this.returnId) {
|
|
55
|
+
parsedToolCall.id = toolCall.id;
|
|
56
|
+
}
|
|
57
|
+
// backward-compatibility with previous
|
|
58
|
+
// versions of Langchain JS, which uses `name` and `arguments`
|
|
59
|
+
Object.defineProperty(parsedToolCall, "name", {
|
|
60
|
+
get() {
|
|
61
|
+
return this.type;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(parsedToolCall, "arguments", {
|
|
65
|
+
get() {
|
|
66
|
+
return this.args;
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
parsedToolCalls.push(parsedToolCall);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return parsedToolCalls;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.JsonOutputToolsParser = JsonOutputToolsParser;
|
|
76
|
+
/**
|
|
77
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object if you are
|
|
78
|
+
* expecting only a single tool to be called.
|
|
79
|
+
*/
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
+
class JsonOutputKeyToolsParser extends base_js_1.BaseLLMOutputParser {
|
|
82
|
+
static lc_name() {
|
|
83
|
+
return "JsonOutputKeyToolsParser";
|
|
84
|
+
}
|
|
85
|
+
constructor(params) {
|
|
86
|
+
super(params);
|
|
87
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: ["langchain", "output_parsers", "openai_tools"]
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
configurable: true,
|
|
96
|
+
writable: true,
|
|
97
|
+
value: true
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(this, "returnId", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
configurable: true,
|
|
102
|
+
writable: true,
|
|
103
|
+
value: false
|
|
104
|
+
});
|
|
105
|
+
/** The type of tool calls to return. */
|
|
106
|
+
Object.defineProperty(this, "keyName", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
configurable: true,
|
|
109
|
+
writable: true,
|
|
110
|
+
value: void 0
|
|
111
|
+
});
|
|
112
|
+
/** Whether to return only the first tool call. */
|
|
113
|
+
Object.defineProperty(this, "returnSingle", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: false
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(this, "initialParser", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true,
|
|
122
|
+
writable: true,
|
|
123
|
+
value: void 0
|
|
124
|
+
});
|
|
125
|
+
this.keyName = params.keyName;
|
|
126
|
+
this.returnSingle = params.returnSingle ?? this.returnSingle;
|
|
127
|
+
this.initialParser = new JsonOutputToolsParser(params);
|
|
128
|
+
}
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
+
async parseResult(generations) {
|
|
131
|
+
const results = await this.initialParser.parseResult(generations);
|
|
132
|
+
const matchingResults = results.filter((result) => result.type === this.keyName);
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
|
+
let returnedValues = matchingResults;
|
|
135
|
+
if (!this.returnId) {
|
|
136
|
+
returnedValues = matchingResults.map((result) => result.args);
|
|
137
|
+
}
|
|
138
|
+
if (this.returnSingle) {
|
|
139
|
+
return returnedValues[0];
|
|
140
|
+
}
|
|
141
|
+
return returnedValues;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.JsonOutputKeyToolsParser = JsonOutputKeyToolsParser;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ChatGeneration } from "../../outputs.js";
|
|
2
|
+
import { BaseLLMOutputParser } from "../base.js";
|
|
3
|
+
export type ParsedToolCall = {
|
|
4
|
+
id?: string;
|
|
5
|
+
type: string;
|
|
6
|
+
args: Record<string, any>;
|
|
7
|
+
/** @deprecated Use `type` instead. Will be removed in 0.2.0. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** @deprecated Use `args` instead. Will be removed in 0.2.0. */
|
|
10
|
+
arguments: Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
export type JsonOutputToolsParserParams = {
|
|
13
|
+
/** Whether to return the tool call id. */
|
|
14
|
+
returnId?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object.
|
|
18
|
+
*/
|
|
19
|
+
export declare class JsonOutputToolsParser extends BaseLLMOutputParser<ParsedToolCall[]> {
|
|
20
|
+
static lc_name(): string;
|
|
21
|
+
returnId: boolean;
|
|
22
|
+
lc_namespace: string[];
|
|
23
|
+
lc_serializable: boolean;
|
|
24
|
+
constructor(fields?: JsonOutputToolsParserParams);
|
|
25
|
+
/**
|
|
26
|
+
* Parses the output and returns a JSON object. If `argsOnly` is true,
|
|
27
|
+
* only the arguments of the function call are returned.
|
|
28
|
+
* @param generations The output of the LLM to parse.
|
|
29
|
+
* @returns A JSON object representation of the function call or its arguments.
|
|
30
|
+
*/
|
|
31
|
+
parseResult(generations: ChatGeneration[]): Promise<ParsedToolCall[]>;
|
|
32
|
+
}
|
|
33
|
+
export type JsonOutputKeyToolsParserParams = {
|
|
34
|
+
keyName: string;
|
|
35
|
+
returnSingle?: boolean;
|
|
36
|
+
/** Whether to return the tool call id. */
|
|
37
|
+
returnId?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object if you are
|
|
41
|
+
* expecting only a single tool to be called.
|
|
42
|
+
*/
|
|
43
|
+
export declare class JsonOutputKeyToolsParser extends BaseLLMOutputParser<any> {
|
|
44
|
+
static lc_name(): string;
|
|
45
|
+
lc_namespace: string[];
|
|
46
|
+
lc_serializable: boolean;
|
|
47
|
+
returnId: boolean;
|
|
48
|
+
/** The type of tool calls to return. */
|
|
49
|
+
keyName: string;
|
|
50
|
+
/** Whether to return only the first tool call. */
|
|
51
|
+
returnSingle: boolean;
|
|
52
|
+
initialParser: JsonOutputToolsParser;
|
|
53
|
+
constructor(params: JsonOutputKeyToolsParserParams);
|
|
54
|
+
parseResult(generations: ChatGeneration[]): Promise<any>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { BaseLLMOutputParser } from "../base.js";
|
|
2
|
+
/**
|
|
3
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object.
|
|
4
|
+
*/
|
|
5
|
+
export class JsonOutputToolsParser extends BaseLLMOutputParser {
|
|
6
|
+
static lc_name() {
|
|
7
|
+
return "JsonOutputToolsParser";
|
|
8
|
+
}
|
|
9
|
+
constructor(fields) {
|
|
10
|
+
super(fields);
|
|
11
|
+
Object.defineProperty(this, "returnId", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: false
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: ["langchain", "output_parsers", "openai_tools"]
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: true
|
|
28
|
+
});
|
|
29
|
+
this.returnId = fields?.returnId ?? this.returnId;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parses the output and returns a JSON object. If `argsOnly` is true,
|
|
33
|
+
* only the arguments of the function call are returned.
|
|
34
|
+
* @param generations The output of the LLM to parse.
|
|
35
|
+
* @returns A JSON object representation of the function call or its arguments.
|
|
36
|
+
*/
|
|
37
|
+
async parseResult(generations) {
|
|
38
|
+
const toolCalls = generations[0].message.additional_kwargs.tool_calls;
|
|
39
|
+
if (!toolCalls) {
|
|
40
|
+
throw new Error(`No tools_call in message ${JSON.stringify(generations)}`);
|
|
41
|
+
}
|
|
42
|
+
const clonedToolCalls = JSON.parse(JSON.stringify(toolCalls));
|
|
43
|
+
const parsedToolCalls = [];
|
|
44
|
+
for (const toolCall of clonedToolCalls) {
|
|
45
|
+
if (toolCall.function !== undefined) {
|
|
46
|
+
// @ts-expect-error name and arguemnts are defined by Object.defineProperty
|
|
47
|
+
const parsedToolCall = {
|
|
48
|
+
type: toolCall.function.name,
|
|
49
|
+
args: JSON.parse(toolCall.function.arguments),
|
|
50
|
+
};
|
|
51
|
+
if (this.returnId) {
|
|
52
|
+
parsedToolCall.id = toolCall.id;
|
|
53
|
+
}
|
|
54
|
+
// backward-compatibility with previous
|
|
55
|
+
// versions of Langchain JS, which uses `name` and `arguments`
|
|
56
|
+
Object.defineProperty(parsedToolCall, "name", {
|
|
57
|
+
get() {
|
|
58
|
+
return this.type;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(parsedToolCall, "arguments", {
|
|
62
|
+
get() {
|
|
63
|
+
return this.args;
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
parsedToolCalls.push(parsedToolCall);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return parsedToolCalls;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Class for parsing the output of a tool-calling LLM into a JSON object if you are
|
|
74
|
+
* expecting only a single tool to be called.
|
|
75
|
+
*/
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
+
export class JsonOutputKeyToolsParser extends BaseLLMOutputParser {
|
|
78
|
+
static lc_name() {
|
|
79
|
+
return "JsonOutputKeyToolsParser";
|
|
80
|
+
}
|
|
81
|
+
constructor(params) {
|
|
82
|
+
super(params);
|
|
83
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: ["langchain", "output_parsers", "openai_tools"]
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
configurable: true,
|
|
92
|
+
writable: true,
|
|
93
|
+
value: true
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(this, "returnId", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: false
|
|
100
|
+
});
|
|
101
|
+
/** The type of tool calls to return. */
|
|
102
|
+
Object.defineProperty(this, "keyName", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
configurable: true,
|
|
105
|
+
writable: true,
|
|
106
|
+
value: void 0
|
|
107
|
+
});
|
|
108
|
+
/** Whether to return only the first tool call. */
|
|
109
|
+
Object.defineProperty(this, "returnSingle", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
configurable: true,
|
|
112
|
+
writable: true,
|
|
113
|
+
value: false
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(this, "initialParser", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
configurable: true,
|
|
118
|
+
writable: true,
|
|
119
|
+
value: void 0
|
|
120
|
+
});
|
|
121
|
+
this.keyName = params.keyName;
|
|
122
|
+
this.returnSingle = params.returnSingle ?? this.returnSingle;
|
|
123
|
+
this.initialParser = new JsonOutputToolsParser(params);
|
|
124
|
+
}
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
+
async parseResult(generations) {
|
|
127
|
+
const results = await this.initialParser.parseResult(generations);
|
|
128
|
+
const matchingResults = results.filter((result) => result.type === this.keyName);
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
+
let returnedValues = matchingResults;
|
|
131
|
+
if (!this.returnId) {
|
|
132
|
+
returnedValues = matchingResults.map((result) => result.args);
|
|
133
|
+
}
|
|
134
|
+
if (this.returnSingle) {
|
|
135
|
+
return returnedValues[0];
|
|
136
|
+
}
|
|
137
|
+
return returnedValues;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/output_parsers/openai_tools/index.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/output_parsers/openai_tools/index.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/output_parsers/openai_tools/index.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/output_parsers/openai_tools/index.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"description": "Core LangChain.js abstractions and schemas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -245,6 +245,15 @@
|
|
|
245
245
|
"import": "./output_parsers.js",
|
|
246
246
|
"require": "./output_parsers.cjs"
|
|
247
247
|
},
|
|
248
|
+
"./output_parsers/openai_tools": {
|
|
249
|
+
"types": {
|
|
250
|
+
"import": "./output_parsers/openai_tools.d.ts",
|
|
251
|
+
"require": "./output_parsers/openai_tools.d.cts",
|
|
252
|
+
"default": "./output_parsers/openai_tools.d.ts"
|
|
253
|
+
},
|
|
254
|
+
"import": "./output_parsers/openai_tools.js",
|
|
255
|
+
"require": "./output_parsers/openai_tools.cjs"
|
|
256
|
+
},
|
|
248
257
|
"./outputs": {
|
|
249
258
|
"types": {
|
|
250
259
|
"import": "./outputs.d.ts",
|
|
@@ -587,6 +596,10 @@
|
|
|
587
596
|
"output_parsers.js",
|
|
588
597
|
"output_parsers.d.ts",
|
|
589
598
|
"output_parsers.d.cts",
|
|
599
|
+
"output_parsers/openai_tools.cjs",
|
|
600
|
+
"output_parsers/openai_tools.js",
|
|
601
|
+
"output_parsers/openai_tools.d.ts",
|
|
602
|
+
"output_parsers/openai_tools.d.cts",
|
|
590
603
|
"outputs.cjs",
|
|
591
604
|
"outputs.js",
|
|
592
605
|
"outputs.d.ts",
|