@langchain/core 0.1.12 → 0.1.14
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.d.ts +4 -0
- package/dist/load/import_map.cjs +2 -1
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/runnables/base.d.ts +4 -4
- package/dist/runnables/passthrough.cjs +42 -7
- package/dist/runnables/passthrough.d.ts +6 -0
- package/dist/runnables/passthrough.js +42 -7
- package/dist/tracers/base.cjs +1 -1
- package/dist/tracers/base.js +1 -1
- package/dist/utils/function_calling.cjs +31 -0
- package/dist/utils/function_calling.d.ts +16 -0
- package/dist/utils/function_calling.js +26 -0
- package/dist/utils/stream.d.ts +1 -1
- package/dist/utils/testing/index.cjs +32 -3
- package/dist/utils/testing/index.d.ts +15 -1
- package/dist/utils/testing/index.js +30 -2
- package/package.json +11 -2
- package/utils/function_calling.cjs +1 -0
- package/utils/function_calling.d.ts +1 -0
- package/utils/function_calling.js +1 -0
package/dist/load/import_map.cjs
CHANGED
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.vectorstores = exports.utils__types = exports.utils__tiktoken = exports.utils__testing = exports.utils__stream = exports.utils__math = exports.utils__json_schema = exports.utils__json_patch = exports.utils__hash = exports.utils__env = exports.utils__chunk_array = exports.utils__async_caller = exports.tracers__tracer_langchain_v1 = exports.tracers__tracer_langchain = exports.tracers__run_collector = exports.tracers__log_stream = exports.tracers__initialize = exports.tracers__console = exports.tracers__base = exports.tools = exports.stores = exports.retrievers = exports.runnables = exports.prompt_values = exports.prompts = exports.outputs = exports.output_parsers = exports.messages = exports.memory = exports.load__serializable = exports.language_models__llms = exports.language_models__chat_models = exports.language_models__base = exports.example_selectors = exports.embeddings = exports.documents = exports.chat_history = exports.callbacks__promises = exports.callbacks__manager = exports.callbacks__base = exports.caches = exports.agents = void 0;
|
|
27
|
+
exports.vectorstores = exports.utils__types = exports.utils__tiktoken = exports.utils__testing = exports.utils__stream = exports.utils__math = exports.utils__json_schema = exports.utils__json_patch = exports.utils__hash = exports.utils__function_calling = exports.utils__env = exports.utils__chunk_array = exports.utils__async_caller = exports.tracers__tracer_langchain_v1 = exports.tracers__tracer_langchain = exports.tracers__run_collector = exports.tracers__log_stream = exports.tracers__initialize = exports.tracers__console = exports.tracers__base = exports.tools = exports.stores = exports.retrievers = exports.runnables = exports.prompt_values = exports.prompts = exports.outputs = exports.output_parsers = exports.messages = exports.memory = exports.load__serializable = exports.language_models__llms = exports.language_models__chat_models = exports.language_models__base = exports.example_selectors = exports.embeddings = exports.documents = exports.chat_history = exports.callbacks__promises = exports.callbacks__manager = exports.callbacks__base = exports.caches = exports.agents = void 0;
|
|
28
28
|
exports.agents = __importStar(require("../agents.cjs"));
|
|
29
29
|
exports.caches = __importStar(require("../caches.cjs"));
|
|
30
30
|
exports.callbacks__base = __importStar(require("../callbacks/base.cjs"));
|
|
@@ -58,6 +58,7 @@ exports.tracers__tracer_langchain_v1 = __importStar(require("../tracers/tracer_l
|
|
|
58
58
|
exports.utils__async_caller = __importStar(require("../utils/async_caller.cjs"));
|
|
59
59
|
exports.utils__chunk_array = __importStar(require("../utils/chunk_array.cjs"));
|
|
60
60
|
exports.utils__env = __importStar(require("../utils/env.cjs"));
|
|
61
|
+
exports.utils__function_calling = __importStar(require("../utils/function_calling.cjs"));
|
|
61
62
|
exports.utils__hash = __importStar(require("../utils/hash.cjs"));
|
|
62
63
|
exports.utils__json_patch = __importStar(require("../utils/json_patch.cjs"));
|
|
63
64
|
exports.utils__json_schema = __importStar(require("../utils/json_schema.cjs"));
|
|
@@ -31,6 +31,7 @@ export * as tracers__tracer_langchain_v1 from "../tracers/tracer_langchain_v1.js
|
|
|
31
31
|
export * as utils__async_caller from "../utils/async_caller.js";
|
|
32
32
|
export * as utils__chunk_array from "../utils/chunk_array.js";
|
|
33
33
|
export * as utils__env from "../utils/env.js";
|
|
34
|
+
export * as utils__function_calling from "../utils/function_calling.js";
|
|
34
35
|
export * as utils__hash from "../utils/hash.js";
|
|
35
36
|
export * as utils__json_patch from "../utils/json_patch.js";
|
|
36
37
|
export * as utils__json_schema from "../utils/json_schema.js";
|
package/dist/load/import_map.js
CHANGED
|
@@ -32,6 +32,7 @@ export * as tracers__tracer_langchain_v1 from "../tracers/tracer_langchain_v1.js
|
|
|
32
32
|
export * as utils__async_caller from "../utils/async_caller.js";
|
|
33
33
|
export * as utils__chunk_array from "../utils/chunk_array.js";
|
|
34
34
|
export * as utils__env from "../utils/env.js";
|
|
35
|
+
export * as utils__function_calling from "../utils/function_calling.js";
|
|
35
36
|
export * as utils__hash from "../utils/hash.js";
|
|
36
37
|
export * as utils__json_patch from "../utils/json_patch.js";
|
|
37
38
|
export * as utils__json_schema from "../utils/json_schema.js";
|
package/dist/runnables/base.d.ts
CHANGED
|
@@ -147,15 +147,15 @@ export declare abstract class Runnable<RunInput = any, RunOutput = any, CallOpti
|
|
|
147
147
|
* @param coerceable A runnable, function, or object whose values are functions or runnables.
|
|
148
148
|
* @returns A new runnable sequence.
|
|
149
149
|
*/
|
|
150
|
-
pipe<NewRunOutput>(coerceable: RunnableLike<RunOutput, NewRunOutput>):
|
|
150
|
+
pipe<NewRunOutput>(coerceable: RunnableLike<RunOutput, NewRunOutput>): Runnable<RunInput, Exclude<NewRunOutput, Error>>;
|
|
151
151
|
/**
|
|
152
152
|
* Pick keys from the dict output of this runnable. Returns a new runnable.
|
|
153
153
|
*/
|
|
154
|
-
pick(keys: string | string[]):
|
|
154
|
+
pick(keys: string | string[]): Runnable;
|
|
155
155
|
/**
|
|
156
156
|
* Assigns new fields to the dict output of this runnable. Returns a new runnable.
|
|
157
157
|
*/
|
|
158
|
-
assign(mapping: RunnableMapLike<Record<string, unknown>, Record<string, unknown>>):
|
|
158
|
+
assign(mapping: RunnableMapLike<Record<string, unknown>, Record<string, unknown>>): Runnable;
|
|
159
159
|
/**
|
|
160
160
|
* Default implementation of transform, which buffers input and then calls stream.
|
|
161
161
|
* Subclasses should override this method if they can start producing output while
|
|
@@ -357,7 +357,7 @@ export declare class RunnableSequence<RunInput = any, RunOutput = any> extends R
|
|
|
357
357
|
last: Runnable<any, RunOutput>;
|
|
358
358
|
name?: string;
|
|
359
359
|
});
|
|
360
|
-
get steps(): Runnable<
|
|
360
|
+
get steps(): Runnable<any, any, RunnableConfig>[];
|
|
361
361
|
invoke(input: RunInput, options?: RunnableConfig): Promise<RunOutput>;
|
|
362
362
|
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
363
363
|
returnExceptions?: false;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RunnablePassthrough = void 0;
|
|
4
|
+
const stream_js_1 = require("../utils/stream.cjs");
|
|
4
5
|
const base_js_1 = require("./base.cjs");
|
|
5
6
|
/**
|
|
6
7
|
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
@@ -29,8 +30,11 @@ const base_js_1 = require("./base.cjs");
|
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
32
|
class RunnablePassthrough extends base_js_1.Runnable {
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
static lc_name() {
|
|
34
|
+
return "RunnablePassthrough";
|
|
35
|
+
}
|
|
36
|
+
constructor(fields) {
|
|
37
|
+
super(fields);
|
|
34
38
|
Object.defineProperty(this, "lc_namespace", {
|
|
35
39
|
enumerable: true,
|
|
36
40
|
configurable: true,
|
|
@@ -43,15 +47,46 @@ class RunnablePassthrough extends base_js_1.Runnable {
|
|
|
43
47
|
writable: true,
|
|
44
48
|
value: true
|
|
45
49
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
Object.defineProperty(this, "func", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
value: void 0
|
|
55
|
+
});
|
|
56
|
+
if (fields) {
|
|
57
|
+
this.func = fields.func;
|
|
58
|
+
}
|
|
49
59
|
}
|
|
50
60
|
async invoke(input, options) {
|
|
61
|
+
if (this.func) {
|
|
62
|
+
await this.func(input, options);
|
|
63
|
+
}
|
|
51
64
|
return this._callWithConfig((input) => Promise.resolve(input), input, options);
|
|
52
65
|
}
|
|
53
|
-
transform(generator, options) {
|
|
54
|
-
|
|
66
|
+
async *transform(generator, options) {
|
|
67
|
+
let finalOutput;
|
|
68
|
+
let finalOutputSupported = true;
|
|
69
|
+
for await (const chunk of this._transformStreamWithConfig(generator, (input) => input, options)) {
|
|
70
|
+
yield chunk;
|
|
71
|
+
if (finalOutputSupported) {
|
|
72
|
+
if (finalOutput === undefined) {
|
|
73
|
+
finalOutput = chunk;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
try {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
finalOutput = (0, stream_js_1.concat)(finalOutput, chunk);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
finalOutput = undefined;
|
|
82
|
+
finalOutputSupported = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (this.func && finalOutput !== undefined) {
|
|
88
|
+
await this.func(finalOutput, options);
|
|
89
|
+
}
|
|
55
90
|
}
|
|
56
91
|
/**
|
|
57
92
|
* A runnable that assigns key-value pairs to the input.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Runnable, RunnableAssign, RunnableMapLike } from "./base.js";
|
|
2
2
|
import type { RunnableConfig } from "./config.js";
|
|
3
|
+
type RunnablePassthroughFunc<RunInput = any> = ((input: RunInput) => void) | ((input: RunInput, config?: RunnableConfig) => void) | ((input: RunInput) => Promise<void>) | ((input: RunInput, config?: RunnableConfig) => Promise<void>);
|
|
3
4
|
/**
|
|
4
5
|
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
5
6
|
*
|
|
@@ -30,6 +31,10 @@ export declare class RunnablePassthrough<RunInput> extends Runnable<RunInput, Ru
|
|
|
30
31
|
static lc_name(): string;
|
|
31
32
|
lc_namespace: string[];
|
|
32
33
|
lc_serializable: boolean;
|
|
34
|
+
func?: RunnablePassthroughFunc<RunInput>;
|
|
35
|
+
constructor(fields?: {
|
|
36
|
+
func?: RunnablePassthroughFunc<RunInput>;
|
|
37
|
+
});
|
|
33
38
|
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunInput>;
|
|
34
39
|
transform(generator: AsyncGenerator<RunInput>, options: Partial<RunnableConfig>): AsyncGenerator<RunInput>;
|
|
35
40
|
/**
|
|
@@ -62,3 +67,4 @@ export declare class RunnablePassthrough<RunInput> extends Runnable<RunInput, Ru
|
|
|
62
67
|
*/
|
|
63
68
|
static assign<RunInput extends Record<string, unknown>, RunOutput extends Record<string, unknown>>(mapping: RunnableMapLike<RunInput, RunOutput>): RunnableAssign<RunInput, RunInput & RunOutput>;
|
|
64
69
|
}
|
|
70
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { concat } from "../utils/stream.js";
|
|
1
2
|
import { Runnable, RunnableAssign, RunnableMap, } from "./base.js";
|
|
2
3
|
/**
|
|
3
4
|
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
@@ -26,8 +27,11 @@ import { Runnable, RunnableAssign, RunnableMap, } from "./base.js";
|
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
29
|
export class RunnablePassthrough extends Runnable {
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
static lc_name() {
|
|
31
|
+
return "RunnablePassthrough";
|
|
32
|
+
}
|
|
33
|
+
constructor(fields) {
|
|
34
|
+
super(fields);
|
|
31
35
|
Object.defineProperty(this, "lc_namespace", {
|
|
32
36
|
enumerable: true,
|
|
33
37
|
configurable: true,
|
|
@@ -40,15 +44,46 @@ export class RunnablePassthrough extends Runnable {
|
|
|
40
44
|
writable: true,
|
|
41
45
|
value: true
|
|
42
46
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
Object.defineProperty(this, "func", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
if (fields) {
|
|
54
|
+
this.func = fields.func;
|
|
55
|
+
}
|
|
46
56
|
}
|
|
47
57
|
async invoke(input, options) {
|
|
58
|
+
if (this.func) {
|
|
59
|
+
await this.func(input, options);
|
|
60
|
+
}
|
|
48
61
|
return this._callWithConfig((input) => Promise.resolve(input), input, options);
|
|
49
62
|
}
|
|
50
|
-
transform(generator, options) {
|
|
51
|
-
|
|
63
|
+
async *transform(generator, options) {
|
|
64
|
+
let finalOutput;
|
|
65
|
+
let finalOutputSupported = true;
|
|
66
|
+
for await (const chunk of this._transformStreamWithConfig(generator, (input) => input, options)) {
|
|
67
|
+
yield chunk;
|
|
68
|
+
if (finalOutputSupported) {
|
|
69
|
+
if (finalOutput === undefined) {
|
|
70
|
+
finalOutput = chunk;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
try {
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
finalOutput = concat(finalOutput, chunk);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
finalOutput = undefined;
|
|
79
|
+
finalOutputSupported = false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (this.func && finalOutput !== undefined) {
|
|
85
|
+
await this.func(finalOutput, options);
|
|
86
|
+
}
|
|
52
87
|
}
|
|
53
88
|
/**
|
|
54
89
|
* A runnable that assigns key-value pairs to the input.
|
package/dist/tracers/base.cjs
CHANGED
|
@@ -218,7 +218,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
218
218
|
throw new Error("No chain run to end.");
|
|
219
219
|
}
|
|
220
220
|
run.end_time = Date.now();
|
|
221
|
-
run.error = error.message;
|
|
221
|
+
run.error = error.message + (error.stack ? `\n\n${error.stack}` : "");
|
|
222
222
|
run.events.push({
|
|
223
223
|
name: "error",
|
|
224
224
|
time: new Date(run.end_time).toISOString(),
|
package/dist/tracers/base.js
CHANGED
|
@@ -215,7 +215,7 @@ export class BaseTracer extends BaseCallbackHandler {
|
|
|
215
215
|
throw new Error("No chain run to end.");
|
|
216
216
|
}
|
|
217
217
|
run.end_time = Date.now();
|
|
218
|
-
run.error = error.message;
|
|
218
|
+
run.error = error.message + (error.stack ? `\n\n${error.stack}` : "");
|
|
219
219
|
run.events.push({
|
|
220
220
|
name: "error",
|
|
221
221
|
time: new Date(run.end_time).toISOString(),
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToOpenAITool = exports.convertToOpenAIFunction = void 0;
|
|
4
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
|
+
/**
|
|
6
|
+
* Formats a `StructuredTool` instance into a format that is compatible
|
|
7
|
+
* with OpenAI function calling. It uses the `zodToJsonSchema`
|
|
8
|
+
* function to convert the schema of the `StructuredTool` into a JSON
|
|
9
|
+
* schema, which is then used as the parameters for the OpenAI function.
|
|
10
|
+
*/
|
|
11
|
+
function convertToOpenAIFunction(tool) {
|
|
12
|
+
return {
|
|
13
|
+
name: tool.name,
|
|
14
|
+
description: tool.description,
|
|
15
|
+
parameters: (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.convertToOpenAIFunction = convertToOpenAIFunction;
|
|
19
|
+
/**
|
|
20
|
+
* Formats a `StructuredTool` instance into a format that is compatible
|
|
21
|
+
* with OpenAI tool calling. It uses the `zodToJsonSchema`
|
|
22
|
+
* function to convert the schema of the `StructuredTool` into a JSON
|
|
23
|
+
* schema, which is then used as the parameters for the OpenAI tool.
|
|
24
|
+
*/
|
|
25
|
+
function convertToOpenAITool(tool) {
|
|
26
|
+
return {
|
|
27
|
+
type: "function",
|
|
28
|
+
function: convertToOpenAIFunction(tool),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.convertToOpenAITool = convertToOpenAITool;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StructuredToolInterface } from "../tools.js";
|
|
2
|
+
import { FunctionDefinition, ToolDefinition } from "../language_models/base.js";
|
|
3
|
+
/**
|
|
4
|
+
* Formats a `StructuredTool` instance into a format that is compatible
|
|
5
|
+
* with OpenAI function calling. It uses the `zodToJsonSchema`
|
|
6
|
+
* function to convert the schema of the `StructuredTool` into a JSON
|
|
7
|
+
* schema, which is then used as the parameters for the OpenAI function.
|
|
8
|
+
*/
|
|
9
|
+
export declare function convertToOpenAIFunction(tool: StructuredToolInterface): FunctionDefinition;
|
|
10
|
+
/**
|
|
11
|
+
* Formats a `StructuredTool` instance into a format that is compatible
|
|
12
|
+
* with OpenAI tool calling. It uses the `zodToJsonSchema`
|
|
13
|
+
* function to convert the schema of the `StructuredTool` into a JSON
|
|
14
|
+
* schema, which is then used as the parameters for the OpenAI tool.
|
|
15
|
+
*/
|
|
16
|
+
export declare function convertToOpenAITool(tool: StructuredToolInterface): ToolDefinition;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
|
+
/**
|
|
3
|
+
* Formats a `StructuredTool` instance into a format that is compatible
|
|
4
|
+
* with OpenAI function calling. It uses the `zodToJsonSchema`
|
|
5
|
+
* function to convert the schema of the `StructuredTool` into a JSON
|
|
6
|
+
* schema, which is then used as the parameters for the OpenAI function.
|
|
7
|
+
*/
|
|
8
|
+
export function convertToOpenAIFunction(tool) {
|
|
9
|
+
return {
|
|
10
|
+
name: tool.name,
|
|
11
|
+
description: tool.description,
|
|
12
|
+
parameters: zodToJsonSchema(tool.schema),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Formats a `StructuredTool` instance into a format that is compatible
|
|
17
|
+
* with OpenAI tool calling. It uses the `zodToJsonSchema`
|
|
18
|
+
* function to convert the schema of the `StructuredTool` into a JSON
|
|
19
|
+
* schema, which is then used as the parameters for the OpenAI tool.
|
|
20
|
+
*/
|
|
21
|
+
export function convertToOpenAITool(tool) {
|
|
22
|
+
return {
|
|
23
|
+
type: "function",
|
|
24
|
+
function: convertToOpenAIFunction(tool),
|
|
25
|
+
};
|
|
26
|
+
}
|
package/dist/utils/stream.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface IterableReadableStreamInterface<T> extends ReadableStream<T>,
|
|
1
|
+
export interface IterableReadableStreamInterface<T> extends ReadableStream<T>, AsyncIterable<T> {
|
|
2
2
|
}
|
|
3
3
|
export declare class IterableReadableStream<T> extends ReadableStream<T> implements IterableReadableStreamInterface<T> {
|
|
4
4
|
reader: ReadableStreamDefaultReader<T>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable no-promise-executor-return */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.FakeTracer = exports.FakeListChatMessageHistory = exports.FakeChatMessageHistory = exports.FakeListChatModel = exports.FakeRetriever = exports.FakeChatModel = exports.FakeStreamingLLM = exports.FakeLLM = exports.FakeRunnable = exports.FakeSplitIntoListParser = void 0;
|
|
3
|
+
exports.FakeTool = exports.FakeTracer = exports.FakeListChatMessageHistory = exports.FakeChatMessageHistory = exports.FakeListChatModel = exports.FakeRetriever = exports.FakeChatModel = exports.FakeStreamingLLM = exports.FakeLLM = exports.FakeRunnable = exports.FakeSplitIntoListParser = void 0;
|
|
6
4
|
const chat_history_js_1 = require("../../chat_history.cjs");
|
|
7
5
|
const document_js_1 = require("../../documents/document.cjs");
|
|
8
6
|
const chat_models_js_1 = require("../../language_models/chat_models.cjs");
|
|
@@ -12,6 +10,7 @@ const base_js_1 = require("../../output_parsers/base.cjs");
|
|
|
12
10
|
const outputs_js_1 = require("../../outputs.cjs");
|
|
13
11
|
const retrievers_js_1 = require("../../retrievers.cjs");
|
|
14
12
|
const base_js_2 = require("../../runnables/base.cjs");
|
|
13
|
+
const tools_js_1 = require("../../tools.cjs");
|
|
15
14
|
const base_js_3 = require("../../tracers/base.cjs");
|
|
16
15
|
/**
|
|
17
16
|
* Parser for comma-separated values. It splits the input text by commas
|
|
@@ -366,3 +365,33 @@ class FakeTracer extends base_js_3.BaseTracer {
|
|
|
366
365
|
}
|
|
367
366
|
}
|
|
368
367
|
exports.FakeTracer = FakeTracer;
|
|
368
|
+
class FakeTool extends tools_js_1.StructuredTool {
|
|
369
|
+
constructor(fields) {
|
|
370
|
+
super(fields);
|
|
371
|
+
Object.defineProperty(this, "name", {
|
|
372
|
+
enumerable: true,
|
|
373
|
+
configurable: true,
|
|
374
|
+
writable: true,
|
|
375
|
+
value: void 0
|
|
376
|
+
});
|
|
377
|
+
Object.defineProperty(this, "description", {
|
|
378
|
+
enumerable: true,
|
|
379
|
+
configurable: true,
|
|
380
|
+
writable: true,
|
|
381
|
+
value: void 0
|
|
382
|
+
});
|
|
383
|
+
Object.defineProperty(this, "schema", {
|
|
384
|
+
enumerable: true,
|
|
385
|
+
configurable: true,
|
|
386
|
+
writable: true,
|
|
387
|
+
value: void 0
|
|
388
|
+
});
|
|
389
|
+
this.name = fields.name;
|
|
390
|
+
this.description = fields.description;
|
|
391
|
+
this.schema = fields.schema;
|
|
392
|
+
}
|
|
393
|
+
async _call(arg, _runManager) {
|
|
394
|
+
return JSON.stringify(arg);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
exports.FakeTool = FakeTool;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BaseCallbackConfig, CallbackManagerForLLMRun, CallbackManagerForToolRun } from "../../callbacks/manager.js";
|
|
2
3
|
import { BaseChatMessageHistory, BaseListChatMessageHistory } from "../../chat_history.js";
|
|
3
4
|
import { Document } from "../../documents/document.js";
|
|
4
5
|
import { BaseChatModel, BaseChatModelParams } from "../../language_models/chat_models.js";
|
|
@@ -8,6 +9,7 @@ import { BaseOutputParser } from "../../output_parsers/base.js";
|
|
|
8
9
|
import { GenerationChunk, type ChatResult, ChatGenerationChunk } from "../../outputs.js";
|
|
9
10
|
import { BaseRetriever } from "../../retrievers.js";
|
|
10
11
|
import { Runnable } from "../../runnables/base.js";
|
|
12
|
+
import { StructuredTool, ToolParams } from "../../tools.js";
|
|
11
13
|
import { BaseTracer, Run } from "../../tracers/base.js";
|
|
12
14
|
/**
|
|
13
15
|
* Parser for comma-separated values. It splits the input text by commas
|
|
@@ -130,3 +132,15 @@ export declare class FakeTracer extends BaseTracer {
|
|
|
130
132
|
constructor();
|
|
131
133
|
protected persistRun(run: Run): Promise<void>;
|
|
132
134
|
}
|
|
135
|
+
export interface FakeToolParams<T extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any>> extends ToolParams {
|
|
136
|
+
name: string;
|
|
137
|
+
description: string;
|
|
138
|
+
schema: T;
|
|
139
|
+
}
|
|
140
|
+
export declare class FakeTool<T extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any>> extends StructuredTool<T> {
|
|
141
|
+
name: string;
|
|
142
|
+
description: string;
|
|
143
|
+
schema: T;
|
|
144
|
+
constructor(fields: FakeToolParams<T>);
|
|
145
|
+
protected _call(arg: z.output<T>, _runManager?: CallbackManagerForToolRun): Promise<string>;
|
|
146
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable no-promise-executor-return */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
1
|
import { BaseChatMessageHistory, BaseListChatMessageHistory, } from "../../chat_history.js";
|
|
4
2
|
import { Document } from "../../documents/document.js";
|
|
5
3
|
import { BaseChatModel, } from "../../language_models/chat_models.js";
|
|
@@ -9,6 +7,7 @@ import { BaseOutputParser } from "../../output_parsers/base.js";
|
|
|
9
7
|
import { ChatGenerationChunk, } from "../../outputs.js";
|
|
10
8
|
import { BaseRetriever } from "../../retrievers.js";
|
|
11
9
|
import { Runnable } from "../../runnables/base.js";
|
|
10
|
+
import { StructuredTool } from "../../tools.js";
|
|
12
11
|
import { BaseTracer } from "../../tracers/base.js";
|
|
13
12
|
/**
|
|
14
13
|
* Parser for comma-separated values. It splits the input text by commas
|
|
@@ -353,3 +352,32 @@ export class FakeTracer extends BaseTracer {
|
|
|
353
352
|
return Promise.resolve();
|
|
354
353
|
}
|
|
355
354
|
}
|
|
355
|
+
export class FakeTool extends StructuredTool {
|
|
356
|
+
constructor(fields) {
|
|
357
|
+
super(fields);
|
|
358
|
+
Object.defineProperty(this, "name", {
|
|
359
|
+
enumerable: true,
|
|
360
|
+
configurable: true,
|
|
361
|
+
writable: true,
|
|
362
|
+
value: void 0
|
|
363
|
+
});
|
|
364
|
+
Object.defineProperty(this, "description", {
|
|
365
|
+
enumerable: true,
|
|
366
|
+
configurable: true,
|
|
367
|
+
writable: true,
|
|
368
|
+
value: void 0
|
|
369
|
+
});
|
|
370
|
+
Object.defineProperty(this, "schema", {
|
|
371
|
+
enumerable: true,
|
|
372
|
+
configurable: true,
|
|
373
|
+
writable: true,
|
|
374
|
+
value: void 0
|
|
375
|
+
});
|
|
376
|
+
this.name = fields.name;
|
|
377
|
+
this.description = fields.description;
|
|
378
|
+
this.schema = fields.schema;
|
|
379
|
+
}
|
|
380
|
+
async _call(arg, _runManager) {
|
|
381
|
+
return JSON.stringify(arg);
|
|
382
|
+
}
|
|
383
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Core LangChain.js abstractions and schemas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"p-queue": "^6.6.2",
|
|
44
44
|
"p-retry": "4",
|
|
45
45
|
"uuid": "^9.0.0",
|
|
46
|
-
"zod": "^3.22.3"
|
|
46
|
+
"zod": "^3.22.3",
|
|
47
|
+
"zod-to-json-schema": "3.20.3"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@jest/globals": "^29.5.0",
|
|
@@ -254,6 +255,11 @@
|
|
|
254
255
|
"import": "./utils/env.js",
|
|
255
256
|
"require": "./utils/env.cjs"
|
|
256
257
|
},
|
|
258
|
+
"./utils/function_calling": {
|
|
259
|
+
"types": "./utils/function_calling.d.ts",
|
|
260
|
+
"import": "./utils/function_calling.js",
|
|
261
|
+
"require": "./utils/function_calling.cjs"
|
|
262
|
+
},
|
|
257
263
|
"./utils/hash": {
|
|
258
264
|
"types": "./utils/hash.d.ts",
|
|
259
265
|
"import": "./utils/hash.js",
|
|
@@ -405,6 +411,9 @@
|
|
|
405
411
|
"utils/env.cjs",
|
|
406
412
|
"utils/env.js",
|
|
407
413
|
"utils/env.d.ts",
|
|
414
|
+
"utils/function_calling.cjs",
|
|
415
|
+
"utils/function_calling.js",
|
|
416
|
+
"utils/function_calling.d.ts",
|
|
408
417
|
"utils/hash.cjs",
|
|
409
418
|
"utils/hash.js",
|
|
410
419
|
"utils/hash.d.ts",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/utils/function_calling.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/utils/function_calling.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/utils/function_calling.js'
|