Skip to content

Commit 3ee1743

Browse files
committed
update prompts
1 parent d419b0a commit 3ee1743

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed

scrapegraphai/nodes/generate_answer_csv_node.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,15 @@ def execute(self, state):
102102
output_parser = JsonOutputParser(pydantic_object=self.node_config["schema"])
103103
else:
104104
output_parser = JsonOutputParser()
105-
105+
106+
template_no_chunks_csv_prompt = template_no_chunks_csv
107+
template_chunks_csv_prompt = template_chunks_csv
108+
template_merge_csv_prompt = template_merge_csv
109+
106110
if self.additional_info is not None:
107-
template_no_chunks_csv += self.additional_info
108-
template_chunks_csv += self.additional_info
109-
template_merge_csv += self.additional_info
111+
template_no_chunks_csv_prompt = self.additional_info + template_no_chunks_csv
112+
template_chunks_csv_prompt = self.additional_info + template_chunks_csv
113+
template_merge_csv_prompt = self.additional_info + template_merge_csv
110114

111115
format_instructions = output_parser.get_format_instructions()
112116

@@ -118,7 +122,7 @@ def execute(self, state):
118122
):
119123
if len(doc) == 1:
120124
prompt = PromptTemplate(
121-
template=template_no_chunks_csv,
125+
template=template_no_chunks_csv_prompt,
122126
input_variables=["question"],
123127
partial_variables={
124128
"context": chunk.page_content,
@@ -130,7 +134,7 @@ def execute(self, state):
130134
answer = chain.invoke({"question": user_prompt})
131135
else:
132136
prompt = PromptTemplate(
133-
template=template_chunks_csv,
137+
template=template_chunks_csv_prompt,
134138
input_variables=["question"],
135139
partial_variables={
136140
"context": chunk.page_content,
@@ -150,7 +154,7 @@ def execute(self, state):
150154
answer = map_chain.invoke({"question": user_prompt})
151155
# Merge the answers from the chunks
152156
merge_prompt = PromptTemplate(
153-
template=template_merge_csv,
157+
template=template_merge_csv_prompt,
154158
input_variables=["context", "question"],
155159
partial_variables={"format_instructions": format_instructions},
156160
)

scrapegraphai/nodes/generate_answer_node.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ def execute(self, state: dict) -> dict:
100100
template_merge_prompt = template_merge
101101

102102
if self.additional_info is not None:
103-
template_no_chunks_prompt += self.additional_info
104-
template_chunks_prompt += self.additional_info
105-
template_merge_prompt += self.additional_info
103+
template_no_chunks_prompt = self.additional_info + template_no_chunks_prompt
104+
template_chunks_prompt = self.additional_info + template_chunks_prompt
105+
template_merge_prompt = self.additional_info + template_merge_prompt
106106

107107
chains_dict = {}
108108

scrapegraphai/nodes/generate_answer_omni_node.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,14 @@ def execute(self, state: dict) -> dict:
8787
output_parser = JsonOutputParser(pydantic_object=self.node_config["schema"])
8888
else:
8989
output_parser = JsonOutputParser()
90+
template_no_chunk_omni_prompt = template_no_chunk_omni
91+
template_chunks_omni_prompt = template_chunks_omni
92+
template_merge_omni_prompt= template_merge_omni
9093

9194
if self.additional_info is not None:
92-
template_no_chunk_omni += self.additional_info
93-
template_chunks_omni += self.additional_info
94-
template_merge_omni += self.additional_info
95+
template_no_chunk_omni_prompt = self.additional_info + template_no_chunk_omni_prompt
96+
template_chunks_omni_prompt = self.additional_info + template_chunks_omni_prompt
97+
template_merge_omni_prompt = self.additional_info + template_merge_omni_prompt
9598

9699
format_instructions = output_parser.get_format_instructions()
97100

@@ -104,7 +107,7 @@ def execute(self, state: dict) -> dict:
104107
):
105108
if len(doc) == 1:
106109
prompt = PromptTemplate(
107-
template=template_no_chunk_omni,
110+
template=template_no_chunk_omni_prompt,
108111
input_variables=["question"],
109112
partial_variables={
110113
"context": chunk.page_content,
@@ -117,7 +120,7 @@ def execute(self, state: dict) -> dict:
117120
answer = chain.invoke({"question": user_prompt})
118121
else:
119122
prompt = PromptTemplate(
120-
template=template_chunks_omni,
123+
template=template_chunks_omni_prompt,
121124
input_variables=["question"],
122125
partial_variables={
123126
"context": chunk.page_content,
@@ -137,7 +140,7 @@ def execute(self, state: dict) -> dict:
137140
answer = map_chain.invoke({"question": user_prompt})
138141
# Merge the answers from the chunks
139142
merge_prompt = PromptTemplate(
140-
template=template_merge_omni,
143+
template=template_merge_omni_prompt,
141144
input_variables=["context", "question"],
142145
partial_variables={
143146
"format_instructions": format_instructions,

scrapegraphai/nodes/generate_answer_pdf_node.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ def execute(self, state):
103103
output_parser = JsonOutputParser(pydantic_object=self.node_config["schema"])
104104
else:
105105
output_parser = JsonOutputParser()
106-
106+
template_no_chunks_pdf_prompt = template_no_chunks_pdf
107+
template_chunks_pdf_prompt = template_chunks_pdf
108+
template_merge_pdf_prompt = template_merge_pdf
109+
107110
if self.additional_info is not None:
108-
template_no_chunks_pdf += self.additional_info
109-
template_chunks_pdf += self.additional_info
110-
template_merge_pdf += self.additional_info
111+
template_no_chunks_pdf_prompt = self.additional_info + template_no_chunks_pdf_prompt
112+
template_chunks_pdf_prompt = self.additional_info + template_chunks_pdf_prompt
113+
template_merge_pdf_prompt = self.additional_info + template_merge_pdf_prompt
111114

112115
format_instructions = output_parser.get_format_instructions()
113116

@@ -118,7 +121,7 @@ def execute(self, state):
118121
):
119122
if len(doc) == 1:
120123
prompt = PromptTemplate(
121-
template=template_no_chunks_pdf,
124+
template=template_no_chunks_pdf_prompt,
122125
input_variables=["question"],
123126
partial_variables={
124127
"context":chunk.page_content,
@@ -130,7 +133,7 @@ def execute(self, state):
130133

131134
else:
132135
prompt = PromptTemplate(
133-
template=template_chunks_pdf,
136+
template=template_chunks_pdf_prompt,
134137
input_variables=["question"],
135138
partial_variables={
136139
"context":chunk,
@@ -150,7 +153,7 @@ def execute(self, state):
150153
answer = map_chain.invoke({"question": user_prompt})
151154
# Merge the answers from the chunks
152155
merge_prompt = PromptTemplate(
153-
template=template_merge_pdf,
156+
template=template_merge_pdf_prompt,
154157
input_variables=["context", "question"],
155158
partial_variables={"format_instructions": format_instructions},
156159
)

0 commit comments

Comments
 (0)