mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-28 14:35:00 +00:00
feat(image): support response_type
in the OpenAI API request (#2347)
* Change response_format type to string to match OpenAI Spec Signed-off-by: prajwal <prajwalnayak7@gmail.com> * updated response_type type to interface Signed-off-by: prajwal <prajwalnayak7@gmail.com> * feat: correctly parse generic struct Signed-off-by: mudler <mudler@localai.io> * add tests Signed-off-by: mudler <mudler@localai.io> --------- Signed-off-by: prajwal <prajwalnayak7@gmail.com> Signed-off-by: mudler <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@users.noreply.github.com> Co-authored-by: mudler <mudler@localai.io>
This commit is contained in:
parent
087bceccac
commit
4d98dd9ce7
7 changed files with 57 additions and 13 deletions
|
@ -183,8 +183,13 @@ func ChatEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, startup
|
|||
noActionDescription = config.FunctionsConfig.NoActionDescriptionName
|
||||
}
|
||||
|
||||
if input.ResponseFormat.Type == "json_object" {
|
||||
input.Grammar = functions.JSONBNF
|
||||
if config.ResponseFormatMap != nil {
|
||||
d := schema.ChatCompletionResponseFormat{}
|
||||
dat, _ := json.Marshal(config.ResponseFormatMap)
|
||||
_ = json.Unmarshal(dat, &d)
|
||||
if d.Type == "json_object" {
|
||||
input.Grammar = functions.JSONBNF
|
||||
}
|
||||
}
|
||||
|
||||
config.Grammar = input.Grammar
|
||||
|
|
|
@ -69,8 +69,13 @@ func CompletionEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, a
|
|||
return fmt.Errorf("failed reading parameters from request:%w", err)
|
||||
}
|
||||
|
||||
if input.ResponseFormat.Type == "json_object" {
|
||||
input.Grammar = functions.JSONBNF
|
||||
if config.ResponseFormatMap != nil {
|
||||
d := schema.ChatCompletionResponseFormat{}
|
||||
dat, _ := json.Marshal(config.ResponseFormatMap)
|
||||
_ = json.Unmarshal(dat, &d)
|
||||
if d.Type == "json_object" {
|
||||
input.Grammar = functions.JSONBNF
|
||||
}
|
||||
}
|
||||
|
||||
config.Grammar = input.Grammar
|
||||
|
|
|
@ -149,10 +149,8 @@ func ImageEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, appCon
|
|||
return fmt.Errorf("invalid value for 'size'")
|
||||
}
|
||||
|
||||
b64JSON := false
|
||||
if input.ResponseFormat.Type == "b64_json" {
|
||||
b64JSON = true
|
||||
}
|
||||
b64JSON := config.ResponseFormat == "b64_json"
|
||||
|
||||
// src and clip_skip
|
||||
var result []schema.Item
|
||||
for _, i := range config.PromptStrings {
|
||||
|
|
|
@ -129,6 +129,15 @@ func updateRequestConfig(config *config.BackendConfig, input *schema.OpenAIReque
|
|||
config.Maxtokens = input.Maxtokens
|
||||
}
|
||||
|
||||
if input.ResponseFormat != nil {
|
||||
switch responseFormat := input.ResponseFormat.(type) {
|
||||
case string:
|
||||
config.ResponseFormat = responseFormat
|
||||
case map[string]interface{}:
|
||||
config.ResponseFormatMap = responseFormat
|
||||
}
|
||||
}
|
||||
|
||||
switch stop := input.Stop.(type) {
|
||||
case string:
|
||||
if stop != "" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue