Closed ekimbasoglu closed 1 month ago
hugchat has changed some things in recent updates which is causing the issue.
Will check when I get time
Hello @rabilrbl, I find the issue and explained here, you can check the PR; https://github.com/rabilrbl/hugging-tg-chatbot/pull/40/commits/917d352100aabc3d77a621610f38a39dfe4ec4f8
@ekimbasoglu
Your PR is causing an error.
.chat()
needs to use _stream_yield_all=true
instead of stream=True
I'm getting key token
not found error.
No time to fix. Let me know if @ekimbasoglu can check. Otherwise I'll check in my liesure time
Fix I used: Does it fix your issue?
import os
import requests
from hugchat import hugchat
from hugchat.login import Login
from dotenv import load_dotenv
load_dotenv()
if os.getenv("HF_EMAIL") and os.getenv("HF_PASSWORD"):
# Log in to huggingface and grant authorization to huggingchat
sign = Login(os.getenv("HF_EMAIL"), os.getenv("HF_PASSWORD"))
cookies = sign.login()
else:
cookies = requests.get("https://huggingface.co/chat/").cookies
# Create a ChatBot
chatbot = hugchat.ChatBot(cookies=cookies.get_dict())
import logging
``
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def generate_response(message: str):
"""Generate a response to a message"""
response_queue = ""
try:
for resp in chatbot.chat(message, _stream_yield_all=True):
if resp:
if "token" in resp:
response_queue += resp["token"]
if len(response_queue) > 100:
yield response_queue
response_queue = ""
except Exception as e:
pass
yield response_queue
@PrivacyOsint2 Yup, that was a simple fix 😅 . Couldn't think of it haha. Thanks
Whether I use the regular version or the updated version of hugchat; it doesn't prompt the code. It's either giving error, or prompting API error code.
When I have time I'll post an image of an error @rabilrbl