英語| 简体中文
非公式のHuggingchat Python API、チャットボットなどに拡張可能。
注記
個人的な理由から、このリポジトリの更新は遅くなり、最も基本的な機能を正常に使用できるようにします
最近の新しい更新:
- アシスタント(画像ジェネレーターなど)
- Web検索
- コンテキストを暗記します
- 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 :現在のセッションのすべての会話の情報のリストを表示します。次に、切り替える1つを選択できます。
/switch all :アカウントにすべての会話の情報のリストを表示します。次に、切り替える1つを選択できます。 (アカウントがたくさんの会話をしている場合はお勧めしません)
/del <index> :渡されたインデックスにリンクされた会話を削除します。アクティブセッションは削除されません。
/delete-all :ログインしたユーザーのすべての会話を削除します。
/clear :端子をクリアします。
/llm :切り替えることができる使用可能なモデルを取得します。
/llm <index> : /llmに基づいて、モデルを指定されたモデルインデックスに切り替えます。
/share :モデル著者とデータを共有するための設定を切り替えます。デフォルトで。
/exit :CLI環境を閉じます。
/stream :応答のストリーミングを切り替えます。
/web :Web検索を切り替えます。
/web-hint :ディスプレイWeb検索ヒントを切り替えます。
AIは、偏った生成や誤った情報などの既知の問題を抱える積極的な研究の分野です。このアプリケーションをハイステークスの決定やアドバイスに使用しないでください。
サーバーリソースは貴重であり、このAPIを高頻度でリクエストすることはお勧めしません。
❤
これは公式の抱きしめられた顔製品ではありません。これは個人的なプロジェクトであり、決して顔を抱きしめることとは関係ありません。私たちを訴えないでください。