mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-07-12 21:01:56 +08:00
refactoring of the code
This commit is contained in:
parent
446c2ceea3
commit
e872f97cbf
@ -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
|
||||
from .request import send_request
|
||||
|
||||
@ -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)
|
||||
f.write(base_script)
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ schema_example= {
|
||||
"project_name": {"type": "string"},
|
||||
"project_description": {"type": "string"},
|
||||
"url": {"type": "string"}
|
||||
},
|
||||
},
|
||||
"required": ["project_name", "project_description", "url"],
|
||||
},
|
||||
},
|
||||
|
||||
@ -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", "")
|
||||
return res.replace("\\n", "")
|
||||
|
||||
@ -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
|
||||
return result
|
||||
|
||||
Loading…
Reference in New Issue
Block a user