Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(langchain): Fix withConfig with universal chat model #7085

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions langchain/src/chat_models/tests/universal.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,47 @@ describe("Can call base runnable methods", () => {
expect(batchResult[0].content).not.toBe("");
expect(batchResult[1].content).not.toBe("");
});

it("can call withConfig with tools", async () => {
const weatherTool = {
schema: z
.object({
location: z
.string()
.describe("The city and state, e.g. San Francisco, CA"),
})
.describe("Get the current weather in a given location"),
name: "GetWeather",
description: "Get the current weather in a given location",
};

const openaiModel = await initChatModel("gpt-4o-mini", {
temperature: 0,
apiKey: openAIApiKey,
});

const modelWithTools = openaiModel.bindTools([weatherTool], {
tool_choice: "GetWeather",
});
expect(modelWithTools._queuedMethodOperations.bindTools).toBeDefined();
expect(modelWithTools._queuedMethodOperations.bindTools[0][0].name).toBe(
"GetWeather"
);
const modelWithConfig = modelWithTools.withConfig({ runName: "weather" });

expect(modelWithConfig.bound).toHaveProperty("_queuedMethodOperations");
expect(
(modelWithConfig.bound as any)._queuedMethodOperations.bindTools
).toBeDefined();
expect(
(modelWithConfig.bound as any)._queuedMethodOperations.bindTools[0][0]
.name
).toBe("GetWeather");

expect(modelWithConfig.config.runName).toBe("weather");

const result = await modelWithConfig.invoke("What's 8x8?");
expect(result.tool_calls).toBeDefined();
expect(result.tool_calls?.[0].name).toBe("GetWeather");
});
});
1 change: 1 addition & 0 deletions langchain/src/chat_models/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ class _ConfigurableModel<
? [...this._configurableFields]
: this._configurableFields,
configPrefix: this._configPrefix,
queuedMethodOperations: this._queuedMethodOperations,
});

return new RunnableBinding<RunInput, AIMessageChunk, CallOptions>({
Expand Down
Loading