test: fix compile error in api integration test (#548)
This commit is contained in:
committed by
GitHub
parent
a2d2bf6851
commit
08c167fecf
@@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/sashabaranov/go-openai"
|
||||||
"github.com/sashabaranov/go-openai/internal/test/checks"
|
"github.com/sashabaranov/go-openai/internal/test/checks"
|
||||||
"github.com/sashabaranov/go-openai/jsonschema"
|
"github.com/sashabaranov/go-openai/jsonschema"
|
||||||
)
|
)
|
||||||
@@ -20,7 +21,7 @@ func TestAPI(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
c := NewClient(apiToken)
|
c := openai.NewClient(apiToken)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_, err = c.ListEngines(ctx)
|
_, err = c.ListEngines(ctx)
|
||||||
checks.NoError(t, err, "ListEngines error")
|
checks.NoError(t, err, "ListEngines error")
|
||||||
@@ -36,23 +37,23 @@ func TestAPI(t *testing.T) {
|
|||||||
checks.NoError(t, err, "GetFile error")
|
checks.NoError(t, err, "GetFile error")
|
||||||
} // else skip
|
} // else skip
|
||||||
|
|
||||||
embeddingReq := EmbeddingRequest{
|
embeddingReq := openai.EmbeddingRequest{
|
||||||
Input: []string{
|
Input: []string{
|
||||||
"The food was delicious and the waiter",
|
"The food was delicious and the waiter",
|
||||||
"Other examples of embedding request",
|
"Other examples of embedding request",
|
||||||
},
|
},
|
||||||
Model: AdaSearchQuery,
|
Model: openai.AdaSearchQuery,
|
||||||
}
|
}
|
||||||
_, err = c.CreateEmbeddings(ctx, embeddingReq)
|
_, err = c.CreateEmbeddings(ctx, embeddingReq)
|
||||||
checks.NoError(t, err, "Embedding error")
|
checks.NoError(t, err, "Embedding error")
|
||||||
|
|
||||||
_, err = c.CreateChatCompletion(
|
_, err = c.CreateChatCompletion(
|
||||||
ctx,
|
ctx,
|
||||||
ChatCompletionRequest{
|
openai.ChatCompletionRequest{
|
||||||
Model: GPT3Dot5Turbo,
|
Model: openai.GPT3Dot5Turbo,
|
||||||
Messages: []ChatCompletionMessage{
|
Messages: []openai.ChatCompletionMessage{
|
||||||
{
|
{
|
||||||
Role: ChatMessageRoleUser,
|
Role: openai.ChatMessageRoleUser,
|
||||||
Content: "Hello!",
|
Content: "Hello!",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -63,11 +64,11 @@ func TestAPI(t *testing.T) {
|
|||||||
|
|
||||||
_, err = c.CreateChatCompletion(
|
_, err = c.CreateChatCompletion(
|
||||||
ctx,
|
ctx,
|
||||||
ChatCompletionRequest{
|
openai.ChatCompletionRequest{
|
||||||
Model: GPT3Dot5Turbo,
|
Model: openai.GPT3Dot5Turbo,
|
||||||
Messages: []ChatCompletionMessage{
|
Messages: []openai.ChatCompletionMessage{
|
||||||
{
|
{
|
||||||
Role: ChatMessageRoleUser,
|
Role: openai.ChatMessageRoleUser,
|
||||||
Name: "John_Doe",
|
Name: "John_Doe",
|
||||||
Content: "Hello!",
|
Content: "Hello!",
|
||||||
},
|
},
|
||||||
@@ -76,9 +77,9 @@ func TestAPI(t *testing.T) {
|
|||||||
)
|
)
|
||||||
checks.NoError(t, err, "CreateChatCompletion (with name) returned error")
|
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",
|
Prompt: "Ex falso quodlibet",
|
||||||
Model: GPT3Ada,
|
Model: openai.GPT3Ada,
|
||||||
MaxTokens: 5,
|
MaxTokens: 5,
|
||||||
Stream: true,
|
Stream: true,
|
||||||
})
|
})
|
||||||
@@ -103,15 +104,15 @@ func TestAPI(t *testing.T) {
|
|||||||
|
|
||||||
_, err = c.CreateChatCompletion(
|
_, err = c.CreateChatCompletion(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
ChatCompletionRequest{
|
openai.ChatCompletionRequest{
|
||||||
Model: GPT3Dot5Turbo,
|
Model: openai.GPT3Dot5Turbo,
|
||||||
Messages: []ChatCompletionMessage{
|
Messages: []openai.ChatCompletionMessage{
|
||||||
{
|
{
|
||||||
Role: ChatMessageRoleUser,
|
Role: openai.ChatMessageRoleUser,
|
||||||
Content: "What is the weather like in Boston?",
|
Content: "What is the weather like in Boston?",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Functions: []FunctionDefinition{{
|
Functions: []openai.FunctionDefinition{{
|
||||||
Name: "get_current_weather",
|
Name: "get_current_weather",
|
||||||
Parameters: jsonschema.Definition{
|
Parameters: jsonschema.Definition{
|
||||||
Type: jsonschema.Object,
|
Type: jsonschema.Object,
|
||||||
@@ -140,12 +141,12 @@ func TestAPIError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
c := NewClient(apiToken + "_invalid")
|
c := openai.NewClient(apiToken + "_invalid")
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_, err = c.ListEngines(ctx)
|
_, err = c.ListEngines(ctx)
|
||||||
checks.HasError(t, err, "ListEngines should fail with an invalid key")
|
checks.HasError(t, err, "ListEngines should fail with an invalid key")
|
||||||
|
|
||||||
var apiErr *APIError
|
var apiErr *openai.APIError
|
||||||
if !errors.As(err, &apiErr) {
|
if !errors.As(err, &apiErr) {
|
||||||
t.Fatalf("Error is not an APIError: %+v", err)
|
t.Fatalf("Error is not an APIError: %+v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user