HuggingChat API?

问题描述 投票:0回答:2

我尝试使用 Python 中的请求访问 HuggingChat,但由于某种原因我收到的响应代码为 500。到目前为止我所拥有的是这样的:

hf_url = "https://huggingface.co/chat"
resp = session.post(hf_url + f"/conversation/{self.now_conversation}", json=req_json, stream=True)

JSON 对象保存“输入”字段和其他“参数”,例如温度、top_p 等。

req_json = {
            "inputs": text,
            "parameters": {
                "temperature": temperature,
                "top_p": top_p,
...

没有可以直接使用的API吗?如果没有,我在这里缺少身份验证吗?当我与 HuggingChat 聊天时,我检查了浏览器发出的请求,但没有发现任何内容。

python chatbot huggingface
2个回答
0
投票
from hugchat import hugchat
from hugchat.login import Login

sign = Login("[email protected]", "Dishant@2101")
cookies = sign.login()
sign.saveCookiesToDir()

chatbot = hugchat.ChatBot(cookies=cookies.get_dict()) 
id = chatbot.new_conversation()
chatbot.change_conversation(id)

print('[[ Welcome to AI. Let\'s talk! ]]')
print('\'q\' or \'quit\' to exit')
print('\'c\' or \'change\' to change conversation')
print('\'n\' or \'new\' to start a new conversation')

while True:
    user_input = input('> ')
    if user_input.lower() == '':
        pass
    elif user_input.lower() in ['q', 'quit']:
        break
    elif user_input.lower() in ['c', 'change']:
        print('Choose a conversation to switch to:')
        print(chatbot.get_conversation_list())
    elif user_input.lower() in ['n', 'new']:
        print('Clean slate!')
        id = chatbot.new_conversation()
        chatbot.change_conversation(id)
    else:
        print(chatbot.chat(user_input))

试试这个..


0
投票

我正在尝试使用这个拥抱聊天API,出于某种原因,在使用

chatbot.chat('hello')
后我收到此错误:
raise ChatError(f"Failed to parse response: {res}") hugchat.exceptions.ChatError: Failed to parse response: {"type":"status","status":"started"}

© www.soinside.com 2019 - 2024. All rights reserved.