mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
fix: respect OpenAI spec for response format (#1289)
fix: properly respect OpenAI spec for response format Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
733b612eb2
commit
66a558ff41
4 changed files with 10 additions and 4 deletions
|
@ -81,7 +81,7 @@ func ChatEndpoint(cm *config.ConfigLoader, o *options.Option) func(c *fiber.Ctx)
|
||||||
noActionDescription = config.FunctionsConfig.NoActionDescriptionName
|
noActionDescription = config.FunctionsConfig.NoActionDescriptionName
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.ResponseFormat == "json_object" {
|
if input.ResponseFormat.Type == "json_object" {
|
||||||
input.Grammar = grammar.JSONBNF
|
input.Grammar = grammar.JSONBNF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
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
|
input.Grammar = grammar.JSONBNF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ func ImageEndpoint(cm *config.ConfigLoader, o *options.Option) func(c *fiber.Ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
b64JSON := false
|
b64JSON := false
|
||||||
if input.ResponseFormat == "b64_json" {
|
if input.ResponseFormat.Type == "b64_json" {
|
||||||
b64JSON = true
|
b64JSON = true
|
||||||
}
|
}
|
||||||
// src and clip_skip
|
// src and clip_skip
|
||||||
|
|
|
@ -83,6 +83,12 @@ type OpenAIModel struct {
|
||||||
Object string `json:"object"`
|
Object string `json:"object"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ChatCompletionResponseFormatType string
|
||||||
|
|
||||||
|
type ChatCompletionResponseFormat struct {
|
||||||
|
Type ChatCompletionResponseFormatType `json:"type,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type OpenAIRequest struct {
|
type OpenAIRequest struct {
|
||||||
config.PredictionOptions
|
config.PredictionOptions
|
||||||
|
|
||||||
|
@ -92,7 +98,7 @@ type OpenAIRequest struct {
|
||||||
// whisper
|
// whisper
|
||||||
File string `json:"file" validate:"required"`
|
File string `json:"file" validate:"required"`
|
||||||
//whisper/image
|
//whisper/image
|
||||||
ResponseFormat string `json:"response_format"`
|
ResponseFormat ChatCompletionResponseFormat `json:"response_format"`
|
||||||
// image
|
// image
|
||||||
Size string `json:"size"`
|
Size string `json:"size"`
|
||||||
// Prompt is read only by completion/image API calls
|
// Prompt is read only by completion/image API calls
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue