mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-07-18 21:00:31 +08:00
feat: add refactoring of merge and parse
This commit is contained in:
parent
7320c71cf7
commit
2c0b4591ae
@ -87,6 +87,37 @@ class GenerateAnswerNode(BaseNode):
|
|||||||
self.logger.error(f"Error during chain execution: {str(e)}")
|
self.logger.error(f"Error during chain execution: {str(e)}")
|
||||||
raise
|
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:
|
def execute(self, state: dict) -> dict:
|
||||||
"""
|
"""
|
||||||
Executes the GenerateAnswerNode.
|
Executes the GenerateAnswerNode.
|
||||||
|
|||||||
2
uv.lock
2
uv.lock
@ -3446,7 +3446,7 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scrapegraphai"
|
name = "scrapegraphai"
|
||||||
version = "1.36.0"
|
version = "1.39.0b1"
|
||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "async-timeout", version = "4.0.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" },
|
{ name = "async-timeout", version = "4.0.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" },
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user