langchain 0.2.3 → 0.2.4
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/README.md +2 -2
- package/dist/agents/executor.cjs +6 -4
- package/dist/agents/executor.js +6 -4
- package/dist/agents/tests/create_tool_calling_agent.int.test.js +51 -0
- package/dist/document_loaders/web/s3.cjs +1 -0
- package/dist/document_loaders/web/s3.js +1 -0
- package/dist/smith/runner_utils.cjs +1 -1
- package/dist/smith/runner_utils.d.ts +1 -1
- package/dist/smith/runner_utils.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ This library aims to assist in the development of those types of applications. C
|
|
|
57
57
|
|
|
58
58
|
**❓Question Answering over specific documents**
|
|
59
59
|
|
|
60
|
-
- [Documentation](https://js.langchain.com/docs/
|
|
60
|
+
- [Documentation](https://js.langchain.com/v0.2/docs/tutorials/rag)
|
|
61
61
|
- End-to-end Example: [Doc-Chatbot](https://github.com/dissorial/doc-chatbot)
|
|
62
62
|
|
|
63
63
|
|
|
@@ -95,7 +95,7 @@ Please see [here](https://js.langchain.com/v0.2/) for full documentation, which
|
|
|
95
95
|
- [Getting started](https://js.langchain.com/v0.2/docs/introduction): installation, setting up the environment, simple examples
|
|
96
96
|
- [Tutorials](https://js.langchain.com/v0.2/docs/tutorials/): interactive guides and walkthroughs of common use cases/tasks.
|
|
97
97
|
- [Use case](https://js.langchain.com/v0.2/docs/how_to/) walkthroughs and best practices for every component of the LangChain library.
|
|
98
|
-
- [Reference](https://
|
|
98
|
+
- [Reference](https://api.js.langchain.com): full API docs
|
|
99
99
|
|
|
100
100
|
## 💁 Contributing
|
|
101
101
|
|
package/dist/agents/executor.cjs
CHANGED
|
@@ -161,7 +161,10 @@ class AgentExecutorIterator extends serializable_1.Serializable {
|
|
|
161
161
|
const callbackManager = await manager_1.CallbackManager.configure(this.callbacks ?? this.config?.callbacks, this.agentExecutor.callbacks, this.tags ?? this.config?.tags, this.agentExecutor.tags, this.metadata ?? this.config?.metadata, this.agentExecutor.metadata, {
|
|
162
162
|
verbose: this.agentExecutor.verbose,
|
|
163
163
|
});
|
|
164
|
-
this.runManager = await callbackManager?.handleChainStart(this.agentExecutor.toJSON(), this.inputs,
|
|
164
|
+
this.runManager = await callbackManager?.handleChainStart(this.agentExecutor.toJSON(), this.inputs, this.config?.runId, undefined, this.tags ?? this.config?.tags, this.metadata ?? this.config?.metadata, this.runName ?? this.config?.runName);
|
|
165
|
+
if (this.config !== undefined) {
|
|
166
|
+
delete this.config.runId;
|
|
167
|
+
}
|
|
165
168
|
}
|
|
166
169
|
}
|
|
167
170
|
/**
|
|
@@ -191,9 +194,7 @@ class AgentExecutorIterator extends serializable_1.Serializable {
|
|
|
191
194
|
const toolReturn = await this.agentExecutor._getToolReturn(nextStep);
|
|
192
195
|
if (toolReturn) {
|
|
193
196
|
output = await this.agentExecutor._return(toolReturn, this.intermediateSteps, runManager);
|
|
194
|
-
|
|
195
|
-
await this.runManager.handleChainEnd(output);
|
|
196
|
-
}
|
|
197
|
+
await this.runManager?.handleChainEnd(output);
|
|
197
198
|
await this.setFinalOutputs(output);
|
|
198
199
|
}
|
|
199
200
|
}
|
|
@@ -204,6 +205,7 @@ class AgentExecutorIterator extends serializable_1.Serializable {
|
|
|
204
205
|
const output = await this.agentExecutor.agent.returnStoppedResponse(this.agentExecutor.earlyStoppingMethod, this.intermediateSteps, this.inputs);
|
|
205
206
|
const returnedOutput = await this.agentExecutor._return(output, this.intermediateSteps, this.runManager);
|
|
206
207
|
await this.setFinalOutputs(returnedOutput);
|
|
208
|
+
await this.runManager?.handleChainEnd(returnedOutput);
|
|
207
209
|
return returnedOutput;
|
|
208
210
|
}
|
|
209
211
|
async _callNext() {
|
package/dist/agents/executor.js
CHANGED
|
@@ -158,7 +158,10 @@ export class AgentExecutorIterator extends Serializable {
|
|
|
158
158
|
const callbackManager = await CallbackManager.configure(this.callbacks ?? this.config?.callbacks, this.agentExecutor.callbacks, this.tags ?? this.config?.tags, this.agentExecutor.tags, this.metadata ?? this.config?.metadata, this.agentExecutor.metadata, {
|
|
159
159
|
verbose: this.agentExecutor.verbose,
|
|
160
160
|
});
|
|
161
|
-
this.runManager = await callbackManager?.handleChainStart(this.agentExecutor.toJSON(), this.inputs,
|
|
161
|
+
this.runManager = await callbackManager?.handleChainStart(this.agentExecutor.toJSON(), this.inputs, this.config?.runId, undefined, this.tags ?? this.config?.tags, this.metadata ?? this.config?.metadata, this.runName ?? this.config?.runName);
|
|
162
|
+
if (this.config !== undefined) {
|
|
163
|
+
delete this.config.runId;
|
|
164
|
+
}
|
|
162
165
|
}
|
|
163
166
|
}
|
|
164
167
|
/**
|
|
@@ -188,9 +191,7 @@ export class AgentExecutorIterator extends Serializable {
|
|
|
188
191
|
const toolReturn = await this.agentExecutor._getToolReturn(nextStep);
|
|
189
192
|
if (toolReturn) {
|
|
190
193
|
output = await this.agentExecutor._return(toolReturn, this.intermediateSteps, runManager);
|
|
191
|
-
|
|
192
|
-
await this.runManager.handleChainEnd(output);
|
|
193
|
-
}
|
|
194
|
+
await this.runManager?.handleChainEnd(output);
|
|
194
195
|
await this.setFinalOutputs(output);
|
|
195
196
|
}
|
|
196
197
|
}
|
|
@@ -201,6 +202,7 @@ export class AgentExecutorIterator extends Serializable {
|
|
|
201
202
|
const output = await this.agentExecutor.agent.returnStoppedResponse(this.agentExecutor.earlyStoppingMethod, this.intermediateSteps, this.inputs);
|
|
202
203
|
const returnedOutput = await this.agentExecutor._return(output, this.intermediateSteps, this.runManager);
|
|
203
204
|
await this.setFinalOutputs(returnedOutput);
|
|
205
|
+
await this.runManager?.handleChainEnd(returnedOutput);
|
|
204
206
|
return returnedOutput;
|
|
205
207
|
}
|
|
206
208
|
async _callNext() {
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { test, expect } from "@jest/globals";
|
|
2
3
|
import { ChatOpenAI } from "@langchain/openai";
|
|
3
4
|
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
5
|
+
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
4
6
|
import { TavilySearchResults } from "../../util/testing/tools/tavily_search.js";
|
|
5
7
|
import { AgentExecutor, createToolCallingAgent } from "../index.js";
|
|
8
|
+
const syntaxErrorTool = new DynamicStructuredTool({
|
|
9
|
+
name: "query",
|
|
10
|
+
description: "use this tool to generate and execute a query from a question using the index.",
|
|
11
|
+
schema: z.object({
|
|
12
|
+
index_name: z.string().describe("The name of the index to query."),
|
|
13
|
+
question: z.string().describe("The question to answer."),
|
|
14
|
+
}),
|
|
15
|
+
func: async (_params) => {
|
|
16
|
+
return JSON.stringify({
|
|
17
|
+
result: "-ERR Syntax error at offset 19 near Bronx",
|
|
18
|
+
query: 'FT.AGGREGATE bites "@Borough:{The Bronx} @Gender:{M}" GROUPBY 0 REDUCE COUNT 0',
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
});
|
|
6
22
|
const tools = [new TavilySearchResults({ maxResults: 1 })];
|
|
7
23
|
test("createToolCallingAgent works", async () => {
|
|
8
24
|
const prompt = ChatPromptTemplate.fromMessages([
|
|
@@ -69,3 +85,38 @@ test("createToolCallingAgent stream events works", async () => {
|
|
|
69
85
|
}
|
|
70
86
|
}
|
|
71
87
|
});
|
|
88
|
+
test("createToolCallingAgent stream events works for multiple turns", async () => {
|
|
89
|
+
const prompt = ChatPromptTemplate.fromMessages([
|
|
90
|
+
["system", "You are a helpful assistant"],
|
|
91
|
+
["placeholder", "{chat_history}"],
|
|
92
|
+
["human", "{input}"],
|
|
93
|
+
["placeholder", "{agent_scratchpad}"],
|
|
94
|
+
]);
|
|
95
|
+
const llm = new ChatOpenAI({
|
|
96
|
+
modelName: "gpt-4o",
|
|
97
|
+
temperature: 0,
|
|
98
|
+
});
|
|
99
|
+
const agent = await createToolCallingAgent({
|
|
100
|
+
llm,
|
|
101
|
+
tools: [syntaxErrorTool],
|
|
102
|
+
prompt,
|
|
103
|
+
});
|
|
104
|
+
const agentExecutor = new AgentExecutor({
|
|
105
|
+
agent,
|
|
106
|
+
tools: [syntaxErrorTool],
|
|
107
|
+
maxIterations: 3,
|
|
108
|
+
});
|
|
109
|
+
const input = "Generate a query that looks up how many animals have been bitten in the Bronx.";
|
|
110
|
+
const eventStream = agentExecutor.streamEvents({
|
|
111
|
+
input,
|
|
112
|
+
}, {
|
|
113
|
+
version: "v2",
|
|
114
|
+
});
|
|
115
|
+
for await (const event of eventStream) {
|
|
116
|
+
const eventType = event.event;
|
|
117
|
+
console.log("Event type: ", eventType);
|
|
118
|
+
if (eventType === "on_chat_model_stream") {
|
|
119
|
+
console.log("Content: ", event.data);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
@@ -154,6 +154,7 @@ class S3Loader extends base_js_1.BaseDocumentLoader {
|
|
|
154
154
|
const unstructuredLoader = new this._UnstructuredLoader(filePath, options);
|
|
155
155
|
const docs = await unstructuredLoader.load();
|
|
156
156
|
return docs;
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
158
|
}
|
|
158
159
|
catch (e) {
|
|
159
160
|
throw new Error(`Failed to load file ${filePath} using unstructured loader: ${e.message}`);
|
|
@@ -128,6 +128,7 @@ export class S3Loader extends BaseDocumentLoader {
|
|
|
128
128
|
const unstructuredLoader = new this._UnstructuredLoader(filePath, options);
|
|
129
129
|
const docs = await unstructuredLoader.load();
|
|
130
130
|
return docs;
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
131
132
|
}
|
|
132
133
|
catch (e) {
|
|
133
134
|
throw new Error(`Failed to load file ${filePath} using unstructured loader: ${e.message}`);
|
|
@@ -140,7 +140,7 @@ class CallbackManagerRunTree extends langsmith_1.RunTree {
|
|
|
140
140
|
});
|
|
141
141
|
this.callbackManager = callbackManager;
|
|
142
142
|
}
|
|
143
|
-
|
|
143
|
+
createChild(config) {
|
|
144
144
|
const child = new CallbackManagerRunTree({
|
|
145
145
|
...config,
|
|
146
146
|
parent_run: this,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Runnable } from "@langchain/core/runnables";
|
|
2
2
|
import { Client, Feedback } from "langsmith";
|
|
3
|
-
import type { TraceableFunction } from "langsmith/traceable";
|
|
3
|
+
import type { TraceableFunction } from "langsmith/singletons/traceable";
|
|
4
4
|
import { type RunEvalConfig } from "./config.js";
|
|
5
5
|
export type ChainOrFactory = Runnable | (() => Runnable) | AnyTraceableFunction | ((obj: any) => any) | ((obj: any) => Promise<any>) | (() => (obj: unknown) => unknown) | (() => (obj: unknown) => Promise<unknown>);
|
|
6
6
|
type AnyTraceableFunction = TraceableFunction<(...any: any[]) => any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -881,14 +881,14 @@
|
|
|
881
881
|
},
|
|
882
882
|
"dependencies": {
|
|
883
883
|
"@langchain/core": "~0.2.0",
|
|
884
|
-
"@langchain/openai": "~0.0
|
|
884
|
+
"@langchain/openai": "~0.1.0",
|
|
885
885
|
"@langchain/textsplitters": "~0.0.0",
|
|
886
886
|
"binary-extensions": "^2.2.0",
|
|
887
887
|
"js-tiktoken": "^1.0.12",
|
|
888
888
|
"js-yaml": "^4.1.0",
|
|
889
889
|
"jsonpointer": "^5.0.1",
|
|
890
890
|
"langchainhub": "~0.0.8",
|
|
891
|
-
"langsmith": "~0.1.
|
|
891
|
+
"langsmith": "~0.1.30",
|
|
892
892
|
"ml-distance": "^4.0.0",
|
|
893
893
|
"openapi-types": "^12.1.3",
|
|
894
894
|
"p-retry": "4",
|