Skip to content

Concurrent users face the mixing of sessions #8561

Closed
@sajjadmosaheb

Description

@sajjadmosaheb

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? 🔎

  • I have searched and found no existing issues

Reproduction

import openai
import time
import gradio as gr
import os
import re

# Initialize the client

client = openai.OpenAI(api_key =os.getenv("OPENAI_API_KEY"))

assistant_id=os.getenv("assistant_id")

# Step 2: Create a Thread
thread = client.beta.threads.create()

def main(Question,history):
    # Step 3: Add a Message to a Thread
    message = client.beta.threads.messages.create(
        thread_id=thread.id,
        role="user",
        content=Question)

    # Step 4: Run the Assistant
    run = client.beta.threads.runs.create(
        thread_id=thread.id,
        assistant_id=assistant_id)

    while True:
        # Wait for 5 seconds
        time.sleep(5)

        # Retrieve the run status
        run_status = client.beta.threads.runs.retrieve(
            thread_id=thread.id,
            run_id=run.id
        )

        # If run is completed, get messages
        if run_status.status == 'completed':
            messages = client.beta.threads.messages.list(
                thread_id=thread.id
            )
            response = ""            
            content = messages.data[0].content[0].text.value
            response += f"\n\n{content }\n\n"
            return response
        else:
            continue

theme = 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocs/websiteRelated to documentation or website

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions