Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,18 @@ from openai import OpenAI
|
|
4 |
|
5 |
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def show_json(obj):
|
8 |
print("###")
|
9 |
print(json.loads(obj.model_dump_json()))
|
@@ -27,22 +39,16 @@ def extract_content_value(data):
|
|
27 |
return content_values
|
28 |
|
29 |
def chat(message, history, system_prompt):
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
)
|
35 |
-
|
36 |
-
show_json(assistant)
|
37 |
-
|
38 |
-
thread = client.beta.threads.create()
|
39 |
|
40 |
-
show_json(thread)
|
41 |
-
|
42 |
message = client.beta.threads.messages.create(
|
43 |
thread_id=thread.id,
|
44 |
role="user",
|
45 |
-
content=
|
46 |
)
|
47 |
|
48 |
show_json(message)
|
|
|
4 |
|
5 |
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
6 |
|
7 |
+
assistant = client.beta.assistants.create(
|
8 |
+
name="Math Tutor",
|
9 |
+
instructions=system_prompt,
|
10 |
+
model="gpt-4-1106-preview",
|
11 |
+
)
|
12 |
+
|
13 |
+
show_json(assistant)
|
14 |
+
|
15 |
+
thread = client.beta.threads.create()
|
16 |
+
|
17 |
+
show_json(thread)
|
18 |
+
|
19 |
def show_json(obj):
|
20 |
print("###")
|
21 |
print(json.loads(obj.model_dump_json()))
|
|
|
39 |
return content_values
|
40 |
|
41 |
def chat(message, history, system_prompt):
|
42 |
+
history_openai_format = []
|
43 |
+
for human, assistant in history:
|
44 |
+
history_openai_format.append({"role": "user", "content": human })
|
45 |
+
history_openai_format.append({"role": "assistant", "content":assistant})
|
46 |
+
history_openai_format.append({"role": "user", "content": message})
|
|
|
|
|
|
|
|
|
47 |
|
|
|
|
|
48 |
message = client.beta.threads.messages.create(
|
49 |
thread_id=thread.id,
|
50 |
role="user",
|
51 |
+
content=history_openai_format,
|
52 |
)
|
53 |
|
54 |
show_json(message)
|