Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,22 +8,17 @@ client = OpenAI()
|
|
| 8 |
assistant_id=os.environ["OPENAI_ASSISTANT_ID"]
|
| 9 |
|
| 10 |
def get_thread_id(streaming_chat_thread_id_state):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
# print(thread_id)
|
| 19 |
-
# except TypeError as e:
|
| 20 |
-
# thread_id = None
|
| 21 |
-
thread_id = streaming_chat_thread_id
|
| 22 |
-
if not thread_id or thread_id == "Demo":
|
| 23 |
thread = client.beta.threads.create()
|
| 24 |
thread_id = thread.id
|
| 25 |
print(f"new thread_id: {thread_id}")
|
| 26 |
-
|
| 27 |
else:
|
| 28 |
print(f"old thread_id: {thread_id}")
|
| 29 |
return thread_id
|
|
@@ -46,11 +41,11 @@ def openai_chat(user_message, thread_id):
|
|
| 46 |
total += delta
|
| 47 |
yield total
|
| 48 |
|
| 49 |
-
def chat(user_message, history,
|
| 50 |
-
thread_id =get_thread_id(
|
| 51 |
yield from openai_chat(user_message, thread_id)
|
| 52 |
|
| 53 |
history = []
|
| 54 |
-
|
| 55 |
-
additional_inputs = [
|
| 56 |
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)
|
|
|
|
| 8 |
assistant_id=os.environ["OPENAI_ASSISTANT_ID"]
|
| 9 |
|
| 10 |
def get_thread_id(streaming_chat_thread_id_state):
|
| 11 |
+
if not streaming_chat_thread_id_state:
|
| 12 |
+
streaming_chat_thread_id_state = gr.State({ "thread_id": None})
|
| 13 |
+
print("======thread_id======")
|
| 14 |
+
thread_id = streaming_chat_thread_id_state["thread_id"]
|
| 15 |
+
print(thread_id)
|
| 16 |
+
|
| 17 |
+
if not thread_id:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
thread = client.beta.threads.create()
|
| 19 |
thread_id = thread.id
|
| 20 |
print(f"new thread_id: {thread_id}")
|
| 21 |
+
streaming_chat_thread_id_state["thread_id"] = thread_id
|
| 22 |
else:
|
| 23 |
print(f"old thread_id: {thread_id}")
|
| 24 |
return thread_id
|
|
|
|
| 41 |
total += delta
|
| 42 |
yield total
|
| 43 |
|
| 44 |
+
def chat(user_message, history, streaming_chat_thread_id_state):
|
| 45 |
+
thread_id =get_thread_id(streaming_chat_thread_id_state)
|
| 46 |
yield from openai_chat(user_message, thread_id)
|
| 47 |
|
| 48 |
history = []
|
| 49 |
+
streaming_chat_thread_id_state = gr.State({ "thread_id": None})
|
| 50 |
+
additional_inputs = [streaming_chat_thread_id_state]
|
| 51 |
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)
|