You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using huggingface space to share my app which is a chatbot based on the openai model. I implemented the Chatinterface methode that should handle the session state automatically. but when I open the app in different device and different user and ask about the history of the chat, it mixing the chat up.
what should I do?
thanks in advance
Sajjad
Have you searched existing issues? 🔎
I have searched and found no existing issues
Reproduction
importopenaiimporttimeimportgradioasgrimportosimportre# Initialize the clientclient=openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
assistant_id=os.getenv("assistant_id")
# Step 2: Create a Threadthread=client.beta.threads.create()
defmain(Question,history):
# Step 3: Add a Message to a Threadmessage=client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content=Question)
# Step 4: Run the Assistantrun=client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant_id)
whileTrue:
# Wait for 5 secondstime.sleep(5)
# Retrieve the run statusrun_status=client.beta.threads.runs.retrieve(
thread_id=thread.id,
run_id=run.id
)
# If run is completed, get messagesifrun_status.status=='completed':
messages=client.beta.threads.messages.list(
thread_id=thread.id
)
response=""content=messages.data[0].content[0].text.valueresponse+=f"\n\n{content}\n\n"returnresponseelse:
continuetheme=gr.themes.Soft(
primary_hue="red",
secondary_hue="sky",
)
css="footer {visibility: hidden}"sg=gr.ChatInterface(main,
title="Coworker-همکار(نسخه بتا)",
css=css,
fill_height=True,
chatbot=gr.Chatbot(rtl=True,bubble_full_width=False,show_share_button=False,label='Coworker',show_copy_button=True,likeable=True),
textbox=gr.Textbox(rtl=True,placeholder="از من بپرس ...", container=False, scale=7),
retry_btn=None,
analytics_enabled=False,
theme=theme,
undo_btn=None,
submit_btn="ارسال",
clear_btn=gr.ClearButton(value=" 🗑️پاک کردن",size="lg")).queue(default_concurrency_limit=100)
sg.launch()
Screenshot
No response
Logs
No response
System Info
hugging face space
gradio 4.
Severity
I can work around it
The text was updated successfully, but these errors were encountered:
Hi @sajjadmosaheb the reason you are running into this issue is because you have a single thread instance that is being shared across all of the users of your session. You will need to create separate threads based on the user that is interaction. You can figure out which users is which by looking at the session_hash of the request, as described here: https://www.gradio.app/docs/gradio/request
We'll add an example in our docs to make this clearer
Describe the bug
I'm using huggingface space to share my app which is a chatbot based on the openai model. I implemented the Chatinterface methode that should handle the session state automatically. but when I open the app in different device and different user and ask about the history of the chat, it mixing the chat up.
what should I do?
thanks in advance
Sajjad
Have you searched existing issues? 🔎
Reproduction
Screenshot
No response
Logs
No response
System Info
Severity
I can work around it
The text was updated successfully, but these errors were encountered: