Skip to content

Commit c2c2e65

Browse files
committed
Update generate_answer_node.py
1 parent c6edeee commit c2c2e65

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

scrapegraphai/nodes/generate_answer_node.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,22 @@ def execute(self, state: dict) -> dict:
8888
# Initialize the output parser
8989
if self.node_config.get("schema", None) is not None:
9090
output_parser = JsonOutputParser(pydantic_object=self.node_config["schema"])
91+
if isinstance(self.llm_model, ChatOpenAI):
92+
self.llm_model = self.llm_model.with_structured_output(self.node_config["schema"])
93+
9194
else:
9295
output_parser = JsonOutputParser()
9396

9497
format_instructions = output_parser.get_format_instructions()
9598

99+
template_no_chunks_prompt = template_no_chunks
100+
template_chunks_prompt = template_chunks
101+
template_merge_prompt = template_merge
102+
96103
if isinstance(self.llm_model, ChatOpenAI) and not self.script_creator or self.force and not self.script_creator or self.is_md_scraper:
97104
template_no_chunks_prompt = template_no_chunks_md
98105
template_chunks_prompt = template_chunks_md
99106
template_merge_prompt = template_merge_md
100-
else:
101-
template_no_chunks_prompt = template_no_chunks
102-
template_chunks_prompt = template_chunks
103-
template_merge_prompt = template_merge
104107

105108
if self.additional_info is not None:
106109
template_no_chunks_prompt = self.additional_info + template_no_chunks_prompt

0 commit comments

Comments
 (0)