الإنجليزية | 简体中文
API غير الرسمي Python API ، قابل للتمديد لدردشة chatbots وما إلى ذلك.
ملحوظة
لأسباب شخصية ، سيصبح تحديث هذا الريبو بطيئًا ، وسنضمن استخدام الميزات الأساسية بشكل طبيعي
تحديثات جديدة مؤخرًا:
- مساعد (مولد الصور ، إلخ)
- البحث على شبكة الإنترنت
- حفظ السياق
- يدعم تغيير LLMS
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 Params:
-u <your huggingface email> : تقديم بريد إلكتروني إلى تسجيل الدخول إلى تسجيل الدخول.-p : قوة طلب كلمة المرور لتسجيل الدخول ، يتجاهل ملفات تعريف الارتباط المحفوظة.-s : تمكين إخراج وضع الدفق في CLI.-c : متابعة المحادثة السابقة في CLI ".الأوامر في وضع CLI:
/new : إنشاء وتبديل إلى محادثة جديدة.
/ids : يعرض قائمة بجميع أرقام الهوية وسلاسل الهوية في الجلسة الحالية .
/switch : يعرض قائمة بمعلومات جميع المحادثات في الجلسة الحالية . ثم يمكنك اختيار واحد للتبديل إليه.
/switch all : يعرض قائمة بمعلومات جميع المحادثات في حسابك . ثم يمكنك اختيار واحد للتبديل إليه. (لا ينصح به إذا كان حسابك يحتوي على الكثير من المحادثات)
/del <index> : حذف المحادثة المرتبطة بالفهرس الذي تم تمريره. لن يحذف الجلسة النشطة.
/delete-all : يحذف جميع المحادثات الخاصة بالمستخدم المسجل.
/clear : مسح المحطة.
/llm : الحصول على النماذج المتاحة التي يمكنك التبديل إليها.
/llm <index> : تبديل النموذج إلى فهرس النموذج المعطى على أساس /llm .
/share : إعدادات التبديل لمشاركة البيانات مع مؤلف النموذج. بشكل افتراضي.
/exit : يغلق بيئة CLI.
/stream : تبديل تدفق الاستجابة.
/web : Toggles Web Search.
/web-hint : تلميح تبديل عرض ويب.
الذكاء الاصطناعى هو مجال للبحث النشط مع مشاكل معروفة مثل التوليد المتحيز والمعلومات الخاطئة. لا تستخدم هذا التطبيق لاتخاذ القرارات أو المشورة عالية المخاطر.
موارد الخادم ثمينة ، لا ينصح بطلب واجهة برمجة التطبيقات هذه بتردد عالي.
❤
هذا ليس منتجًا رسميًا للوجه المعانقة. هذا مشروع شخصي ولا ينتمي إلى وجه المعانقة بأي شكل من الأشكال. لا تقاضينا.