diff --git a/scrapegraphai/nodes/generate_answer_node.py b/scrapegraphai/nodes/generate_answer_node.py index f7f20cf8..d50b72db 100644 --- a/scrapegraphai/nodes/generate_answer_node.py +++ b/scrapegraphai/nodes/generate_answer_node.py @@ -87,6 +87,37 @@ class GenerateAnswerNode(BaseNode): self.logger.error(f"Error during chain execution: {str(e)}") raise + def process(self, state: dict) -> dict: + """Process the input state and generate an answer.""" + user_prompt = state.get("user_prompt") + # Check for content in different possible state keys + content = ( + state.get("relevant_chunks") + or state.get("parsed_doc") + or state.get("doc") + or state.get("content") + ) + + if not content: + raise ValueError("No content found in state to generate answer from") + + if not user_prompt: + raise ValueError("No user prompt found in state") + + # Create the chain input with both content and question keys + chain_input = { + "content": content, + "question": user_prompt + } + + try: + response = self.invoke_with_timeout(self.chain, chain_input, self.timeout) + state.update({self.output[0]: response}) + return state + except Exception as e: + self.logger.error(f"Error in GenerateAnswerNode: {str(e)}") + raise + def execute(self, state: dict) -> dict: """ Executes the GenerateAnswerNode. diff --git a/uv.lock b/uv.lock index 000a667c..415aade0 100644 --- a/uv.lock +++ b/uv.lock @@ -3446,7 +3446,7 @@ wheels = [ [[package]] name = "scrapegraphai" -version = "1.36.0" +version = "1.39.0b1" source = { editable = "." } dependencies = [ { name = "async-timeout", version = "4.0.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" },