Skip to content

Commit 1bcf8ac

Browse files
committed
Change response_format type to string to match OpenAI Spec
1 parent a10a952 commit 1bcf8ac

File tree

8 files changed

+11
-37
lines changed

8 files changed

+11
-37
lines changed

core/http/endpoints/openai/chat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func ChatEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, startup
181181
noActionDescription = config.FunctionsConfig.NoActionDescriptionName
182182
}
183183

184-
if input.ResponseFormat.Type == "json_object" {
184+
if input.ResponseFormat == "json_object" {
185185
input.Grammar = functions.JSONBNF
186186
}
187187

core/http/endpoints/openai/completion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func CompletionEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, a
6969
return fmt.Errorf("failed reading parameters from request:%w", err)
7070
}
7171

72-
if input.ResponseFormat.Type == "json_object" {
72+
if input.ResponseFormat == "json_object" {
7373
input.Grammar = functions.JSONBNF
7474
}
7575

core/http/endpoints/openai/image.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func ImageEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, appCon
150150
}
151151

152152
b64JSON := false
153-
if input.ResponseFormat.Type == "b64_json" {
153+
if input.ResponseFormat == "b64_json" {
154154
b64JSON = true
155155
}
156156
// src and clip_skip

core/schema/openai.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ type OpenAIModel struct {
101101

102102
type ChatCompletionResponseFormatType string
103103

104-
type ChatCompletionResponseFormat struct {
105-
Type ChatCompletionResponseFormatType `json:"type,omitempty"`
106-
}
107-
108104
type OpenAIRequest struct {
109105
PredictionOptions
110106

@@ -114,7 +110,7 @@ type OpenAIRequest struct {
114110
// whisper
115111
File string `json:"file" validate:"required"`
116112
//whisper/image
117-
ResponseFormat ChatCompletionResponseFormat `json:"response_format"`
113+
ResponseFormat ChatCompletionResponseFormatType `json:"response_format,omitempty"`
118114
// image
119115
Size string `json:"size"`
120116
// Prompt is read only by completion/image API calls

swagger/docs.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,7 @@ const docTemplate = `{
477477
]
478478
},
479479
"schema.ChatCompletionResponseFormat": {
480-
"type": "object",
481-
"properties": {
482-
"type": {
483-
"type": "string"
484-
}
485-
}
480+
"type": "string"
486481
},
487482
"schema.Choice": {
488483
"type": "object",
@@ -678,11 +673,7 @@ const docTemplate = `{
678673
},
679674
"response_format": {
680675
"description": "whisper/image",
681-
"allOf": [
682-
{
683-
"$ref": "#/definitions/schema.ChatCompletionResponseFormat"
684-
}
685-
]
676+
"type": "string"
686677
},
687678
"rope_freq_base": {
688679
"type": "number"

swagger/swagger.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,7 @@
470470
]
471471
},
472472
"schema.ChatCompletionResponseFormat": {
473-
"type": "object",
474-
"properties": {
475-
"type": {
476-
"type": "string"
477-
}
478-
}
473+
"type": "string"
479474
},
480475
"schema.Choice": {
481476
"type": "object",
@@ -671,11 +666,7 @@
671666
},
672667
"response_format": {
673668
"description": "whisper/image",
674-
"allOf": [
675-
{
676-
"$ref": "#/definitions/schema.ChatCompletionResponseFormat"
677-
}
678-
]
669+
"type": "string"
679670
},
680671
"rope_freq_base": {
681672
"type": "number"

swagger/swagger.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ definitions:
164164
- Retrieval
165165
- Function
166166
schema.ChatCompletionResponseFormat:
167-
properties:
168-
type:
169-
type: string
170-
type: object
167+
type: string
171168
schema.Choice:
172169
properties:
173170
delta:
@@ -300,8 +297,7 @@ definitions:
300297
repeat_penalty:
301298
type: number
302299
response_format:
303-
allOf:
304-
- $ref: '#/definitions/schema.ChatCompletionResponseFormat'
300+
type: string
305301
description: whisper/image
306302
rope_freq_base:
307303
type: number

tests/e2e-aio/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var _ = Describe("E2E test", func() {
9393
model := "gpt-4"
9494

9595
req := openai.ChatCompletionRequest{
96-
ResponseFormat: &openai.ChatCompletionResponseFormat{Type: openai.ChatCompletionResponseFormatTypeJSONObject},
96+
ResponseFormat: "b64_json",
9797
Model: model,
9898
Messages: []openai.ChatCompletionMessage{
9999
{

0 commit comments

Comments
 (0)