Spaces:
Runtime error
Runtime error
Update app.py
Browse files7 unmodified lines89101112131415161718192021222324252627282916 unmodified lines46474849505152535455567 unmodified linesassistant_id=os.environ["OPENAI_ASSISTANT_ID"]def get_thread_id(streaming_chat_thread_id_state):# if not streaming_chat_thread_id_state:# streaming_chat_thread_id_state = gr.State({"thread_id": None})# print("======thread_id======")# print(type(streaming_chat_thread_id_state))# print(streaming_chat_thread_id_state)# try:# thread_id = streaming_chat_thread_id_state["thread_id"]# print(thread_id)# except TypeError as e:# thread_id = Nonethread_id = streaming_chat_thread_idif not thread_id or thread_id == "Demo":thread = client.beta.threads.create()thread_id = thread.idprint(f"new thread_id: {thread_id}")# streaming_chat_thread_id_state["thread_id"] = thread_idelse:print(f"old thread_id: {thread_id}")return thread_id16 unmodified linestotal += deltayield totaldef chat(user_message, history, streaming_chat_thread_id):thread_id =get_thread_id(streaming_chat_thread_id)yield from openai_chat(user_message, thread_id)history = []streaming_chat_thread_id = "Demo"# = gr.State({"thread_id": None})additional_inputs = [streaming_chat_thread_id]gr.ChatInterface(chat, examples=[["What are the troy rack mounting options?"], ["what are the steps for helen"], ["what are the main comparison between troy and janus specs"]], title="User Support Bot", additional_inputs=additional_inputs).launch(debug=True)7 unmodified lines8910111213141516171819202122232416 unmodified lines41424344454647484950517 unmodified linesassistant_id=os.environ["OPENAI_ASSISTANT_ID"]def get_thread_id(streaming_chat_thread_id_state):if not streaming_chat_thread_id_state:streaming_chat_thread_id_state = gr.State({ "thread_id": None})print("======thread_id======")thread_id = streaming_chat_thread_id_state["thread_id"]print(thread_id)if not thread_id:thread = client.beta.threads.create()thread_id = thread.idprint(f"new thread_id: {thread_id}")streaming_chat_thread_id_state["thread_id"] = thread_idelse:print(f"old thread_id: {thread_id}")return thread_id16 unmodified linestotal += deltayield totaldef chat(user_message, history, streaming_chat_thread_id_state):thread_id =get_thread_id(streaming_chat_thread_id_state)yield from openai_chat(user_message, thread_id)history = []streaming_chat_thread_id_state = gr.State({ "thread_id": None})additional_inputs = [streaming_chat_thread_id_state]gr.ChatInterface(chat, examples=[["What are the troy rack mounting options?"], ["what are the steps for helen"], ["what are the main comparison between troy and janus specs"]], title="User Support Bot", additional_inputs=additional_inputs).launch(debug=True)
app.py+12-17