File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- using System . Collections . Generic ;
21using NUnit . Framework ;
2+ using System . Threading ;
33using System . Threading . Tasks ;
4+ using System . Collections . Generic ;
5+ using System . Linq ;
6+ using UnityEngine ;
47
58namespace OpenAI . Tests
69{
@@ -22,5 +25,37 @@ public async Task Create_Chat_Completion()
2225 var res = await openai . CreateChatCompletion ( req ) ;
2326 Assert . NotNull ( res ) ;
2427 }
28+
29+ [ Test ]
30+ public async Task Create_Chat_Completion_Stream ( )
31+ {
32+ bool responseReceived = false ;
33+ float timeout = 10 ;
34+ float time = 0 ;
35+
36+ var req = new CreateChatCompletionRequest
37+ {
38+ Model = "gpt-3.5-turbo" ,
39+ Messages = new List < ChatMessage > ( )
40+ {
41+ new ChatMessage ( ) { Role = "user" , Content = "Hello!" }
42+ } ,
43+ Temperature = 0 ,
44+ Stream = true
45+ } ;
46+
47+ openai . CreateChatCompletionAsync ( req , null , ( ) =>
48+ {
49+ responseReceived = true ;
50+ } , new CancellationTokenSource ( ) ) ;
51+
52+ while ( ! responseReceived && time < timeout )
53+ {
54+ await Task . Delay ( 100 ) ;
55+ time += 0.1f ;
56+ }
57+
58+ Assert . IsTrue ( responseReceived ) ;
59+ }
2560 }
2661}
Original file line number Diff line number Diff line change 11using NUnit . Framework ;
2+ using System . Threading ;
23using System . Threading . Tasks ;
34
45namespace OpenAI . Tests
@@ -8,7 +9,7 @@ public class CompletionsApiTests
89 private OpenAIApi openai = new OpenAIApi ( ) ;
910
1011 [ Test ]
11- public async Task Create_Completion ( )
12+ public async Task Create_Text_Completion ( )
1213 {
1314 var req = new CreateCompletionRequest
1415 {
@@ -20,5 +21,35 @@ public async Task Create_Completion()
2021 var res = await openai . CreateCompletion ( req ) ;
2122 Assert . NotNull ( res ) ;
2223 }
24+
25+ [ Test ]
26+ public async Task Create_Text_Completion_Stream ( )
27+ {
28+ bool responseReceived = false ;
29+ float timeout = 5 ;
30+ float time = 0 ;
31+
32+ var req = new CreateCompletionRequest
33+ {
34+ Model = "text-davinci-003" ,
35+ Prompt = "Say this is a test" ,
36+ MaxTokens = 7 ,
37+ Temperature = 0 ,
38+ Stream = true
39+ } ;
40+
41+ openai . CreateCompletionAsync ( req , null , ( ) =>
42+ {
43+ responseReceived = true ;
44+ } , new CancellationTokenSource ( ) ) ;
45+
46+ while ( ! responseReceived && time < timeout )
47+ {
48+ await Task . Delay ( 100 ) ;
49+ time += 0.1f ;
50+ }
51+
52+ Assert . IsTrue ( responseReceived ) ;
53+ }
2354 }
2455}
You can’t perform that action at this time.
0 commit comments