hugging chat api
v0.4.16
英语| 简体中文
非官方的拥抱python api,可用于聊天机器人等
笔记
出于个人原因,此存储库的更新将变得慢,我们将确保可以正常使用最基本的功能
最近的新更新:
- 助手(图像生成器等)
- 网络搜索
- 记住上下文
- 支持更改LLM的支持
pip3 install hugchat以下是此存储库的所有常见用法,您不一定会使用它们,您可以根据需要添加或删除一些:)
from hugchat import hugchat
from hugchat . login import Login
# Log in to huggingface and grant authorization to huggingchat
EMAIL = "your email"
PASSWD = "your password"
cookie_path_dir = "./cookies/" # NOTE: trailing slash (/) is required to avoid errors
sign = Login ( EMAIL , PASSWD )
cookies = sign . login ( cookie_dir_path = cookie_path_dir , save_cookies = True )
# Create your ChatBot
chatbot = hugchat . ChatBot ( cookies = cookies . get_dict ()) # or cookie_path="usercookies/<email>.json"
message_result = chatbot . chat ( "Hi!" ) # note: message_result is a generator, the method will return immediately.
# Non stream
message_str : str = message_result . wait_until_done () # you can also print(message_result) directly.
# get files(such as images)
file_list = message_result . get_files_created () # must call wait_until_done() first!
# tips: model "CohereForAI/c4ai-command-r-plus" can generate images :)
# Stream response
for resp in chatbot . chat (
"Hello" ,
stream = True
):
print ( resp )
# Web search
query_result = chatbot . chat ( "Hi!" , web_search = True )
print ( query_result )
for source in query_result . web_search_sources :
print ( source . link )
print ( source . title )
# Create a new conversation
chatbot . 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 index
chatbot . switch_llm ( 0 ) # Switch to the first model
chatbot . switch_llm ( 1 ) # Switch to the second model
# Get information about the current conversation
info = chatbot . get_conversation_info ()
print ( info . id , info . title , info . model , info . system_prompt , info . history )
# Assistant
ASSISTANT_ID = "66017fca58d60bd7d5c5c26c" # get the assistant id from https://huggingface.co/chat/assistants
chatbot . new_conversation ( assistant = ASSISTANT_ID , switch_to = True ) # create a new conversation with assistant
# [DANGER] Delete all the conversations for the logged in user
chatbot . delete_all_conversations ()只需在终端上运行以下命令即可启动CLI模式
python -m hugchat.cliCLI参数:
-u <your huggingface email> :向登录提供帐户电子邮件。-p :强制请求密码登录,忽略保存的cookie。-s :在CLI中启用流媒体模式输出。-c :继续在CLI中继续对话”。在CLI模式下命令:
/new :创建并切换到新对话。
/ids :在当前会话中显示所有ID号和ID字符串的列表。
/switch :在当前会话中显示所有对话信息的列表。然后,您可以选择一个要切换的。
/switch all :在您的帐户中显示所有对话信息的列表。然后,您可以选择一个要切换的。 (如果您的帐户有很多对话,不建议您使用)
/del <index> :删除与传递的索引链接的对话。不会删除活动会话。
/delete-all :删除登录用户的所有对话。
/clear :清除终端。
/llm :获取可以切换的可用型号。
/llm <index> :基于/llm开关模型转到给定的模型索引。
/share :切换设置以与模型作者共享数据。默认情况下。
/exit :关闭CLI环境。
/stream :切换流响应。
/web :切换Web搜索。
/web-hint :切换显示Web搜索提示。
AI是一个积极研究的领域,具有诸如偏见的产生和错误信息等已知问题。请勿将此应用程序用于高风险决策或建议。
服务器资源是珍贵的,不建议以高频要求此API。
❤
这不是官方的拥抱脸部产品。这是一个个人项目,并不以任何方式隶属于拥抱的脸。不要起诉我们。