Skip to content

Commit

Permalink
fix: return the empty string when get message.text
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulter committed May 31, 2024
1 parent 11bb414 commit e766d7e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/hugchat/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ class Message(Generator):
g: Generator
_stream_yield_all: bool = False
web_search: bool = False

web_search_sources: list = []
# For backward compatibility, we have to reserve the `text` field.
text: str = ""
_result_text: str = ""
web_search_done: bool = not web_search
msg_status: int = MSGSTATUS_PENDING
error: Union[Exception, None] = None
Expand All @@ -76,6 +74,15 @@ def __init__(
self._stream_yield_all = _stream_yield_all
self.web_search = web_search

@property
def text(self) -> str:
self._result_text = self.wait_until_done()
return self._result_text

@text.setter
def text(self, v: str) -> None:
self._result_text = v

def _filterResponse(self, obj: dict):
if not obj.__contains__("type"):
if obj.__contains__("message"):
Expand All @@ -99,7 +106,7 @@ def __next__(self) -> dict:
t: str = a["type"]
message_type: str = ""
if t == RESPONSE_TYPE_FINAL:
self.text = a["text"]
self._result_text = a["text"]
self.msg_status = MSGSTATUS_RESOLVED
elif t == RESPONSE_TYPE_WEB:
# gracefully pass unparseable webpages
Expand Down Expand Up @@ -195,7 +202,7 @@ def wait_until_done(self) -> str:
while not self.is_done():
self.__next__()
if self.is_done() == MSGSTATUS_RESOLVED:
return self.text
return self._result_text
elif self.error is not None:
raise self.error
else:
Expand Down

0 comments on commit e766d7e

Please sign in to comment.