Skip to content

Commit 3b95911

Browse files
committed
fix: updated ollama structured output
1 parent 7fee217 commit 3b95911

7 files changed

+9
-7
lines changed

examples/smart_scraper_graph/ollama/smart_scraper_lite_ollama.py

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"llm": {
1313
"model": "ollama/llama3.1",
1414
"temperature": 0,
15-
"format": "json",
1615
"base_url": "http://localhost:11434",
1716
},
1817
"verbose": True,

examples/smart_scraper_graph/ollama/smart_scraper_multi_concat_ollama.py

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"llm": {
1919
"model": "ollama/llama3.1",
2020
"temperature": 0,
21-
"format": "json", # Ollama needs the format to be specified explicitly
2221
"base_url": "http://localhost:11434", # set ollama URL arbitrarily
2322
},
2423
"verbose": True,

examples/smart_scraper_graph/ollama/smart_scraper_multi_lite_ollama.py

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"llm": {
1616
"model": "ollama/llama3.1",
1717
"temperature": 0,
18-
"format": "json", # Ollama needs the format to be specified explicitly
1918
"base_url": "http://localhost:11434", # set ollama URL arbitrarily
2019
},
2120
"verbose": True,

examples/smart_scraper_graph/ollama/smart_scraper_multi_ollama.py

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"llm": {
1414
"model": "ollama/llama3.1",
1515
"temperature": 0,
16-
"format": "json", # Ollama needs the format to be specified explicitly
1716
# "base_url": "http://localhost:11434", # set ollama URL arbitrarily
1817
},
1918
"verbose": True,

examples/smart_scraper_graph/ollama/smart_scraper_ollama.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
"llm": {
1414
"model": "ollama/llama3.2:3b",
1515
"temperature": 0,
16-
"format": "json", # Ollama needs the format to be specified explicitly
1716
# "base_url": "http://localhost:11434", # set ollama URL arbitrarily
18-
"model_tokens": 1024,
17+
"model_tokens": 4096,
1918
},
2019
"verbose": True,
2120
"headless": False,

examples/smart_scraper_graph/ollama/smart_scraper_schema_ollama.py

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class Projects(BaseModel):
2727
"llm": {
2828
"model": "ollama/llama3.1",
2929
"temperature": 0,
30-
"format": "json", # Ollama needs the format to be specified explicitly
3130
# "base_url": "http://localhost:11434", # set ollama URL arbitrarily
3231
},
3332
"verbose": True,

scrapegraphai/nodes/merge_answers_node.py

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import List, Optional
66

77
from langchain.prompts import PromptTemplate
8+
from langchain_community.chat_models import ChatOllama
89
from langchain_core.output_parsers import JsonOutputParser
910
from langchain_mistralai import ChatMistralAI
1011
from langchain_openai import ChatOpenAI
@@ -42,6 +43,13 @@ def __init__(
4243
super().__init__(node_name, "node", input, output, 2, node_config)
4344

4445
self.llm_model = node_config["llm_model"]
46+
47+
if isinstance(self.llm_model, ChatOllama):
48+
if self.node_config.get("schema", None) is None:
49+
self.llm_model.format = "json"
50+
else:
51+
self.llm_model.format = self.node_config["schema"].model_json_schema()
52+
4553
self.verbose = (
4654
False if node_config is None else node_config.get("verbose", False)
4755
)

0 commit comments

Comments
 (0)