Fix integration test (#762)
* added TestCompletionStream test moved completion stream testing to seperate function added NoErrorF fixes nil pointer reference on stream object * update integration test models
This commit is contained in:
@@ -26,7 +26,7 @@ func TestAPI(t *testing.T) {
|
||||
_, err = c.ListEngines(ctx)
|
||||
checks.NoError(t, err, "ListEngines error")
|
||||
|
||||
_, err = c.GetEngine(ctx, "davinci")
|
||||
_, err = c.GetEngine(ctx, openai.GPT3Davinci002)
|
||||
checks.NoError(t, err, "GetEngine error")
|
||||
|
||||
fileRes, err := c.ListFiles(ctx)
|
||||
@@ -42,7 +42,7 @@ func TestAPI(t *testing.T) {
|
||||
"The food was delicious and the waiter",
|
||||
"Other examples of embedding request",
|
||||
},
|
||||
Model: openai.AdaSearchQuery,
|
||||
Model: openai.AdaEmbeddingV2,
|
||||
}
|
||||
_, err = c.CreateEmbeddings(ctx, embeddingReq)
|
||||
checks.NoError(t, err, "Embedding error")
|
||||
@@ -77,31 +77,6 @@ func TestAPI(t *testing.T) {
|
||||
)
|
||||
checks.NoError(t, err, "CreateChatCompletion (with name) returned error")
|
||||
|
||||
stream, err := c.CreateCompletionStream(ctx, openai.CompletionRequest{
|
||||
Prompt: "Ex falso quodlibet",
|
||||
Model: openai.GPT3Ada,
|
||||
MaxTokens: 5,
|
||||
Stream: true,
|
||||
})
|
||||
checks.NoError(t, err, "CreateCompletionStream returned error")
|
||||
defer stream.Close()
|
||||
|
||||
counter := 0
|
||||
for {
|
||||
_, err = stream.Recv()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
t.Errorf("Stream error: %v", err)
|
||||
} else {
|
||||
counter++
|
||||
}
|
||||
}
|
||||
if counter == 0 {
|
||||
t.Error("Stream did not return any responses")
|
||||
}
|
||||
|
||||
_, err = c.CreateChatCompletion(
|
||||
context.Background(),
|
||||
openai.ChatCompletionRequest{
|
||||
@@ -134,6 +109,41 @@ func TestAPI(t *testing.T) {
|
||||
checks.NoError(t, err, "CreateChatCompletion (with functions) returned error")
|
||||
}
|
||||
|
||||
func TestCompletionStream(t *testing.T) {
|
||||
apiToken := os.Getenv("OPENAI_TOKEN")
|
||||
if apiToken == "" {
|
||||
t.Skip("Skipping testing against production OpenAI API. Set OPENAI_TOKEN environment variable to enable it.")
|
||||
}
|
||||
|
||||
c := openai.NewClient(apiToken)
|
||||
ctx := context.Background()
|
||||
|
||||
stream, err := c.CreateCompletionStream(ctx, openai.CompletionRequest{
|
||||
Prompt: "Ex falso quodlibet",
|
||||
Model: openai.GPT3Babbage002,
|
||||
MaxTokens: 5,
|
||||
Stream: true,
|
||||
})
|
||||
checks.NoError(t, err, "CreateCompletionStream returned error")
|
||||
defer stream.Close()
|
||||
|
||||
counter := 0
|
||||
for {
|
||||
_, err = stream.Recv()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
t.Errorf("Stream error: %v", err)
|
||||
} else {
|
||||
counter++
|
||||
}
|
||||
}
|
||||
if counter == 0 {
|
||||
t.Error("Stream did not return any responses")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIError(t *testing.T) {
|
||||
apiToken := os.Getenv("OPENAI_TOKEN")
|
||||
if apiToken == "" {
|
||||
|
||||
Reference in New Issue
Block a user