bstraehle commited on
Commit
bd96781
1 Parent(s): 12c2b66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -14,7 +14,7 @@ def init_assistant():
14
 
15
  _client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
16
 
17
- _assistant = client.beta.assistants.create(
18
  name="Math Tutor",
19
  instructions="You are a personal math tutor. Answer questions briefly, in a sentence or less.",
20
  model="gpt-4-1106-preview",
@@ -22,9 +22,10 @@ def init_assistant():
22
 
23
  _thread = client.beta.threads.create()
24
 
25
- def wait_on_run(client, run, thread):
 
26
  while run.status == "queued" or run.status == "in_progress":
27
- run = client.beta.threads.runs.retrieve(
28
  run_id=run.id,
29
  thread_id=thread.id,
30
  )
@@ -62,7 +63,7 @@ def chat(message, history):
62
  #print(len(history_openai_format))
63
  #print(history_openai_format)
64
 
65
- message = client.beta.threads.messages.create(
66
  role="user",
67
  thread_id=_thread.id,
68
  content=history_openai_format,
@@ -70,16 +71,16 @@ def chat(message, history):
70
 
71
  #show_json("message", message)
72
 
73
- run = client.beta.threads.runs.create(
74
  assistant_id=_assistant.id,
75
  thread_id=_thread.id,
76
  )
77
 
78
- run = wait_on_run(client, run, thread)
79
 
80
  #show_json("run", run)
81
 
82
- messages = client.beta.threads.messages.list(thread_id=_thread.id)
83
 
84
  #show_json("messages", messages)
85
 
 
14
 
15
  _client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
16
 
17
+ _assistant = _client.beta.assistants.create(
18
  name="Math Tutor",
19
  instructions="You are a personal math tutor. Answer questions briefly, in a sentence or less.",
20
  model="gpt-4-1106-preview",
 
22
 
23
  _thread = client.beta.threads.create()
24
 
25
+ def wait_on_run(run, thread):
26
+ global _client
27
  while run.status == "queued" or run.status == "in_progress":
28
+ run = _client.beta.threads.runs.retrieve(
29
  run_id=run.id,
30
  thread_id=thread.id,
31
  )
 
63
  #print(len(history_openai_format))
64
  #print(history_openai_format)
65
 
66
+ message = _client.beta.threads.messages.create(
67
  role="user",
68
  thread_id=_thread.id,
69
  content=history_openai_format,
 
71
 
72
  #show_json("message", message)
73
 
74
+ run = _client.beta.threads.runs.create(
75
  assistant_id=_assistant.id,
76
  thread_id=_thread.id,
77
  )
78
 
79
+ run = wait_on_run(run, thread)
80
 
81
  #show_json("run", run)
82
 
83
+ messages = _client.beta.threads.messages.list(thread_id=_thread.id)
84
 
85
  #show_json("messages", messages)
86