From 850819acf20a0bcf1f1d1475fc69b911018dff4d Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Mon, 10 Feb 2025 13:59:06 -0800 Subject: [PATCH] feat(ollama): Switch Ollama default withStructuredOutput method to jsonSchema (#7681) --- libs/langchain-ollama/src/chat_models.ts | 3 +-- .../src/tests/chat_models_structured_output.int.test.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/langchain-ollama/src/chat_models.ts b/libs/langchain-ollama/src/chat_models.ts index fc23966a26a4..dc2b2f2a7761 100644 --- a/libs/langchain-ollama/src/chat_models.ts +++ b/libs/langchain-ollama/src/chat_models.ts @@ -841,8 +841,7 @@ export class ChatOllama parsed: RunOutput; } > { - // TODO: Make this method the default in a minor bump - if (config?.method === "jsonSchema") { + if (config?.method === undefined || config?.method === "jsonSchema") { const outputSchemaIsZod = isZodSchema(outputSchema); const jsonSchema = outputSchemaIsZod ? zodToJsonSchema(outputSchema) diff --git a/libs/langchain-ollama/src/tests/chat_models_structured_output.int.test.ts b/libs/langchain-ollama/src/tests/chat_models_structured_output.int.test.ts index cba16e4639d5..70d4c3ee363f 100644 --- a/libs/langchain-ollama/src/tests/chat_models_structured_output.int.test.ts +++ b/libs/langchain-ollama/src/tests/chat_models_structured_output.int.test.ts @@ -96,7 +96,6 @@ test("Ollama can call withStructuredOutput includeRaw JSON Schema", async () => }).withStructuredOutput(weatherTool.schema, { name: weatherTool.name, includeRaw: true, - method: "jsonSchema", }); const result = await model.invoke(messageHistory); @@ -113,6 +112,7 @@ test("Ollama can call withStructuredOutput includeRaw with tool calling", async }).withStructuredOutput(weatherTool.schema, { name: weatherTool.name, includeRaw: true, + method: "functionCalling", }); const result = await model.invoke(messageHistory);