Better __repr__ for Response and AsyncResponse

This commit is contained in:
Simon Willison 2024-11-14 14:42:40 -08:00
parent f90f29dec9
commit 3b6e73445c

View file

@ -349,6 +349,12 @@ class Response(_BaseResponse):
self._end = time.monotonic()
self._done = True
def __repr__(self):
text = "... not yet done ..."
if self._done:
text = "".join(self._chunks)
return "<Response prompt='{}' text='{}'>".format(self.prompt.prompt, text)
class AsyncResponse(_BaseResponse):
model: "AsyncModel"
@ -440,7 +446,7 @@ class AsyncResponse(_BaseResponse):
text = "... not yet awaited ..."
if self._done:
text = "".join(self._chunks)
return "<Response prompt='{}' text='{}'>".format(self.prompt.prompt, text)
return "<AsyncResponse prompt='{}' text='{}'>".format(self.prompt.prompt, text)
class Options(BaseModel):