Bahasa Inggris | 简体中文
API Huggingchat Python yang tidak resmi, dapat diperpanjang untuk chatbots dll.
Catatan
Untuk alasan pribadi, pembaruan repo ini akan menjadi lambat, dan kami akan memastikan bahwa fitur paling mendasar dapat digunakan secara normal
Baru -baru ini pembaruan baru:
- Asisten (generator gambar, dll)
- Pencarian Web
- Menghafal konteks
- Dukungan untuk mengubah LLMS
pip3 install hugchatBerikut ini adalah penggunaan umum dari repo ini, Anda mungkin tidak perlu menggunakan semuanya, Anda dapat menambahkan atau menghapus beberapa sesuai kebutuhan :)
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 ()Cukup jalankan perintah berikut di terminal Anda untuk memulai mode CLI
python -m hugchat.cliParams CLI:
-u <your huggingface email> : Menyediakan email akun untuk login.-p : Kata sandi permintaan paksa ke login, mengabaikan cookie yang disimpan.-s : Aktifkan output mode streaming di CLI.-c : Lanjutkan percakapan sebelumnya di CLI ".Perintah dalam mode CLI:
/new : Buat dan beralih ke percakapan baru.
/ids : Menampilkan daftar semua nomor ID dan string ID di sesi saat ini .
/switch : Menampilkan daftar info semua percakapan di sesi saat ini . Kemudian Anda dapat memilih satu untuk beralih.
/switch all : Menampilkan daftar info semua percakapan di akun Anda . Kemudian Anda dapat memilih satu untuk beralih. (Tidak disarankan jika akun Anda memiliki banyak percakapan)
/del <index> : Menghapus percakapan yang terhubung dengan indeks yang disahkan. Tidak akan menghapus sesi aktif.
/delete-all : hapus semua percakapan untuk pengguna yang masuk.
/clear : Hapus terminal.
/llm : Dapatkan model yang tersedia yang bisa Anda beralih.
/llm <index> : Sakelar Model ke Indeks Model yang Diberikan berdasarkan /llm .
/share : Mengalihkan Pengaturan untuk Berbagi Data dengan Penulis Model. Aktif secara default.
/exit : Menutup lingkungan CLI.
/stream : Mengaktifkan streaming respons.
/web : Mencari Pencarian Web.
/web-hint : Toggle menampilkan petunjuk pencarian web.
AI adalah bidang penelitian aktif dengan masalah yang diketahui seperti generasi yang bias dan informasi yang salah. Jangan gunakan aplikasi ini untuk keputusan atau nasihat berisiko tinggi.
Sumber daya server sangat berharga, tidak disarankan untuk meminta API ini dalam frekuensi tinggi.
❤
Ini bukan produk wajah pelukan resmi. Ini adalah proyek pribadi dan tidak berafiliasi dengan wajah memeluk dengan cara apa pun. Jangan menuntut kami.