Skip to content

Python scraper based on AI

fix: updated ollama structured output

PeriniM3b9591156d96
diff --git a/examples/smart_scraper_graph/ollama/smart_scraper_lite_ollama.py b/examples/smart_scraper_graph/ollama/smart_scraper_lite_ollama.py
index fd23f39c..9c4b9a69 100644
--- a/examples/smart_scraper_graph/ollama/smart_scraper_lite_ollama.py
+++ b/examples/smart_scraper_graph/ollama/smart_scraper_lite_ollama.py
@@ -12,7 +12,6 @@ graph_config = {
"llm": {
"model": "ollama/llama3.1",
"temperature": 0,
- "format": "json",
"base_url": "http://localhost:11434",
},
"verbose": True,
diff --git a/examples/smart_scraper_graph/ollama/smart_scraper_multi_concat_ollama.py b/examples/smart_scraper_graph/ollama/smart_scraper_multi_concat_ollama.py
index 566be922..a29ac3fc 100644
--- a/examples/smart_scraper_graph/ollama/smart_scraper_multi_concat_ollama.py
+++ b/examples/smart_scraper_graph/ollama/smart_scraper_multi_concat_ollama.py
@@ -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,
diff --git a/examples/smart_scraper_graph/ollama/smart_scraper_multi_lite_ollama.py b/examples/smart_scraper_graph/ollama/smart_scraper_multi_lite_ollama.py
index 90c58f9d..15055f96 100644
--- a/examples/smart_scraper_graph/ollama/smart_scraper_multi_lite_ollama.py
+++ b/examples/smart_scraper_graph/ollama/smart_scraper_multi_lite_ollama.py
@@ -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,
diff --git a/examples/smart_scraper_graph/ollama/smart_scraper_multi_ollama.py b/examples/smart_scraper_graph/ollama/smart_scraper_multi_ollama.py
index c42bb627..04eb0e67 100644
--- a/examples/smart_scraper_graph/ollama/smart_scraper_multi_ollama.py
+++ b/examples/smart_scraper_graph/ollama/smart_scraper_multi_ollama.py
@@ -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,
diff --git a/examples/smart_scraper_graph/ollama/smart_scraper_ollama.py b/examples/smart_scraper_graph/ollama/smart_scraper_ollama.py
index 61294eaf..1a766905 100644
--- a/examples/smart_scraper_graph/ollama/smart_scraper_ollama.py
+++ b/examples/smart_scraper_graph/ollama/smart_scraper_ollama.py
@@ -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,
diff --git a/examples/smart_scraper_graph/ollama/smart_scraper_schema_ollama.py b/examples/smart_scraper_graph/ollama/smart_scraper_schema_ollama.py
index 38eeaeb5..9cbf65f2 100644
--- a/examples/smart_scraper_graph/ollama/smart_scraper_schema_ollama.py
+++ b/examples/smart_scraper_graph/ollama/smart_scraper_schema_ollama.py
@@ -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,
diff --git a/scrapegraphai/nodes/merge_answers_node.py b/scrapegraphai/nodes/merge_answers_node.py
index 77eb1587..b867b3e0 100644
--- a/scrapegraphai/nodes/merge_answers_node.py
+++ b/scrapegraphai/nodes/merge_answers_node.py
@@ -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)
)