Skip to content

Commit

Permalink
fix: respect OpenAI spec for response format (#1289)
Browse files Browse the repository at this point in the history
fix: properly respect OpenAI spec for response format

Signed-off-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
mudler authored Nov 15, 2023
1 parent 733b612 commit 66a558f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/openai/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func ChatEndpoint(cm *config.ConfigLoader, o *options.Option) func(c *fiber.Ctx)
noActionDescription = config.FunctionsConfig.NoActionDescriptionName
}

if input.ResponseFormat == "json_object" {
if input.ResponseFormat.Type == "json_object" {
input.Grammar = grammar.JSONBNF
}

Expand Down
2 changes: 1 addition & 1 deletion api/openai/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func CompletionEndpoint(cm *config.ConfigLoader, o *options.Option) func(c *fibe
return fmt.Errorf("failed reading parameters from request:%w", err)
}

if input.ResponseFormat == "json_object" {
if input.ResponseFormat.Type == "json_object" {
input.Grammar = grammar.JSONBNF
}

Expand Down
2 changes: 1 addition & 1 deletion api/openai/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func ImageEndpoint(cm *config.ConfigLoader, o *options.Option) func(c *fiber.Ctx
}

b64JSON := false
if input.ResponseFormat == "b64_json" {
if input.ResponseFormat.Type == "b64_json" {
b64JSON = true
}
// src and clip_skip
Expand Down
8 changes: 7 additions & 1 deletion api/schema/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ type OpenAIModel struct {
Object string `json:"object"`
}

type ChatCompletionResponseFormatType string

type ChatCompletionResponseFormat struct {
Type ChatCompletionResponseFormatType `json:"type,omitempty"`
}

type OpenAIRequest struct {
config.PredictionOptions

Expand All @@ -92,7 +98,7 @@ type OpenAIRequest struct {
// whisper
File string `json:"file" validate:"required"`
//whisper/image
ResponseFormat string `json:"response_format"`
ResponseFormat ChatCompletionResponseFormat `json:"response_format"`
// image
Size string `json:"size"`
// Prompt is read only by completion/image API calls
Expand Down

0 comments on commit 66a558f

Please sign in to comment.