Allow structured outputs via function calling (#828)

This commit is contained in:
Grey Baker
2024-08-16 13:41:39 -04:00
committed by GitHub
parent dd7f5824f9
commit d86425a5cf
3 changed files with 103 additions and 0 deletions

View File

@@ -277,6 +277,32 @@ func TestChatCompletionsFunctions(t *testing.T) {
})
checks.NoError(t, err, "CreateChatCompletion with functions error")
})
t.Run("StructuredOutputs", func(t *testing.T) {
type testMessage struct {
Count int `json:"count"`
Words []string `json:"words"`
}
msg := testMessage{
Count: 2,
Words: []string{"hello", "world"},
}
_, err := client.CreateChatCompletion(context.Background(), openai.ChatCompletionRequest{
MaxTokens: 5,
Model: openai.GPT3Dot5Turbo0613,
Messages: []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleUser,
Content: "Hello!",
},
},
Functions: []openai.FunctionDefinition{{
Name: "test",
Strict: true,
Parameters: &msg,
}},
})
checks.NoError(t, err, "CreateChatCompletion with functions error")
})
}
func TestAzureChatCompletions(t *testing.T) {