Skip to content

Commit 5b47b2c

Browse files
chore(examples): fix static types in assistants example (#852)
1 parent f6c2aed commit 5b47b2c

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

examples/assistant.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import openai
21
import time
32

3+
import openai
4+
45
# gets API Key from environment variable OPENAI_API_KEY
56
client = openai.OpenAI()
67

@@ -16,38 +17,31 @@
1617
message = client.beta.threads.messages.create(
1718
thread_id=thread.id,
1819
role="user",
19-
content="I need to solve the equation `3x + 11 = 14`. Can you help me?"
20+
content="I need to solve the equation `3x + 11 = 14`. Can you help me?",
2021
)
2122

2223
run = client.beta.threads.runs.create(
23-
thread_id=thread.id,
24-
assistant_id=assistant.id,
25-
instructions="Please address the user as Jane Doe. The user has a premium account."
24+
thread_id=thread.id,
25+
assistant_id=assistant.id,
26+
instructions="Please address the user as Jane Doe. The user has a premium account.",
2627
)
2728

2829
print("checking assistant status. ")
2930
while True:
30-
run = client.beta.threads.runs.retrieve(
31-
thread_id=thread.id,
32-
run_id=run.id
33-
)
31+
run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
3432

3533
if run.status == "completed":
3634
print("done!")
37-
messages = client.beta.threads.messages.list(
38-
thread_id=thread.id
39-
)
35+
messages = client.beta.threads.messages.list(thread_id=thread.id)
4036

4137
print("messages: ")
4238
for message in messages:
43-
print({
44-
"role": message.role,
45-
"message": message.content[0].text.value
46-
})
39+
assert message.content[0].type == "text"
40+
print({"role": message.role, "message": message.content[0].text.value})
4741

4842
client.beta.assistants.delete(assistant.id)
49-
43+
5044
break
5145
else:
5246
print("in progress...")
53-
time.sleep(5)
47+
time.sleep(5)

0 commit comments

Comments
 (0)