langchain 0.1.30 → 0.1.32
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/experimental/openai_assistant/index.cjs +6 -1
- package/dist/experimental/openai_assistant/index.d.ts +2 -2
- package/dist/experimental/openai_assistant/index.js +6 -1
- package/dist/experimental/openai_assistant/schema.d.ts +1 -2
- package/dist/retrievers/self_query/index.cjs +1 -6
- package/dist/retrievers/self_query/index.js +1 -6
- package/dist/smith/runner_utils.cjs +2 -2
- package/dist/smith/runner_utils.js +2 -2
- package/dist/tools/convert_to_openai.d.ts +13 -2
- package/package.json +3 -3
|
@@ -67,6 +67,7 @@ class OpenAIAssistantRunnable extends runnables_1.Runnable {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
async invoke(input, _options) {
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
71
|
let run;
|
|
71
72
|
if (this.asAgent && input.steps && input.steps.length > 0) {
|
|
72
73
|
const parsedStepsInput = await this._parseStepsInput(input);
|
|
@@ -148,6 +149,7 @@ class OpenAIAssistantRunnable extends runnables_1.Runnable {
|
|
|
148
149
|
if (!toolCalls) {
|
|
149
150
|
return input;
|
|
150
151
|
}
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
153
|
const toolOutputs = toolCalls.flatMap((toolCall) => {
|
|
152
154
|
const matchedAction = input.steps.find((step) => step.action.toolCallId === toolCall.id);
|
|
153
155
|
return matchedAction
|
|
@@ -193,6 +195,7 @@ class OpenAIAssistantRunnable extends runnables_1.Runnable {
|
|
|
193
195
|
}
|
|
194
196
|
async _waitForRun(runId, threadId) {
|
|
195
197
|
let inProgress = true;
|
|
198
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
196
199
|
let run = {};
|
|
197
200
|
while (inProgress) {
|
|
198
201
|
run = await this.client.beta.threads.runs.retrieve(threadId, runId);
|
|
@@ -235,7 +238,9 @@ class OpenAIAssistantRunnable extends runnables_1.Runnable {
|
|
|
235
238
|
return run.required_action?.submit_tool_outputs.tool_calls ?? [];
|
|
236
239
|
}
|
|
237
240
|
const actions = [];
|
|
238
|
-
run.required_action?.submit_tool_outputs.tool_calls.forEach(
|
|
241
|
+
run.required_action?.submit_tool_outputs.tool_calls.forEach(
|
|
242
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
243
|
+
(item) => {
|
|
239
244
|
const functionCall = item.function;
|
|
240
245
|
const args = JSON.parse(functionCall.arguments);
|
|
241
246
|
actions.push({
|
|
@@ -2,8 +2,8 @@ import { type ClientOptions, OpenAIClient } from "@langchain/openai";
|
|
|
2
2
|
import { StructuredTool } from "@langchain/core/tools";
|
|
3
3
|
import { Runnable, RunnableConfig } from "@langchain/core/runnables";
|
|
4
4
|
import type { OpenAIAssistantFinish, OpenAIAssistantAction, OpenAIToolType } from "./schema.js";
|
|
5
|
-
type ThreadMessage =
|
|
6
|
-
type RequiredActionFunctionToolCall =
|
|
5
|
+
type ThreadMessage = any;
|
|
6
|
+
type RequiredActionFunctionToolCall = any;
|
|
7
7
|
type ExtractRunOutput<AsAgent extends boolean | undefined> = AsAgent extends true ? OpenAIAssistantFinish | OpenAIAssistantAction[] : ThreadMessage[] | RequiredActionFunctionToolCall[];
|
|
8
8
|
export type OpenAIAssistantRunnableInput<AsAgent extends boolean | undefined = undefined> = {
|
|
9
9
|
client?: OpenAIClient;
|
|
@@ -64,6 +64,7 @@ export class OpenAIAssistantRunnable extends Runnable {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
async invoke(input, _options) {
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
68
|
let run;
|
|
68
69
|
if (this.asAgent && input.steps && input.steps.length > 0) {
|
|
69
70
|
const parsedStepsInput = await this._parseStepsInput(input);
|
|
@@ -145,6 +146,7 @@ export class OpenAIAssistantRunnable extends Runnable {
|
|
|
145
146
|
if (!toolCalls) {
|
|
146
147
|
return input;
|
|
147
148
|
}
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
148
150
|
const toolOutputs = toolCalls.flatMap((toolCall) => {
|
|
149
151
|
const matchedAction = input.steps.find((step) => step.action.toolCallId === toolCall.id);
|
|
150
152
|
return matchedAction
|
|
@@ -190,6 +192,7 @@ export class OpenAIAssistantRunnable extends Runnable {
|
|
|
190
192
|
}
|
|
191
193
|
async _waitForRun(runId, threadId) {
|
|
192
194
|
let inProgress = true;
|
|
195
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
193
196
|
let run = {};
|
|
194
197
|
while (inProgress) {
|
|
195
198
|
run = await this.client.beta.threads.runs.retrieve(threadId, runId);
|
|
@@ -232,7 +235,9 @@ export class OpenAIAssistantRunnable extends Runnable {
|
|
|
232
235
|
return run.required_action?.submit_tool_outputs.tool_calls ?? [];
|
|
233
236
|
}
|
|
234
237
|
const actions = [];
|
|
235
|
-
run.required_action?.submit_tool_outputs.tool_calls.forEach(
|
|
238
|
+
run.required_action?.submit_tool_outputs.tool_calls.forEach(
|
|
239
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
240
|
+
(item) => {
|
|
236
241
|
const functionCall = item.function;
|
|
237
242
|
const args = JSON.parse(functionCall.arguments);
|
|
238
243
|
actions.push({
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { OpenAIClient } from "@langchain/openai";
|
|
2
1
|
import type { AgentFinish, AgentAction } from "@langchain/core/agents";
|
|
3
2
|
export type OpenAIAssistantFinish = AgentFinish & {
|
|
4
3
|
runId: string;
|
|
@@ -9,4 +8,4 @@ export type OpenAIAssistantAction = AgentAction & {
|
|
|
9
8
|
runId: string;
|
|
10
9
|
threadId: string;
|
|
11
10
|
};
|
|
12
|
-
export type OpenAIToolType = Array<
|
|
11
|
+
export type OpenAIToolType = Array<any>;
|
|
@@ -90,12 +90,7 @@ class SelfQueryRetriever extends retrievers_1.BaseRetriever {
|
|
|
90
90
|
if (!this.useOriginalQuery && generatedQuery && generatedQuery.length > 0) {
|
|
91
91
|
myQuery = generatedQuery;
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
return this.vectorStore.similaritySearch(myQuery, this.searchParams?.k, filter, runManager?.getChild("vectorstore"));
|
|
98
|
-
}
|
|
93
|
+
return this.vectorStore.similaritySearch(myQuery, this.searchParams?.k, filter, runManager?.getChild("vectorstore"));
|
|
99
94
|
}
|
|
100
95
|
/**
|
|
101
96
|
* Static method to create a new SelfQueryRetriever instance from a
|
|
@@ -85,12 +85,7 @@ export class SelfQueryRetriever extends BaseRetriever {
|
|
|
85
85
|
if (!this.useOriginalQuery && generatedQuery && generatedQuery.length > 0) {
|
|
86
86
|
myQuery = generatedQuery;
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
return [];
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
return this.vectorStore.similaritySearch(myQuery, this.searchParams?.k, filter, runManager?.getChild("vectorstore"));
|
|
93
|
-
}
|
|
88
|
+
return this.vectorStore.similaritySearch(myQuery, this.searchParams?.k, filter, runManager?.getChild("vectorstore"));
|
|
94
89
|
}
|
|
95
90
|
/**
|
|
96
91
|
* Static method to create a new SelfQueryRetriever instance from a
|
|
@@ -414,7 +414,7 @@ const applyEvaluators = async ({ evaluation, runs, examples, client, }) => {
|
|
|
414
414
|
for (let i = 0; i < runs.length; i += 1) {
|
|
415
415
|
const run = runs[i];
|
|
416
416
|
const example = examples[i];
|
|
417
|
-
const evaluatorResults = await Promise.
|
|
417
|
+
const evaluatorResults = await Promise.allSettled(evaluators.map((evaluator) => client.evaluateRun(run, evaluator, {
|
|
418
418
|
referenceExample: example,
|
|
419
419
|
loadChildRuns: false,
|
|
420
420
|
})));
|
|
@@ -423,7 +423,7 @@ const applyEvaluators = async ({ evaluation, runs, examples, client, }) => {
|
|
|
423
423
|
execution_time: run?.end_time && run.start_time
|
|
424
424
|
? run.end_time - run.start_time
|
|
425
425
|
: undefined,
|
|
426
|
-
feedback: evaluatorResults,
|
|
426
|
+
feedback: evaluatorResults.map((evalResult) => evalResult.status === "fulfilled" ? evalResult.value : evalResult.reason),
|
|
427
427
|
run_id: run.id,
|
|
428
428
|
};
|
|
429
429
|
}
|
|
@@ -411,7 +411,7 @@ const applyEvaluators = async ({ evaluation, runs, examples, client, }) => {
|
|
|
411
411
|
for (let i = 0; i < runs.length; i += 1) {
|
|
412
412
|
const run = runs[i];
|
|
413
413
|
const example = examples[i];
|
|
414
|
-
const evaluatorResults = await Promise.
|
|
414
|
+
const evaluatorResults = await Promise.allSettled(evaluators.map((evaluator) => client.evaluateRun(run, evaluator, {
|
|
415
415
|
referenceExample: example,
|
|
416
416
|
loadChildRuns: false,
|
|
417
417
|
})));
|
|
@@ -420,7 +420,7 @@ const applyEvaluators = async ({ evaluation, runs, examples, client, }) => {
|
|
|
420
420
|
execution_time: run?.end_time && run.start_time
|
|
421
421
|
? run.end_time - run.start_time
|
|
422
422
|
: undefined,
|
|
423
|
-
feedback: evaluatorResults,
|
|
423
|
+
feedback: evaluatorResults.map((evalResult) => evalResult.status === "fulfilled" ? evalResult.value : evalResult.reason),
|
|
424
424
|
run_id: run.id,
|
|
425
425
|
};
|
|
426
426
|
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import type { OpenAIClient } from "@langchain/openai";
|
|
2
1
|
import type { StructuredToolInterface } from "@langchain/core/tools";
|
|
3
2
|
import { convertToOpenAIFunction, convertToOpenAITool } from "@langchain/core/utils/function_calling";
|
|
4
3
|
export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
|
|
5
|
-
export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface):
|
|
4
|
+
export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): {
|
|
5
|
+
type: string;
|
|
6
|
+
function: {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
parameters: import("zod-to-json-schema").JsonSchema7Type & {
|
|
10
|
+
$schema?: string | undefined;
|
|
11
|
+
definitions?: {
|
|
12
|
+
[key: string]: import("zod-to-json-schema").JsonSchema7Type;
|
|
13
|
+
} | undefined;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.32",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -1281,7 +1281,7 @@
|
|
|
1281
1281
|
"node-llama-cpp": "2.7.3",
|
|
1282
1282
|
"notion-to-md": "^3.1.0",
|
|
1283
1283
|
"officeparser": "^4.0.4",
|
|
1284
|
-
"openai": "^4.
|
|
1284
|
+
"openai": "^4.32.1",
|
|
1285
1285
|
"pdf-parse": "1.1.1",
|
|
1286
1286
|
"peggy": "^3.0.2",
|
|
1287
1287
|
"playwright": "^1.32.1",
|
|
@@ -1514,7 +1514,7 @@
|
|
|
1514
1514
|
"@anthropic-ai/sdk": "^0.9.1",
|
|
1515
1515
|
"@langchain/community": "~0.0.41",
|
|
1516
1516
|
"@langchain/core": "~0.1.44",
|
|
1517
|
-
"@langchain/openai": "~0.0.
|
|
1517
|
+
"@langchain/openai": "~0.0.26",
|
|
1518
1518
|
"binary-extensions": "^2.2.0",
|
|
1519
1519
|
"js-tiktoken": "^1.0.7",
|
|
1520
1520
|
"js-yaml": "^4.1.0",
|