bstraehle commited on
Commit
453ee12
·
verified ·
1 Parent(s): 06d9591

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -7,6 +7,15 @@ def show_json(obj):
7
  print(json.loads(obj.model_dump_json()))
8
  print("###")
9
 
 
 
 
 
 
 
 
 
 
10
  def chat(message, history):
11
  client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
12
 
@@ -36,11 +45,19 @@ def chat(message, history):
36
  )
37
 
38
  show_json(run)
 
 
39
 
 
 
 
 
 
40
  ###
41
 
42
- for i in range(len(message)):
43
- time.sleep(0.5)
44
- yield "You typed: " + message[: i+1]
 
45
 
46
  gr.ChatInterface(chat).launch()
 
7
  print(json.loads(obj.model_dump_json()))
8
  print("###")
9
 
10
+ def wait_on_run(run, thread):
11
+ while run.status == "queued" or run.status == "in_progress":
12
+ run = client.beta.threads.runs.retrieve(
13
+ thread_id=thread.id,
14
+ run_id=run.id,
15
+ )
16
+ time.sleep(0.5)
17
+ return run
18
+
19
  def chat(message, history):
20
  client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
21
 
 
45
  )
46
 
47
  show_json(run)
48
+
49
+ run = wait_on_run(run, thread)
50
 
51
+ show_json(run)
52
+
53
+ messages = client.beta.threads.messages.list(thread_id=thread.id)
54
+
55
+ show_json(messages)
56
  ###
57
 
58
+ #for i in range(len(message)):
59
+ # time.sleep(0.5)
60
+ # yield "You typed: " + message[: i+1]
61
+ return "Done"
62
 
63
  gr.ChatInterface(chat).launch()