ภาษาอังกฤษ | 简体中文
Huggingchat Python API อย่างไม่เป็นทางการขยายได้สำหรับ chatbots ฯลฯ
บันทึก
ด้วยเหตุผลส่วนตัวการอัปเดต repo นี้จะช้าลงและเราจะมั่นใจได้ว่าคุณสมบัติพื้นฐานที่สุดสามารถใช้งานได้ตามปกติ
การอัปเดตใหม่เมื่อเร็ว ๆ นี้:
- ผู้ช่วย (เครื่องกำเนิดภาพ ฯลฯ )
- การค้นหาเว็บ
- จดจำบริบท
- รองรับการเปลี่ยน LLMS
pip3 install hugchatต่อไปนี้เป็นประเพณีทั่วไปของ repo นี้คุณอาจไม่ได้ใช้ทั้งหมดคุณสามารถเพิ่มหรือลบบางส่วนได้ตามต้องการ :)
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 : แสดงรายการหมายเลข ID ทั้งหมดและ id id ทั้งหมดใน เซสชันปัจจุบัน
/switch : แสดงรายการข้อมูลการสนทนาทั้งหมดใน เซสชันปัจจุบัน จากนั้นคุณสามารถเลือกที่จะเปลี่ยนไป
/switch all : แสดงรายการข้อมูลการสนทนาทั้งหมดใน บัญชีของคุณ จากนั้นคุณสามารถเลือกที่จะเปลี่ยนไป (ไม่แนะนำหากบัญชีของคุณมีการสนทนามากมาย)
/del <index> : ลบการสนทนาที่เชื่อมโยงกับดัชนีที่ผ่าน จะไม่ลบเซสชันที่ใช้งานอยู่
/delete-all : ลบการสนทนาทั้งหมดสำหรับผู้ใช้ที่เข้าสู่ระบบ
/clear : ล้างเทอร์มินัล
/llm : รับรุ่นที่มีอยู่ที่คุณสามารถเปลี่ยนไปได้
/llm <index> : สวิตช์โมเดลเป็นดัชนีโมเดลที่กำหนดตาม /llm
/share : สลับการตั้งค่าสำหรับการแบ่งปันข้อมูลกับผู้เขียนรุ่น เปิดโดยค่าเริ่มต้น
/exit : ปิดสภาพแวดล้อม CLI
/stream : สลับการสตรีมการตอบกลับ
/web : สลับการค้นหาเว็บ
/web-hint : สลับการแสดงคำใบ้การค้นหาเว็บ
AI เป็นพื้นที่ของการวิจัยที่มีปัญหาที่รู้จักเช่นการสร้างแบบเอนเอียงและข้อมูลที่ผิด อย่าใช้แอปพลิเคชันนี้สำหรับการตัดสินใจหรือคำแนะนำที่มีเดิมพันสูง
ทรัพยากรเซิร์ฟเวอร์มีค่าไม่แนะนำให้ขอ API นี้ในความถี่สูง
นี่ไม่ใช่ผลิตภัณฑ์ใบหน้ากอดอย่างเป็นทางการ นี่เป็น โครงการส่วนบุคคล และไม่มีส่วนเกี่ยวข้องกับการกอดใบหน้าในทางใดทางหนึ่ง อย่าฟ้องเรา