-
Notifications
You must be signed in to change notification settings - Fork 0
Bot
It should be noticed that Bot cannot be created with variable = Bot()
you have to get it through HuggingChat which can be imported:
from hugchat_api import HuggingChat
# or
from hugchat_api.core import HuggingChat
# and then
HUG = HuggingChat()
bot = HUG.getBot(<email>, <cookies>, <model?>)Param model is a string represents which model to be used, and it defaults to ListBots.OPENASSISTENT_30B_XOR
You can find all available models under hugchat_api.core.ListBots.
-
self.conversations: Dict[str, str]
store all conversations.
structure:{ id: title } -
self.current_conversation: strthis one is mainly forterminal_cli, normally it shouldn't be concerned.
this method will be called with
wait=Trueonce theBotis created
def fetchConversations(self, wait: bool = True) -> Future | NoneGet conversation_id and title, save them inside self.conversations: Dict[str, str].
Method returns a Future (wait=False) or None since the conversations will be directly updated in Bot it self.
def chat(
self,
text: str,
conversation_id=None,
web_search=False,
max_tries: int = 3,
custom_data: RequestData | None = None,
) -> Message | Nonecustomize parameters is no longer supprted by huggingface.co/chat, but the old request body can still get through it.
Create a chat workflow and submit it to the asyncio loop.
custom_data supports customized parameters such as max_new_tokens top_k etc...
No Future returns but Message which continuously updating web search process and stream message.
def setSystemPrompt(
self, model: str, prompt: str, wait: bool = True
) -> Union[Future, None]:
def setSystemPrompts(
self, prompts: dict[str, str], wait: bool = True
) -> Union[Future, None]:Set system prompt for the given mdoel, it works globally.
For model: str, please see hugchat_api.core.ListBots
def updateTitle(self, conversation_id: str, wait: bool = True) -> Future | strGet conversation summary.
the conversation's title in self.conversations will be updated as well. Normally it will be called after the first chat of the new conversation.
Method returns a Future (wait=False) or the title string
def createConversation(self, wait: bool = True) -> Future | strCreate a new conversation and save the id to self.conversations and change self.current_conversation to the new id.
Method returns a Future (wait=False) or id string
def removeConversation(
self, conversation_id: str, wait: bool = True
) -> Future | None:Removes a given conversation and delete it in self.conversations, if the given one is current conversation then set self.current_conversation to None.
Method returns a Future (wait=False) or None.
def getHistoriesByID(self, conversation_id=None, wait=True) -> Future | listFetch histories of the given conversation.
Method returns a Future (wait=False) or History list.
For the history data structure, please see hugchat_api.utils.formatHistory as an example.
Feel free to ask any questions or share me with your thoughts!