jh-didero commited on
Commit
ccef7af
·
verified ·
1 Parent(s): 7c04312

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -17
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
- # if not streaming_chat_thread_id_state:
12
- # streaming_chat_thread_id_state = gr.State({"thread_id": None})
13
- # print("======thread_id======")
14
- # print(type(streaming_chat_thread_id_state))
15
- # print(streaming_chat_thread_id_state)
16
- # try:
17
- # thread_id = streaming_chat_thread_id_state["thread_id"]
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
- # streaming_chat_thread_id_state["thread_id"] = thread_id
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, streaming_chat_thread_id):
50
- thread_id =get_thread_id(streaming_chat_thread_id)
51
  yield from openai_chat(user_message, thread_id)
52
 
53
  history = []
54
- streaming_chat_thread_id = "Demo"# = gr.State({"thread_id": None})
55
- additional_inputs = [streaming_chat_thread_id]
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)