영어 | 简体中文
비공식 HuggingChat Python API, 챗봇 등의 확장 가능
메모
개인적인 이유로,이 리포지트의 업데이트는 느려질 것이며, 가장 기본적인 기능을 정상적으로 사용할 수 있는지 확인합니다.
최근에 새로운 업데이트 :
- 보조 (이미지 생성기 등)
- 웹 검색
- 맥락을 외우십시오
- 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 매개 변수 :
-u <your huggingface email> : 로그인 할 계정 이메일 제공.-p : 강제 요청 암호로 로그인하고 저장된 쿠키를 무시합니다.-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-hint : Toggles 디스플레이 웹 검색 힌트.
AI는 편견 생성 및 잘못된 정보와 같은 알려진 문제를 가진 활발한 연구 영역입니다. 이 응용 프로그램을 고분비 결정이나 조언에 사용하지 마십시오.
서버 리소스는 소중합니다.이 API를 고주파로 요청하는 것이 좋습니다.
❤
이것은 공식 포옹 페이스 제품이 아닙니다. 이것은 개인 프로젝트 이며 어떤 식 으로든 포옹 얼굴과 제휴하지 않습니다. 우리를 고소하지 마십시오.