Skip to content

Commit 0b12589

Browse files
reasoning node prompt refinement
1 parent 3228f7d commit 0b12589

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

scrapegraphai/nodes/reasoning_node.py

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,42 +72,42 @@ def execute(self, state: dict) -> dict:
7272
self.logger.info(f"--- Executing {self.node_name} Node ---")
7373

7474
TEMPLATE_REASONING = """
75-
**Task**: Analyze the user's request and the provided JSON schema to clearly map the desired data extraction.\n
76-
Break down the user's request into key components, and then explicitly connect these components to the
77-
corresponding elements within the JSON schema.
75+
**Task**: Analyze the user's request and the provided JSON schema to guide an LLM in extracting information directly from HTML.
7876
7977
**User's Request**:
8078
{user_input}
8179
82-
**Desired JSON Output Schema**:
80+
**Target JSON Schema**:
8381
```json
8482
{json_schema}
8583
```
8684
8785
**Analysis Instructions**:
88-
1. **Break Down User Request:**
89-
* Clearly identify the core entities or data types the user is asking for.\n
90-
* Highlight any specific attributes or relationships mentioned in the request.\n
86+
1. **Interpret User Request:**
87+
* Identify the key information types or entities the user is seeking.
88+
* Note any specific attributes, relationships, or constraints mentioned.
9189
9290
2. **Map to JSON Schema**:
93-
* For each identified element in the user request, pinpoint its exact counterpart in the JSON schema.\n
94-
* Explain how the schema structure accommodates the user's needs.
95-
* If applicable, mention any schema elements that are not directly addressed in the user's request.\n
91+
* For each identified element in the user request, locate its corresponding field in the JSON schema.
92+
* Explain how the schema structure represents the requested information.
93+
* Highlight any relevant schema elements not explicitly mentioned in the user's request.
9694
97-
This analysis will be used to guide the HTML structure examination and ultimately inform the code generation process.\n
98-
Please generate only the analysis and no other text.
95+
3. **Data Transformation Guidance**:
96+
* Provide guidance on any necessary transformations to align extracted data with the JSON schema requirements.
9997
100-
**Response**:
98+
This analysis will be used to instruct an LLM that has the HTML content in its context. The LLM will use this guidance to extract the information and return it directly in the specified JSON format.
99+
100+
**Reasoning Output**:
101+
[Your detailed analysis based on the above instructions]
101102
"""
102103

103104
TEMPLATE_REASONING_WITH_CONTEXT = """
104-
**Task**: Analyze the user's request, the provided JSON schema, and the additional context the user provided to clearly map the desired data extraction.\n
105-
Break down the user's request into key components, and then explicitly connect these components to the corresponding elements within the JSON schema.\n
105+
**Task**: Analyze the user's request, provided JSON schema, and additional context to guide an LLM in extracting information directly from HTML.
106106
107107
**User's Request**:
108108
{user_input}
109109
110-
**Desired JSON Output Schema**:
110+
**Target JSON Schema**:
111111
```json
112112
{json_schema}
113113
```
@@ -116,19 +116,28 @@ def execute(self, state: dict) -> dict:
116116
{additional_context}
117117
118118
**Analysis Instructions**:
119-
1. **Break Down User Request:**
120-
* Clearly identify the core entities or data types the user is asking for.\n
121-
* Highlight any specific attributes or relationships mentioned in the request.\n
119+
1. **Interpret User Request and Context:**
120+
* Identify the key information types or entities the user is seeking.
121+
* Note any specific attributes, relationships, or constraints mentioned.
122+
* Incorporate insights from the additional context to refine understanding of the task.
122123
123124
2. **Map to JSON Schema**:
124-
* For each identified element in the user request, pinpoint its exact counterpart in the JSON schema.\n
125-
* Explain how the schema structure accommodates the user's needs.\n
126-
* If applicable, mention any schema elements that are not directly addressed in the user's request.\n
125+
* For each identified element in the user request, locate its corresponding field in the JSON schema.
126+
* Explain how the schema structure represents the requested information.
127+
* Highlight any relevant schema elements not explicitly mentioned in the user's request.
128+
129+
3. **Extraction Strategy**:
130+
* Based on the additional context, suggest specific strategies for locating and extracting the required information from the HTML.
131+
* Highlight any potential challenges or special considerations mentioned in the context.
132+
133+
4. **Data Transformation Guidance**:
134+
* Provide guidance on any necessary transformations to align extracted data with the JSON schema requirements.
135+
* Note any special formatting, validation, or business logic considerations from the additional context.
127136
128-
This analysis will be used to guide the HTML structure examination and ultimately inform the code generation process.\n
129-
Please generate only the analysis and no other text.
137+
This analysis will be used to instruct an LLM that has the HTML content in its context. The LLM will use this guidance to extract the information and return it directly in the specified JSON format.
130138
131-
**Response**:
139+
**Reasoning Output**:
140+
[Your detailed analysis based on the above instructions, incorporating insights from the additional context]
132141
"""
133142

134143
user_prompt = state['user_prompt']

0 commit comments

Comments
 (0)