fix: invalid schema for function 'func_name': None is not of type 'object' (#429)(#432) (#434)

* fix: invalid schema for function 'func_name': None is not of type 'object' (#429)(#432)

* test: add integration test for function call (#429)(#432)

* style: remove duplicate import (#429)(#432)
This commit is contained in:
渡邉祐一 / Yuichi Watanabe
2023-07-11 20:48:15 +09:00
committed by GitHub
parent f028c289d2
commit c3b2451f7c
3 changed files with 63 additions and 30 deletions

View File

@@ -11,6 +11,7 @@ import (
. "github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/internal/test/checks"
"github.com/sashabaranov/go-openai/jsonschema"
)
func TestAPI(t *testing.T) {
@@ -100,6 +101,37 @@ func TestAPI(t *testing.T) {
if counter == 0 {
t.Error("Stream did not return any responses")
}
_, err = c.CreateChatCompletion(
context.Background(),
ChatCompletionRequest{
Model: GPT3Dot5Turbo,
Messages: []ChatCompletionMessage{
{
Role: ChatMessageRoleUser,
Content: "What is the weather like in Boston?",
},
},
Functions: []FunctionDefinition{{
Name: "get_current_weather",
Parameters: jsonschema.Definition{
Type: jsonschema.Object,
Properties: map[string]jsonschema.Definition{
"location": {
Type: jsonschema.String,
Description: "The city and state, e.g. San Francisco, CA",
},
"unit": {
Type: jsonschema.String,
Enum: []string{"celsius", "fahrenheit"},
},
},
Required: []string{"location"},
},
}},
},
)
checks.NoError(t, err, "CreateChatCompletion (with functions) returned error")
}
func TestAPIError(t *testing.T) {