Skip to content

Commit

Permalink
test: fix compile error in api integration test (sashabaranov#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvatanabe authored Nov 8, 2023
1 parent a2d2bf6 commit 08c167f
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions api_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"testing"

"github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/internal/test/checks"
"github.com/sashabaranov/go-openai/jsonschema"
)
Expand All @@ -20,7 +21,7 @@ func TestAPI(t *testing.T) {
}

var err error
c := NewClient(apiToken)
c := openai.NewClient(apiToken)
ctx := context.Background()
_, err = c.ListEngines(ctx)
checks.NoError(t, err, "ListEngines error")
Expand All @@ -36,23 +37,23 @@ func TestAPI(t *testing.T) {
checks.NoError(t, err, "GetFile error")
} // else skip

embeddingReq := EmbeddingRequest{
embeddingReq := openai.EmbeddingRequest{
Input: []string{
"The food was delicious and the waiter",
"Other examples of embedding request",
},
Model: AdaSearchQuery,
Model: openai.AdaSearchQuery,
}
_, err = c.CreateEmbeddings(ctx, embeddingReq)
checks.NoError(t, err, "Embedding error")

_, err = c.CreateChatCompletion(
ctx,
ChatCompletionRequest{
Model: GPT3Dot5Turbo,
Messages: []ChatCompletionMessage{
openai.ChatCompletionRequest{
Model: openai.GPT3Dot5Turbo,
Messages: []openai.ChatCompletionMessage{
{
Role: ChatMessageRoleUser,
Role: openai.ChatMessageRoleUser,
Content: "Hello!",
},
},
Expand All @@ -63,11 +64,11 @@ func TestAPI(t *testing.T) {

_, err = c.CreateChatCompletion(
ctx,
ChatCompletionRequest{
Model: GPT3Dot5Turbo,
Messages: []ChatCompletionMessage{
openai.ChatCompletionRequest{
Model: openai.GPT3Dot5Turbo,
Messages: []openai.ChatCompletionMessage{
{
Role: ChatMessageRoleUser,
Role: openai.ChatMessageRoleUser,
Name: "John_Doe",
Content: "Hello!",
},
Expand All @@ -76,9 +77,9 @@ func TestAPI(t *testing.T) {
)
checks.NoError(t, err, "CreateChatCompletion (with name) returned error")

stream, err := c.CreateCompletionStream(ctx, CompletionRequest{
stream, err := c.CreateCompletionStream(ctx, openai.CompletionRequest{
Prompt: "Ex falso quodlibet",
Model: GPT3Ada,
Model: openai.GPT3Ada,
MaxTokens: 5,
Stream: true,
})
Expand All @@ -103,15 +104,15 @@ func TestAPI(t *testing.T) {

_, err = c.CreateChatCompletion(
context.Background(),
ChatCompletionRequest{
Model: GPT3Dot5Turbo,
Messages: []ChatCompletionMessage{
openai.ChatCompletionRequest{
Model: openai.GPT3Dot5Turbo,
Messages: []openai.ChatCompletionMessage{
{
Role: ChatMessageRoleUser,
Role: openai.ChatMessageRoleUser,
Content: "What is the weather like in Boston?",
},
},
Functions: []FunctionDefinition{{
Functions: []openai.FunctionDefinition{{
Name: "get_current_weather",
Parameters: jsonschema.Definition{
Type: jsonschema.Object,
Expand Down Expand Up @@ -140,12 +141,12 @@ func TestAPIError(t *testing.T) {
}

var err error
c := NewClient(apiToken + "_invalid")
c := openai.NewClient(apiToken + "_invalid")
ctx := context.Background()
_, err = c.ListEngines(ctx)
checks.HasError(t, err, "ListEngines should fail with an invalid key")

var apiErr *APIError
var apiErr *openai.APIError
if !errors.As(err, &apiErr) {
t.Fatalf("Error is not an APIError: %+v", err)
}
Expand Down

0 comments on commit 08c167f

Please sign in to comment.