Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix compile error in api integration test #548

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading