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。
❤
這不是官方的擁抱臉部產品。這是一個個人項目,並不以任何方式隸屬於擁抱的臉。不要起訴我們。