File tree 1 file changed +12
-18
lines changed
1 file changed +12
-18
lines changed Original file line number Diff line number Diff line change 1
- import openai
2
1
import time
3
2
3
+ import openai
4
+
4
5
# gets API Key from environment variable OPENAI_API_KEY
5
6
client = openai .OpenAI ()
6
7
16
17
message = client .beta .threads .messages .create (
17
18
thread_id = thread .id ,
18
19
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?" ,
20
21
)
21
22
22
23
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." ,
26
27
)
27
28
28
29
print ("checking assistant status. " )
29
30
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 )
34
32
35
33
if run .status == "completed" :
36
34
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 )
40
36
41
37
print ("messages: " )
42
38
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 })
47
41
48
42
client .beta .assistants .delete (assistant .id )
49
-
43
+
50
44
break
51
45
else :
52
46
print ("in progress..." )
53
- time .sleep (5 )
47
+ time .sleep (5 )
You can’t perform that action at this time.
0 commit comments