File tree Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Original file line number Diff line number Diff line change 6
6
client = OpenAI ()
7
7
8
8
# Non-streaming:
9
- completion = client .completions .create (
10
- model = "text-davinci-003" ,
11
- prompt = "Say this is a test" ,
9
+ print ('----- standard request -----' )
10
+ completion = client .chat .completions .create (
11
+ model = "gpt-4" ,
12
+ messages = [
13
+ {
14
+ "role" : "user" ,
15
+ "content" : "Say this is a test" ,
16
+ },
17
+ ],
12
18
)
13
- print (completion .choices [0 ].text )
19
+ print (completion .choices [0 ].message . content )
14
20
15
21
# Streaming:
16
- stream = client .completions .create (
17
- model = "text-davinci-003" ,
18
- prompt = "Say this is a test" ,
22
+ print ('----- streaming request -----' )
23
+ stream = client .chat .completions .create (
24
+ model = "gpt-4" ,
25
+ messages = [
26
+ {
27
+ "role" : "user" ,
28
+ "content" : "How do I output all files in a directory using Python?" ,
29
+ },
30
+ ],
19
31
stream = True ,
20
32
)
21
33
for completion in stream :
22
- print (completion .choices [0 ].text , end = "" )
34
+ print (completion .choices [0 ].delta . content , end = "" )
23
35
print ()
You can’t perform that action at this time.
0 commit comments