mirror of
https://github.com/Hopiu/llm.git
synced 2026-05-17 18:21:06 +00:00
Improvements to Response.fake() plus __repr__ for some classes
This commit is contained in:
parent
abfc9c69dc
commit
19ba1a3099
1 changed files with 11 additions and 3 deletions
|
|
@ -150,7 +150,7 @@ class Response(ABC):
|
|||
db["responses"].insert(response)
|
||||
|
||||
@classmethod
|
||||
def fake(cls, model, prompt, system, response):
|
||||
def fake(cls, model: "Model", prompt: str, system: str, response: str):
|
||||
"Utility method to help with writing tests"
|
||||
response_obj = cls(
|
||||
model=model,
|
||||
|
|
@ -182,12 +182,17 @@ class Response(ABC):
|
|||
stream=False,
|
||||
)
|
||||
response.id = row["id"]
|
||||
response._prompt_json = json.loads(row["prompt_json"])
|
||||
response.response_json = json.loads(row["response_json"])
|
||||
response._prompt_json = json.loads(row["prompt_json"] or "null")
|
||||
response.response_json = json.loads(row["response_json"] or "null")
|
||||
response._done = True
|
||||
response._chunks = [row["response"]]
|
||||
return response
|
||||
|
||||
def __repr__(self):
|
||||
return "<Response prompt='{}' text='{}'>".format(
|
||||
self.prompt.prompt, self.text()
|
||||
)
|
||||
|
||||
|
||||
class Options(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
|
@ -258,6 +263,9 @@ class Model(ABC):
|
|||
def __str__(self) -> str:
|
||||
return "{}: {}".format(self.__class__.__name__, self.model_id)
|
||||
|
||||
def __repr__(self):
|
||||
return "<Model '{}'>".format(self.model_id)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ModelWithAliases:
|
||||
|
|
|
|||
Loading…
Reference in a new issue