Skip to content

Commit 61a51d4

Browse files
authored
Merge pull request #466 from ScrapeGraphAI/refactoring_convert_to_md
refactoring of generate answer node
2 parents cb02740 + 032a491 commit 61a51d4

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

examples/local_models/smart_scraper_ollama.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
smart_scraper_graph = SmartScraperGraph(
3131
prompt="List me all the titles",
32-
source="https://sport.sky.it/nba?gr=www",
32+
source="https://perinim.github.io/projects",
3333
config=graph_config
3434
)
3535

scrapegraphai/nodes/base_node.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def update_config(self, params: dict, overwrite: bool = False):
8888
param (dict): The dictionary to update node_config with.
8989
overwrite (bool): Flag indicating if the values of node_config should be overwritten if their value is not None.
9090
"""
91-
9291
for key, val in params.items():
9392
if hasattr(self, key) and not overwrite:
9493
continue

scrapegraphai/nodes/generate_answer_csv_node.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ def execute(self, state):
132132

133133
chain = prompt | self.llm_model | output_parser
134134
answer = chain.invoke({"question": user_prompt})
135-
else:
136-
prompt = PromptTemplate(
135+
break
136+
137+
prompt = PromptTemplate(
137138
template=template_chunks_csv_prompt,
138139
input_variables=["question"],
139140
partial_variables={

scrapegraphai/nodes/generate_answer_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def execute(self, state: dict) -> dict:
119119
"format_instructions": format_instructions})
120120
chain = prompt | self.llm_model | output_parser
121121
answer = chain.invoke({"question": user_prompt})
122+
break
122123

123-
else:
124124
prompt = PromptTemplate(
125125
template=template_chunks_prompt,
126126
input_variables=["question"],

scrapegraphai/nodes/generate_answer_omni_node.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ def execute(self, state: dict) -> dict:
118118

119119
chain = prompt | self.llm_model | output_parser
120120
answer = chain.invoke({"question": user_prompt})
121-
else:
122-
prompt = PromptTemplate(
121+
break
122+
123+
prompt = PromptTemplate(
123124
template=template_chunks_omni_prompt,
124125
input_variables=["question"],
125126
partial_variables={

scrapegraphai/nodes/generate_answer_pdf_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def execute(self, state):
131131
chain = prompt | self.llm_model | output_parser
132132
answer = chain.invoke({"question": user_prompt})
133133

134-
else:
135-
prompt = PromptTemplate(
134+
break
135+
prompt = PromptTemplate(
136136
template=template_chunks_pdf_prompt,
137137
input_variables=["question"],
138138
partial_variables={

scrapegraphai/nodes/parse_node.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,23 @@ def execute(self, state: dict) -> dict:
7575

7676
chunks = chunk(text=docs_transformed.page_content,
7777
chunk_size= self.node_config.get("chunk_size", 4096)-250,
78-
token_counter=lambda x: len(x.split()),
78+
token_counter=lambda x: len(x),
7979
memoize=False)
8080
else:
8181
docs_transformed = docs_transformed[0]
8282

8383
if type(docs_transformed) == Document:
8484
chunks = chunk(text=docs_transformed.page_content,
8585
chunk_size= self.node_config.get("chunk_size", 4096)-250,
86-
token_counter=lambda x: len(x.split()),
86+
token_counter=lambda x: len(x),
8787
memoize=False)
8888
else:
89-
89+
9090
chunks = chunk(text=docs_transformed,
9191
chunk_size= self.node_config.get("chunk_size", 4096)-250,
92-
token_counter=lambda x: len(x.split()),
92+
token_counter=lambda x: len(x),
9393
memoize=False)
94-
94+
9595
state.update({self.output[0]: chunks})
9696

97-
return state
97+
return state

0 commit comments

Comments
 (0)