Skip to content

Python scraper based on AI

refactoring of the code

VinciGit00e872f97cbff9
diff --git a/yosoai/__init__.py b/yosoai/__init__.py
index cec705a8..d8356992 100644
--- a/yosoai/__init__.py
+++ b/yosoai/__init__.py
@@ -2,4 +2,4 @@ from .class_creator import create_class
from .class_generator import Generator
from .getter import _get_function
from .token_calculator import truncate_text_tokens
-from .request import send_request
\ No newline at end of file
+from .request import send_request
diff --git a/yosoai/class_creator.py b/yosoai/class_creator.py
index c183d964..9cc41dc3 100644
--- a/yosoai/class_creator.py
+++ b/yosoai/class_creator.py
@@ -18,9 +18,10 @@ from langchain_core.pydantic_v1 import BaseModel, Field
class _Response(BaseModel):
"""
-
+
for elem in data_dict:
base_script = base_script + f" {elem['title']}: {elem['type']} = Field(description='{elem['description']}')\n"
with open("./yosoai/pydantic_class.py", "w") as f:
- f.write(base_script)
\ No newline at end of file
+ f.write(base_script)
+
\ No newline at end of file
diff --git a/yosoai/class_generator.py b/yosoai/class_generator.py
index 31729b37..0a37aaaf 100644
--- a/yosoai/class_generator.py
+++ b/yosoai/class_generator.py
@@ -6,7 +6,13 @@ from langchain_core.pydantic_v1 import Field
from langchain.output_parsers import PydanticOutputParser
class Generator:
- def __init__(self, api_key: str, temperature_param: float = 0.0, model_name: str = "gpt-3.5-turbo") -> dict:
+ def __init__(
+ self,
+ api_key: str,
+ temperature_param: float = 0.0,
+ model_name: str = "gpt-3.5-turbo"
+ ) -> dict:
+
"""
Initializes the Generator object.
@@ -28,7 +34,8 @@ class Generator:
partial_variables={"format_instructions": self.parser.get_format_instructions()},
)
- self.model = ChatOpenAI(openai_api_key=api_key, temperature=temperature_param, model=model_name)
+ self.model = ChatOpenAI(openai_api_key=api_key, temperature=temperature_param,
+ model=model_name)
self.chain = self.prompt | self.model | self.parser
diff --git a/yosoai/dictionaries.py b/yosoai/dictionaries.py
index 125c0f65..fb15e0af 100644
--- a/yosoai/dictionaries.py
+++ b/yosoai/dictionaries.py
@@ -12,7 +12,7 @@ schema_example= {
"project_name": {"type": "string"},
"project_description": {"type": "string"},
"url": {"type": "string"}
- },
+ },
"required": ["project_name", "project_description", "url"],
},
},
diff --git a/yosoai/remover.py b/yosoai/remover.py
index 27e01eae..cd6515cd 100644
--- a/yosoai/remover.py
+++ b/yosoai/remover.py
@@ -13,7 +13,7 @@ def remover(file:str, only_body:bool = False) -> str:
if only_body == True:
isBody = True
- else:
+ else:
isBody = False
for elem in file.splitlines():
@@ -32,4 +32,5 @@ def remover(file:str, only_body:bool = False) -> str:
if isBody == True:
res = res + elem
- return res.replace("\\n", "")
\ No newline at end of file
+ return res.replace("\\n", "")
+
\ No newline at end of file
diff --git a/yosoai/token_calculator.py b/yosoai/token_calculator.py
index cb15415a..9494eba2 100644
--- a/yosoai/token_calculator.py
+++ b/yosoai/token_calculator.py
@@ -23,4 +23,5 @@ def truncate_text_tokens(text: str, model: str, encoding_name: str) -> List[str]
result = [encoding.decode(chunk) for chunk in chunks]
- return result
\ No newline at end of file
+ return result
+
\ No newline at end of file