Skip to content

Commit e846a14

Browse files
committed
fix: bug on generate answer node
1 parent 30e6b59 commit e846a14

File tree

4 files changed

+138
-72
lines changed

4 files changed

+138
-72
lines changed

examples/smart_scraper_graph/ollama/smart_scraper_ollama.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
graph_config = {
1313
"llm": {
14-
"model": "ollama/llama3.2:3b",
14+
"model": "ollama/llama3.2",
1515
"temperature": 0,
1616
# "base_url": "http://localhost:11434", # set ollama URL arbitrarily
1717
"model_tokens": 4096,
@@ -24,7 +24,7 @@
2424
# Create the SmartScraperGraph instance and run it
2525
# ************************************************
2626
smart_scraper_graph = SmartScraperGraph(
27-
prompt="Find some information about what does the company do and the list of founders.",
27+
prompt="Find some information about the founders.",
2828
source="https://scrapegraphai.com/",
2929
config=graph_config,
3030
)

scrapegraphai/nodes/generate_answer_node.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,8 @@ def execute(self, state: dict) -> dict:
180180
if len(doc) == 1:
181181
prompt = PromptTemplate(
182182
template=template_no_chunks_prompt,
183-
input_variables=["question"],
183+
input_variables=["content", "question"],
184184
partial_variables={
185-
"context": doc,
186185
"format_instructions": format_instructions,
187186
},
188187
)
@@ -192,7 +191,7 @@ def execute(self, state: dict) -> dict:
192191

193192
try:
194193
answer = self.invoke_with_timeout(
195-
chain, {"question": user_prompt}, self.timeout
194+
chain, {"content": doc, "question": user_prompt}, self.timeout
196195
)
197196
except (Timeout, json.JSONDecodeError) as e:
198197
error_msg = (
@@ -216,7 +215,7 @@ def execute(self, state: dict) -> dict:
216215
template=template_chunks_prompt,
217216
input_variables=["question"],
218217
partial_variables={
219-
"context": chunk,
218+
"content": chunk,
220219
"chunk_id": i + 1,
221220
"format_instructions": format_instructions,
222221
},
@@ -242,7 +241,7 @@ def execute(self, state: dict) -> dict:
242241

243242
merge_prompt = PromptTemplate(
244243
template=template_merge_prompt,
245-
input_variables=["context", "question"],
244+
input_variables=["content", "question"],
246245
partial_variables={"format_instructions": format_instructions},
247246
)
248247

@@ -252,7 +251,7 @@ def execute(self, state: dict) -> dict:
252251
try:
253252
answer = self.invoke_with_timeout(
254253
merge_chain,
255-
{"context": batch_results, "question": user_prompt},
254+
{"content": batch_results, "question": user_prompt},
256255
self.timeout,
257256
)
258257
except (Timeout, json.JSONDecodeError) as e:

scrapegraphai/prompts/generate_answer_node_prompts.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
and things that will invalidate the dictionary. \n
1414
Do not start the response with ```json because it will invalidate the postprocessing. \n
1515
OUTPUT INSTRUCTIONS: {format_instructions}\n
16-
Content of {chunk_id}: {context}. \n
16+
Content of {chunk_id}: {content}. \n
1717
"""
1818

1919
TEMPLATE_NO_CHUNKS_MD = """
@@ -27,7 +27,7 @@
2727
Do not start the response with ```json because it will invalidate the postprocessing. \n
2828
OUTPUT INSTRUCTIONS: {format_instructions}\n
2929
USER QUESTION: {question}\n
30-
WEBSITE CONTENT: {context}\n
30+
WEBSITE CONTENT: {content}\n
3131
"""
3232

3333
TEMPLATE_MERGE_MD = """
@@ -42,7 +42,7 @@
4242
Do not start the response with ```json because it will invalidate the postprocessing. \n
4343
OUTPUT INSTRUCTIONS: {format_instructions}\n
4444
USER QUESTION: {question}\n
45-
WEBSITE CONTENT: {context}\n
45+
WEBSITE CONTENT: {content}\n
4646
"""
4747

4848
TEMPLATE_CHUNKS = """
@@ -56,7 +56,7 @@
5656
and things that will invalidate the dictionary. \n
5757
Do not start the response with ```json because it will invalidate the postprocessing. \n
5858
OUTPUT INSTRUCTIONS: {format_instructions}\n
59-
Content of {chunk_id}: {context}. \n
59+
Content of {chunk_id}: {content}. \n
6060
"""
6161

6262
TEMPLATE_NO_CHUNKS = """
@@ -70,7 +70,7 @@
7070
Do not start the response with ```json because it will invalidate the postprocessing. \n
7171
OUTPUT INSTRUCTIONS: {format_instructions}\n
7272
USER QUESTION: {question}\n
73-
WEBSITE CONTENT: {context}\n
73+
WEBSITE CONTENT: {content}\n
7474
"""
7575

7676
TEMPLATE_MERGE = """
@@ -84,7 +84,7 @@
8484
Do not start the response with ```json because it will invalidate the postprocessing. \n
8585
OUTPUT INSTRUCTIONS: {format_instructions}\n
8686
USER QUESTION: {question}\n
87-
WEBSITE CONTENT: {context}\n
87+
WEBSITE CONTENT: {content}\n
8888
"""
8989

9090
REGEN_ADDITIONAL_INFO = """

0 commit comments

Comments
 (0)