Skip to content

Commit d55f6be

Browse files
committed
fix: node refiner + examples
1 parent bb375cd commit d55f6be

File tree

8 files changed

+29
-35
lines changed

8 files changed

+29
-35
lines changed

examples/openai/script_generator_schema_openai.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
"""
44

55
import os
6+
from typing import List
67
from dotenv import load_dotenv
8+
from pydantic import BaseModel, Field
79
from scrapegraphai.graphs import ScriptCreatorGraph
810
from scrapegraphai.utils import prettify_exec_info
911

10-
from pydantic import BaseModel, Field
11-
from typing import List
12-
1312
load_dotenv()
1413

1514
# ************************************************

requirements-dev.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
# features: []
77
# all-features: false
88
# with-sources: false
9-
# generate-hashes: false
10-
# universal: false
119

1210
-e file:.
1311
aiofiles==24.1.0
@@ -131,7 +129,6 @@ graphviz==0.20.3
131129
# via burr
132130
greenlet==3.0.3
133131
# via playwright
134-
# via sqlalchemy
135132
grpcio==1.65.4
136133
# via google-api-core
137134
# via grpcio-status
@@ -501,7 +498,5 @@ urllib3==1.26.19
501498
# via requests
502499
uvicorn==0.30.5
503500
# via burr
504-
watchdog==4.0.2
505-
# via streamlit
506501
yarl==1.9.4
507502
# via aiohttp

requirements.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
# features: []
77
# all-features: false
88
# with-sources: false
9-
# generate-hashes: false
10-
# universal: false
119

1210
-e file:.
1311
aiohttp==3.9.5
@@ -86,7 +84,6 @@ googleapis-common-protos==1.63.2
8684
# via grpcio-status
8785
greenlet==3.0.3
8886
# via playwright
89-
# via sqlalchemy
9087
grpcio==1.65.1
9188
# via google-api-core
9289
# via grpcio-status

scrapegraphai/graphs/code_generator_graph.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pydantic import BaseModel
77
from .base_graph import BaseGraph
88
from .abstract_graph import AbstractGraph
9+
from ..utils.save_code_to_file import save_code_to_file
910
from ..nodes import (
1011
FetchNode,
1112
ParseNode,
@@ -172,17 +173,6 @@ def run(self) -> str:
172173
else:
173174
filename = self.config.get("filename")
174175

175-
self.save_code_to_file(generated_code, filename)
176+
save_code_to_file(generated_code, filename)
176177

177178
return generated_code
178-
179-
def save_code_to_file(self, code: str, filename:str) -> None:
180-
"""
181-
Saves the generated code to a Python file.
182-
183-
Args:
184-
code (str): The generated code to be saved.
185-
filename (str): name of the output file
186-
"""
187-
with open(filename, "w") as file:
188-
file.write(code)

scrapegraphai/nodes/html_analyzer_node.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,15 @@ def execute(self, state: dict) -> dict:
7373
KeyError: If the input keys are not found in the state, indicating
7474
that the necessary information for generating an answer is missing.
7575
"""
76-
7776
self.logger.info(f"--- Executing {self.node_name} Node ---")
7877

7978
input_keys = self.get_input_keys(state)
80-
8179
input_data = [state[key] for key in input_keys]
82-
refined_prompt = input_data[0] # get refined user prompt
83-
html = input_data[1] # get HTML code
84-
85-
reduced_html = reduce_html(html[0].page_content, self.node_config.get("reduction", 0)) # reduce HTML code
86-
87-
if self.additional_info is not None: # use additional context if present
80+
refined_prompt = input_data[0]
81+
html = input_data[1]
82+
reduced_html = reduce_html(html[0].page_content, self.node_config.get("reduction", 0))
83+
84+
if self.additional_info is not None:
8885
prompt = PromptTemplate(
8986
template=TEMPLATE_HTML_ANALYSIS_WITH_CONTEXT,
9087
partial_variables={"initial_analysis": refined_prompt,
@@ -103,4 +100,3 @@ def execute(self, state: dict) -> dict:
103100

104101
state.update({self.output[0]: html_analysis, self.output[1]: reduced_html})
105102
return state
106-

scrapegraphai/nodes/prompt_refiner_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def execute(self, state: dict) -> dict:
7979
KeyError: If the input keys are not found in the state, indicating
8080
that the necessary information for generating an answer is missing.
8181
"""
82-
82+
8383
self.logger.info(f"--- Executing {self.node_name} Node ---")
8484

8585
user_prompt = state['user_prompt']

scrapegraphai/utils/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
from .dict_content_compare import are_content_equal
2424
from .code_error_analysis import (syntax_focused_analysis, execution_focused_analysis,
2525
validation_focused_analysis, semantic_focused_analysis)
26-
from .code_error_correction import (syntax_focused_code_generation, execution_focused_code_generation,
27-
validation_focused_code_generation, semantic_focused_code_generation)
26+
from .code_error_correction import (syntax_focused_code_generation,
27+
execution_focused_code_generation,
28+
validation_focused_code_generation,
29+
semantic_focused_code_generation)
30+
from .save_code_to_file import save_code_to_file
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
save_code_to_file module
3+
"""
4+
5+
def save_code_to_file(code: str, filename:str) -> None:
6+
"""
7+
Saves the generated code to a Python file.
8+
9+
Args:
10+
code (str): The generated code to be saved.
11+
filename (str): name of the output file
12+
"""
13+
with open(filename, "w") as file:
14+
file.write(code)

0 commit comments

Comments
 (0)