Soulter / hugging-chat-api

HuggingChat Python API🤗
GNU Affero General Public License v3.0
836 stars 121 forks source link

cannot change models. #147

Closed PYL29 closed 9 months ago

PYL29 commented 9 months ago

Hello. I can't change models with chatbot.switch_llm(5) function. can anyone help me? Here is the code:

from turtle import mode
from hugchat import hugchat
from hugchat.login import Login

email="**"
passwd="**"
# Log in to huggingface and grant authorization to huggingchat
sign = Login(email, passwd)
cookies = sign.login()

# Save cookies to the local directory
cookie_path_dir = "./cookies_snapshot"
sign.saveCookiesToDir(cookie_path_dir)

# Load cookies when you restart your program:
# sign = login(email, None)
# cookies = sign.loadCookiesFromDir(cookie_path_dir) # This will detect if the JSON file exists, return cookies if it does and raise an Exception if it's not.

# Create a ChatBot
chatbot = hugchat.ChatBot(cookies=cookies.get_dict())  # or cookie_path="usercookies/<email>.json"

models = chatbot.get_available_llm_models()
for i in range(len(models)):
    print(models[i])
print(len(models))

info = chatbot.get_conversation_info()
print(info.id, info.title, info.model, info.system_prompt, info.history)
chatbot.switch_llm(5)
info = chatbot.get_conversation_info()
print(info.id, info.title, info.model, info.system_prompt, info.history)
# non stream response
#query_result = chatbot.query("Hi!")
#print(query_result) # or query_result.text or query_result["text"]

Here is what it returns:

meta-llama/Llama-2-70b-chat-hf
codellama/CodeLlama-34b-Instruct-hf
tiiuae/falcon-180B-chat
mistralai/Mistral-7B-Instruct-v0.1
mistralai/Mistral-7B-Instruct-v0.2
openchat/openchat_3.5
mistralai/Mixtral-8x7B-Instruct-v0.1
7
658afc02e1dd94a1f0c7268d New Chat meta-llama/Llama-2-70b-chat-hf   []
658afc02e1dd94a1f0c7268d New Chat meta-llama/Llama-2-70b-chat-hf   []
Whitelisted1 commented 9 months ago

Try creating a new conversation with chatbot.new_conversation(switch_to=True) after switching to a different model.

Here is a code example:

print(chatbot.query("Who are you?")) # I am LLaMA, an AI assistant developed by Meta AI that can ...

print(chatbot.current_conversation.model) # meta-llama/Llama-2-70b-chat-hf

chatbot.switch_llm(6)
chatbot.new_conversation(switch_to=True)

print(chatbot.query("Who are you?")) # I am a large language model trained by Mistral AI, a leading ...

print(chatbot.current_conversation.model) # mistralai/Mixtral-8x7B-Instruct-v0.1
PYL29 commented 9 months ago

Thank you so much!