Skip to content

refactoring of generate answer node #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/local_models/smart_scraper_ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

smart_scraper_graph = SmartScraperGraph(
prompt="List me all the titles",
source="https://sport.sky.it/nba?gr=www",
source="https://perinim.github.io/projects",
config=graph_config
)

Expand Down
1 change: 0 additions & 1 deletion scrapegraphai/nodes/base_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def update_config(self, params: dict, overwrite: bool = False):
param (dict): The dictionary to update node_config with.
overwrite (bool): Flag indicating if the values of node_config should be overwritten if their value is not None.
"""

for key, val in params.items():
if hasattr(self, key) and not overwrite:
continue
Expand Down
5 changes: 3 additions & 2 deletions scrapegraphai/nodes/generate_answer_csv_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ def execute(self, state):

chain = prompt | self.llm_model | output_parser
answer = chain.invoke({"question": user_prompt})
else:
prompt = PromptTemplate(
break

prompt = PromptTemplate(
template=template_chunks_csv_prompt,
input_variables=["question"],
partial_variables={
Expand Down
2 changes: 1 addition & 1 deletion scrapegraphai/nodes/generate_answer_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def execute(self, state: dict) -> dict:
"format_instructions": format_instructions})
chain = prompt | self.llm_model | output_parser
answer = chain.invoke({"question": user_prompt})
break

else:
prompt = PromptTemplate(
template=template_chunks_prompt,
input_variables=["question"],
Expand Down
5 changes: 3 additions & 2 deletions scrapegraphai/nodes/generate_answer_omni_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def execute(self, state: dict) -> dict:

chain = prompt | self.llm_model | output_parser
answer = chain.invoke({"question": user_prompt})
else:
prompt = PromptTemplate(
break

prompt = PromptTemplate(
template=template_chunks_omni_prompt,
input_variables=["question"],
partial_variables={
Expand Down
4 changes: 2 additions & 2 deletions scrapegraphai/nodes/generate_answer_pdf_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def execute(self, state):
chain = prompt | self.llm_model | output_parser
answer = chain.invoke({"question": user_prompt})

else:
prompt = PromptTemplate(
break
prompt = PromptTemplate(
template=template_chunks_pdf_prompt,
input_variables=["question"],
partial_variables={
Expand Down
12 changes: 6 additions & 6 deletions scrapegraphai/nodes/parse_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ def execute(self, state: dict) -> dict:

chunks = chunk(text=docs_transformed.page_content,
chunk_size= self.node_config.get("chunk_size", 4096)-250,
token_counter=lambda x: len(x.split()),
token_counter=lambda x: len(x),
memoize=False)
else:
docs_transformed = docs_transformed[0]

if type(docs_transformed) == Document:
chunks = chunk(text=docs_transformed.page_content,
chunk_size= self.node_config.get("chunk_size", 4096)-250,
token_counter=lambda x: len(x.split()),
token_counter=lambda x: len(x),
memoize=False)
else:

chunks = chunk(text=docs_transformed,
chunk_size= self.node_config.get("chunk_size", 4096)-250,
token_counter=lambda x: len(x.split()),
token_counter=lambda x: len(x),
memoize=False)

state.update({self.output[0]: chunks})

return state
return state
Loading