Skip to content

Commit ae92939

Browse files
committed
refactoring for pylint score
1 parent 69fb6ce commit ae92939

File tree

12 files changed

+48
-34
lines changed

12 files changed

+48
-34
lines changed

examples/custom_graph_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
)
4141

4242
# execute the graph
43-
inputs = {"user_input": "Give me the news", "url": "https://www.ansa.it/sito/notizie/topnews/index.shtml"}
43+
inputs = {"user_input": "Give me the news",
44+
"url": "https://www.ansa.it/sito/notizie/topnews/index.shtml"}
4445
result = graph.execute(inputs)
4546

4647
# get the answer from the result

examples/graph_builder_example.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Example of graph builder
3+
"""
14
import os
25
from dotenv import load_dotenv
36
from scrapegraphai.builders import GraphBuilder
@@ -14,8 +17,8 @@
1417
}
1518

1619
# Example usage of GraphBuilder
17-
user_prompt = "Extract the news and generate a text summary with a voiceover."
18-
graph_builder = GraphBuilder(user_prompt, llm_config)
20+
USER_PROMPT = "Extract the news and generate a text summary with a voiceover."
21+
graph_builder = GraphBuilder(USER_PROMPT, llm_config)
1922
graph_json = graph_builder.build_graph()
2023

2124
# Convert the resulting JSON to Graphviz format

examples/smart_scraper_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
"model_name": "gpt-3.5-turbo",
1616
}
1717

18-
# Define URL and prompt
19-
url = "https://perinim.github.io/projects/"
20-
prompt = "List me all the titles and project descriptions"
18+
# Define URL and PROMPT
19+
URL = "https://perinim.github.io/projects/"
20+
PROMPT = "List me all the titles and project descriptions"
2121

2222
# Create the SmartScraperGraph instance
23-
smart_scraper_graph = SmartScraperGraph(prompt, url, llm_config)
23+
smart_scraper_graph = SmartScraperGraph(PROMPT, URL, llm_config)
2424

2525
answer = smart_scraper_graph.run()
2626
print(answer)

examples/speech_summary_graph_example.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
curr_dir = os.path.dirname(os.path.realpath(__file__))
1919
output_file_path = os.path.join(curr_dir, "website_summary.mp3")
2020

21-
speech_summary_graph = SpeechSummaryGraph("Make a summary of the webpage to be converted to audio for blind people.",
22-
"https://perinim.github.io/projects/", llm_config,
23-
output_file_path)
21+
speech_summary_graph = SpeechSummaryGraph("""Make a summary of the webpage to be
22+
converted to audio for blind people.""",
23+
"https://perinim.github.io/projects/", llm_config,
24+
output_file_path)
2425

2526
final_state = speech_summary_graph.run()
2627
print(final_state.get("answer", "No answer found."))

scrapegraphai/builders/graph_builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def _generate_nodes_description(self):
8181
"""
8282

8383
return "\n".join([
84-
f'- {node}: {data["description"]} (Type: {data["type"]}, Args: {", ".join(data["args"].keys())})'
84+
f"""- {node}: {data["description"]} (Type: {data["type"]},
85+
Args: {", ".join(data["args"].keys())})"""
8586
for node, data in nodes_metadata.items()
8687
])
8788

scrapegraphai/helpers/nodes_metadata.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
"description": """A node responsible for reducing the amount of text to be processed
3434
by identifying and retrieving the most relevant chunks of text based on the user's query.
3535
Utilizes RecursiveCharacterTextSplitter for chunking, Html2TextTransformer for HTML to text
36-
conversion, and a combination of FAISS and OpenAIEmbeddings for efficient information retrieval.""",
36+
conversion, and a combination of FAISS and OpenAIEmbeddings
37+
for efficient information retrieval.""",
3738
"type": "node",
3839
"args": {
3940
"user_input": "The user's query or question guiding the retrieval.",
4041
"document": "The HTML content to be processed and compressed."
4142
},
42-
"returns": "Updated state with 'relevant_chunks' key containing the most relevant text chunks."
43+
"returns": """Updated state with 'relevant_chunks' key containing
44+
the most relevant text chunks."""
4345
},
4446
"GenerateAnswerNode": {
4547
"description": "Generates an answer based on the user's input and parsed document.",

scrapegraphai/helpers/schemas.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@
4646
"items": {
4747
"type": "string"
4848
},
49-
"description": """An array containing the node_names of the ending nodes of the edge.
50-
If the 'from' node is a conditional node, this array must contain exactly two node_names."""
49+
"description": """An array containing the node_names
50+
of the ending nodes of the edge.
51+
If the 'from' node is a conditional node,
52+
this array must contain exactly two node_names."""
5153
}
5254
},
5355
"required": ["from", "to"]

scrapegraphai/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
from .openai import OpenAI
66
from .openai_itt import OpenAIImageToText
7-
from .openai_tts import OpenAITextToSpeech
7+
from .openai_tts import OpenAITextToSpeech

scrapegraphai/nodes/fetch_html_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
22
Module for fetching the HTML node
33
"""
4-
5-
from .base_node import BaseNode
64
from langchain_community.document_loaders import AsyncHtmlLoader
5+
from .base_node import BaseNode
6+
77

88
class FetchHTMLNode(BaseNode):
99
"""

scrapegraphai/nodes/generate_answer_node.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ def execute(self, state: dict) -> dict:
8686
Content of {chunk_id}: {context}
8787
Question: {question}
8888
"""
89-
9089
template_merge = """You are a website scraper and you have just scraped the
9190
following content from a website.
9291
You are now asked to answer a question about the content you have scraped.\n {format_instructions} \n
@@ -101,14 +100,15 @@ def execute(self, state: dict) -> dict:
101100
prompt = PromptTemplate(
102101
template=template_chunks,
103102
input_variables=["question"],
104-
partial_variables={"context": chunk.page_content, "chunk_id": i + 1, "format_instructions": format_instructions},
103+
partial_variables={"context": chunk.page_content,
104+
"chunk_id": i + 1, "format_instructions": format_instructions},
105105
)
106106
# Dynamically name the chains based on their index
107107
chain_name = f"chunk{i+1}"
108108
chains_dict[chain_name] = prompt | self.llm | output_parser
109109

110110
# Use dictionary unpacking to pass the dynamically named chains to RunnableParallel
111-
map_chain = RunnableParallel(**chains_dict)
111+
map_chain = RunnableParallel(**chains_dict)
112112
# Chain
113113
answer_map = map_chain.invoke({"question": user_input})
114114

0 commit comments

Comments
 (0)