diff --git a/src/hugchat/hugchat.py b/src/hugchat/hugchat.py index 7616b12..d1d8016 100644 --- a/src/hugchat/hugchat.py +++ b/src/hugchat/hugchat.py @@ -504,14 +504,18 @@ def get_remote_conversations(self, replace_conversation_list=True): return conversations - def get_conversation_info(self, conversation: Conversation = None) -> Conversation: + def get_conversation_info(self, conversation: Union[Conversation, str] = None) -> Conversation: """ Fetches information related to the specified conversation. Returns the conversation object. + conversation: Conversation object that has the conversation id Or None to use the current conversation. """ if conversation is None: conversation = self.current_conversation + if isinstance(conversation, str): + conversation = Conversation(id=conversation) + r = self.session.get( self.hf_base_url + f"/chat/conversation/{conversation.id}/__data.json?x-sveltekit-invalidated=01", @@ -608,6 +612,7 @@ def get_assistant_list_by_page(self, page: int) -> List[Assistant]: def search_assistant(self, assistant_name: str = None, assistant_id: str = None) -> Assistant: ''' + - If you created an assistant by your own, you should pass the assistant_id here but not the assistant_name. You can pass your assistant_id into the new_conversation() directly. - Search an available assistant by assistant name or assistant id. - Will search on api.soulter.top/hugchat because offifial api doesn't support search. - Return the `Assistant` object if found, return None if not found. diff --git a/src/hugchat/message.py b/src/hugchat/message.py index 5c14f3a..b26caf0 100644 --- a/src/hugchat/message.py +++ b/src/hugchat/message.py @@ -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 @@ -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"): @@ -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 @@ -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: