Spaces:
Running
Running
Update app.py
Browse files
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
|
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
|
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 |
-
|
52 |
|
53 |
if _thread == None:
|
54 |
-
_thread =
|
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",
|