Package: hugchat
hugging-chat-apiEnglish |简体中文Unofficial HuggingChat Python API, extensible for chatbots etc.NoteSome recent versions may no longer be fully backward compatible to some extent, a good idea is to review this README or issues promptly after any problem arise.Custom parameters(temprature, max_token, etc) is no longer supportedRecently new updates:Assistant(Image Generator, etc)Web searchMemorize contextSupports for changing LLMsInstallationpip3installhugchatUsageAPIThe following are all common usages of this repo, You may not necessarily use all of them, You can add or delete some as needed :)fromhugchatimporthugchatfromhugchat.loginimportLogin# Log in to huggingface and grant authorization to huggingchatEMAIL="your email"PASSWD="your password"cookie_path_dir="./cookies"sign=Login(EMAIL,PASSWD)cookies=sign.login(cookie_dir_path=cookie_path_dir,save_cookies=True)# Create your ChatBotchatbot=hugchat.ChatBot(cookies=cookies.get_dict())# or cookie_path="usercookies/<email>.json"# Non stream responsequery_result=chatbot.chat("Hi!")print(query_result)# or query_result.text or query_result["text"]# Stream responseforrespinchatbot.query("Hello",stream=True):print(resp)# Web search (new feature)query_result=chatbot.query("Hi!",web_search=True)print(query_result)forsourceinquery_result.web_search_sources:print(source.link)print(source.title)print(source.hostname)# Create a new conversationchatbot.new_conversation(switch_to=True)# switch to the new conversation# Get conversations on the server that are not from the current session (all your conversations in huggingchat)conversation_list=chatbot.get_remote_conversations(replace_conversation_list=True)# Get conversation list(local)conversation_list=chatbot.get_conversation_list()# Get the available models (not hardcore)models=chatbot.get_available_llm_models()# Switch model with given indexchatbot.switch_llm(0)# Switch to the first modelchatbot.switch_llm(1)# Switch to the second model# Get information about the current conversationinfo=chatbot.get_conversation_info()print(info.id,info.title,info.model,info.system_prompt,info.history)# Assistantassistant=chatbot.search_assistant(assistant_name="ChatGpt")# assistant name list in https://huggingface.co/chat/assistantsassistant_list=chatbot.get_assistant_list_by_page(page=0)chatbot.new_conversation(assistant=assistant,switch_to=True)# create a new conversation with assistant# [DANGER] Delete all the conversations for the logged in userchatbot.delete_all_conversations()Thequery()function receives these parameters:text: Required[str].retry_count: Optional[int]. Number of retries for requesting huggingchat. Default is 5web_search: Optional[bool]. Whether to use online search.CLIversion 0.0.5.2or newerSimply run the following command in your terminal to start the CLI modepython-mhugchat.cliCLI params:-u <your huggingface email>: Provide account email to login.-p: Force request password to login, ignores saved cookies.-s: Enable streaming mode output in CLI.-c: Continue previous conversation in CLI ".Commands in cli mode:/new: Create and switch to a new conversation./ids: Shows a list of all ID numbers and ID strings in current session./switch <id>: Switches to the ID number or ID string passed./del <id>: Deletes the ID number or ID string passed. Will not delete active session./delete-all: Deletes all the conversations for the logged in user./clear: Clear the terminal./llm: Get available models you can switch to./llm <index>: Switches model to given model index based on/llm./sharewithauthor <on|off>: Changes settings for sharing data with model author. On by default./exit: Closes CLI environment./stream <on|off>: streaming the response./web <on|off>: web search./web-hint <on|off>: display web search hint.AI is an area of active research with known problems such as biased generation and misinformation. Do not use this application for high-stakes decisions or advice.Server resources are precious, it is not recommended to request this API in a high frequency.
(Hugging Face's CTO🤗just liked the suggestion)DisclaimersThis is not an officialHugging Faceproduct. This is apersonal projectand is not affiliated withHugging Facein any way. Don't sue us.Star History