-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix error 400 during function call #433
fix error 400 during function call #433
Conversation
Codecov Report
@@ Coverage Diff @@
## master #433 +/- ##
=======================================
Coverage 97.02% 97.02%
=======================================
Files 17 17
Lines 705 705
=======================================
Hits 684 684
Misses 15 15
Partials 6 6 |
@mehulgohil Thanks for PR. This issue has already been Fixed in #431. This commit has not yet been tagged for release. |
@mehulgohil Please try running the following code using the latest go-openai. (Commit ID: f028c28). package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/jsonschema"
)
func main() {
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
resp, err := client.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: openai.GPT3Dot5Turbo,
Messages: []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleUser,
Content: "What is the weather like in Boston?",
},
},
Functions: []openai.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"},
},
}},
},
)
if err != nil {
fmt.Printf("Completion error: %v\n", err)
return
}
respJson, _ := json.Marshal(resp)
fmt.Println(string(respJson))
} |
@vvatanabe I did try with latest commit only |
@vvatanabe I see the difference here Parameters: &jsonschema.Definition{} |
@vvatanabe I have updated the readme file example for function call |
@mehulgohil I get it, MarshalJSON() is a receiver, so it looks like MarshalJSON() won't execute unless you pass it a pointer.
|
@mehulgohil I made a PR to support both pointers and values. Please check #434 |
This makes sense, thanks @vvatanabe |
@mehulgohil Merged #434 |
I tried this exact example and the response ( |
Describe the change
Added omitempty as json tag for properties field
Describe your solution
Was getting error 400 while calling open api function call. So have added omitempty json tag. As properties was going as null
Tests
Fixed tests accordingly
Issue: #432