bstraehle commited on
Commit
29455b5
1 Parent(s): 68cb77a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -10,7 +10,7 @@ _assistant, _thread = None, None
10
  def show_json(str, obj):
11
  print(f"=> {str}\n{json.loads(obj.model_dump_json())}")
12
 
13
- def init_assistant(client):
14
  assistant = client.beta.assistants.create(
15
  name="Math Tutor",
16
  instructions="You are a personal math tutor. Answer questions briefly, in a sentence or less.",
@@ -19,7 +19,7 @@ def init_assistant(client):
19
  show_json("assistant", assistant)
20
  return assistant
21
 
22
- def init_thread(client):
23
  thread = client.beta.threads.create()
24
  show_json("thread", thread)
25
  return thread
@@ -44,14 +44,11 @@ def extract_content_values(data):
44
  def chat(message, history, openai_api_key):
45
  global _client, _assistant, _thread
46
 
47
- if _client == None:
48
- _client = init_client()
49
-
50
  if _assistant == None:
51
- _assitant = init_assistant(_client)
52
 
53
  if _thread == None:
54
- _thread = init_thread(_client)
55
 
56
  message = _client.beta.threads.messages.create(
57
  role="user",
 
10
  def show_json(str, obj):
11
  print(f"=> {str}\n{json.loads(obj.model_dump_json())}")
12
 
13
+ def create_assistant(client):
14
  assistant = client.beta.assistants.create(
15
  name="Math Tutor",
16
  instructions="You are a personal math tutor. Answer questions briefly, in a sentence or less.",
 
19
  show_json("assistant", assistant)
20
  return assistant
21
 
22
+ def create_thread(client):
23
  thread = client.beta.threads.create()
24
  show_json("thread", thread)
25
  return thread
 
44
  def chat(message, history, openai_api_key):
45
  global _client, _assistant, _thread
46
 
 
 
 
47
  if _assistant == None:
48
+ _assistant = create_assistant(_client)
49
 
50
  if _thread == None:
51
+ _thread = create_thread(_client)
52
 
53
  message = _client.beta.threads.messages.create(
54
  role="user",