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 66client = OpenAI ()
77
88# 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+ ],
1218)
13- print (completion .choices [0 ].text )
19+ print (completion .choices [0 ].message . content )
1420
1521# 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+ ],
1931 stream = True ,
2032)
2133for completion in stream :
22- print (completion .choices [0 ].text , end = "" )
34+ print (completion .choices [0 ].delta . content , end = "" )
2335print ()
You can’t perform that action at this time.
0 commit comments