refactoring of the code

This commit is contained in:
VinciGit00 2024-02-12 22:56:03 +01:00
parent 446c2ceea3
commit e872f97cbf
6 changed files with 19 additions and 9 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -12,7 +12,7 @@ schema_example= {
"project_name": {"type": "string"},
"project_description": {"type": "string"},
"url": {"type": "string"}
},
},
"required": ["project_name", "project_description", "url"],
},
},

View File

@ -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", "")

View File

@ -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