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

mistral[patch]: Force tool use in withStructuredOutput #5932

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
added test
  • Loading branch information
bracesproul committed Jun 28, 2024
commit 4f0740f037677c2cfd5ca52d2381e040a9c9c70f
29 changes: 29 additions & 0 deletions libs/langchain-mistralai/src/tests/chat_models.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -982,3 +982,32 @@ test("Invoke token count usage_metadata", async () => {
res.usage_metadata.input_tokens + res.usage_metadata.output_tokens
);
});

test("withStructuredOutput will always force tool usage", async () => {
const model = new ChatMistralAI({
temperature: 0,
model: "mistral-large-latest",
});

const weatherTool = z
.object({
location: z.string().describe("The name of city to get the weather for."),
})
.describe(
"Get the weather of a specific location and return the temperature in Celsius."
);
const modelWithTools = model.withStructuredOutput(weatherTool, {
name: "get_weather",
includeRaw: true,
});
const response = await modelWithTools.invoke(
"What is the sum of 271623 and 281623? It is VERY important you use a calculator tool to give me the answer."
);

if (!("tool_calls" in response.raw)) {
throw new Error("Tool call not found in response");
}
const castMessage = response.raw as AIMessage;
expect(castMessage.tool_calls).toHaveLength(1);
expect(castMessage.tool_calls?.[0].name).toBe("get_weather");
});
Loading