Skip to content

Commit 2c0b459

Browse files
committed
feat: add refactoring of merge and parse
1 parent 7320c71 commit 2c0b459

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

scrapegraphai/nodes/generate_answer_node.py

+31
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,37 @@ def invoke_with_timeout(self, chain, inputs, timeout):
8787
self.logger.error(f"Error during chain execution: {str(e)}")
8888
raise
8989

90+
def process(self, state: dict) -> dict:
91+
"""Process the input state and generate an answer."""
92+
user_prompt = state.get("user_prompt")
93+
# Check for content in different possible state keys
94+
content = (
95+
state.get("relevant_chunks")
96+
or state.get("parsed_doc")
97+
or state.get("doc")
98+
or state.get("content")
99+
)
100+
101+
if not content:
102+
raise ValueError("No content found in state to generate answer from")
103+
104+
if not user_prompt:
105+
raise ValueError("No user prompt found in state")
106+
107+
# Create the chain input with both content and question keys
108+
chain_input = {
109+
"content": content,
110+
"question": user_prompt
111+
}
112+
113+
try:
114+
response = self.invoke_with_timeout(self.chain, chain_input, self.timeout)
115+
state.update({self.output[0]: response})
116+
return state
117+
except Exception as e:
118+
self.logger.error(f"Error in GenerateAnswerNode: {str(e)}")
119+
raise
120+
90121
def execute(self, state: dict) -> dict:
91122
"""
92123
Executes the GenerateAnswerNode.

uv.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)