Skip to content

Commit 8b54683

Browse files
authored
llms/openai: Optionally supply ResponseFormat (#690)
* fix: ResponseFormat cause openai api response err - is not one of ['json_object', 'text'] - 'response_format.type'
1 parent 4065971 commit 8b54683

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

llms/openai/internal/openaiclient/chat.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type ChatRequest struct {
3333
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
3434
PresencePenalty float64 `json:"presence_penalty,omitempty"`
3535

36-
ResponseFormat ResponseFormat `json:"response_format,omitempty"`
36+
ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
3737

3838
// Function definitions to include in the request.
3939
Functions []FunctionDefinition `json:"functions,omitempty"`

llms/openai/openaillm_option.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type options struct {
3333
apiType APIType
3434
httpClient openaiclient.Doer
3535

36-
responseFormat ResponseFormat
36+
responseFormat *ResponseFormat
3737

3838
// required when APIType is APITypeAzure or APITypeAzureAD
3939
apiVersion string
@@ -49,7 +49,7 @@ type Option func(*options)
4949
type ResponseFormat = openaiclient.ResponseFormat
5050

5151
// ResponseFormatJSON is the JSON response format.
52-
var ResponseFormatJSON = ResponseFormat{Type: "json_object"} //nolint:gochecknoglobals
52+
var ResponseFormatJSON = &ResponseFormat{Type: "json_object"} //nolint:gochecknoglobals
5353

5454
// WithToken passes the OpenAI API token to the client. If not set, the token
5555
// is read from the OPENAI_API_KEY environment variable.
@@ -124,7 +124,7 @@ func WithCallback(callbackHandler callbacks.Handler) Option {
124124
}
125125

126126
// WithResponseFormat allows setting a custom response format.
127-
func WithResponseFormat(responseFormat ResponseFormat) Option {
127+
func WithResponseFormat(responseFormat *ResponseFormat) Option {
128128
return func(opts *options) {
129129
opts.responseFormat = responseFormat
130130
}

0 commit comments

Comments
 (0)