fix: updated ollama structured output

This commit is contained in:
PeriniM 2025-01-12 12:58:36 +01:00
parent 7fee21724d
commit 3b9591156d
7 changed files with 9 additions and 7 deletions

View File

@ -12,7 +12,6 @@ graph_config = {
"llm": {
"model": "ollama/llama3.1",
"temperature": 0,
"format": "json",
"base_url": "http://localhost:11434",
},
"verbose": True,

View File

@ -18,7 +18,6 @@ graph_config = {
"llm": {
"model": "ollama/llama3.1",
"temperature": 0,
"format": "json", # Ollama needs the format to be specified explicitly
"base_url": "http://localhost:11434", # set ollama URL arbitrarily
},
"verbose": True,

View File

@ -15,7 +15,6 @@ graph_config = {
"llm": {
"model": "ollama/llama3.1",
"temperature": 0,
"format": "json", # Ollama needs the format to be specified explicitly
"base_url": "http://localhost:11434", # set ollama URL arbitrarily
},
"verbose": True,

View File

@ -13,7 +13,6 @@ graph_config = {
"llm": {
"model": "ollama/llama3.1",
"temperature": 0,
"format": "json", # Ollama needs the format to be specified explicitly
# "base_url": "http://localhost:11434", # set ollama URL arbitrarily
},
"verbose": True,

View File

@ -13,9 +13,8 @@ graph_config = {
"llm": {
"model": "ollama/llama3.2:3b",
"temperature": 0,
"format": "json", # Ollama needs the format to be specified explicitly
# "base_url": "http://localhost:11434", # set ollama URL arbitrarily
"model_tokens": 1024,
"model_tokens": 4096,
},
"verbose": True,
"headless": False,

View File

@ -27,7 +27,6 @@ graph_config = {
"llm": {
"model": "ollama/llama3.1",
"temperature": 0,
"format": "json", # Ollama needs the format to be specified explicitly
# "base_url": "http://localhost:11434", # set ollama URL arbitrarily
},
"verbose": True,

View File

@ -5,6 +5,7 @@ MergeAnswersNode Module
from typing import List, Optional
from langchain.prompts import PromptTemplate
from langchain_community.chat_models import ChatOllama
from langchain_core.output_parsers import JsonOutputParser
from langchain_mistralai import ChatMistralAI
from langchain_openai import ChatOpenAI
@ -42,6 +43,13 @@ class MergeAnswersNode(BaseNode):
super().__init__(node_name, "node", input, output, 2, node_config)
self.llm_model = node_config["llm_model"]
if isinstance(self.llm_model, ChatOllama):
if self.node_config.get("schema", None) is None:
self.llm_model.format = "json"
else:
self.llm_model.format = self.node_config["schema"].model_json_schema()
self.verbose = (
False if node_config is None else node_config.get("verbose", False)
)