File tree Expand file tree Collapse file tree 1 file changed +12
-18
lines changed Expand file tree Collapse file tree 1 file changed +12
-18
lines changed Original file line number Diff line number Diff line change 1- import  openai 
21import  time 
32
3+ import  openai 
4+ 
45# gets API Key from environment variable OPENAI_API_KEY 
56client  =  openai .OpenAI ()
67
1617message  =  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
2223run  =  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
2829print ("checking assistant status. " )
2930while  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 )
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments