mirror of
https://github.com/mudler/LocalAI.git
synced 2025-06-29 22:20:43 +00:00
fix(completionEndpoint): don't remove existing functionality
This commit is contained in:
parent
cd6a0b1ff8
commit
493828b9d7
1 changed files with 32 additions and 18 deletions
|
@ -190,6 +190,11 @@ func completionEndpoint(cm *ConfigMerger, o *Option) func(c *fiber.Ctx) error {
|
||||||
templateFile = config.TemplateConfig.Completion
|
templateFile = config.TemplateConfig.Completion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if input.Stream {
|
||||||
|
if (len(config.PromptStrings) > 1) {
|
||||||
|
return errors.New("cannot handle more than 1 `PromptStrings` when `Stream`ing")
|
||||||
|
}
|
||||||
|
|
||||||
predInput := config.PromptStrings[0]
|
predInput := config.PromptStrings[0]
|
||||||
|
|
||||||
// A model can have a "file.bin.tmpl" file associated with a prompt template prefix
|
// A model can have a "file.bin.tmpl" file associated with a prompt template prefix
|
||||||
|
@ -201,11 +206,6 @@ func completionEndpoint(cm *ConfigMerger, o *Option) func(c *fiber.Ctx) error {
|
||||||
log.Debug().Msgf("Template found, input modified to: %s", predInput)
|
log.Debug().Msgf("Template found, input modified to: %s", predInput)
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.Stream {
|
|
||||||
if (len(config.PromptStrings) > 1) {
|
|
||||||
return errors.New("cannot handle more than 1 `PromptStrings` when `Stream`ing")
|
|
||||||
}
|
|
||||||
|
|
||||||
responses := make(chan OpenAIResponse)
|
responses := make(chan OpenAIResponse)
|
||||||
|
|
||||||
go process(predInput, input, config, o.loader, responses)
|
go process(predInput, input, config, o.loader, responses)
|
||||||
|
@ -235,13 +235,27 @@ func completionEndpoint(cm *ConfigMerger, o *Option) func(c *fiber.Ctx) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := ComputeChoices(predInput, input, config, o.loader, func(s string, c *[]Choice) {
|
var result []Choice
|
||||||
|
for _, i := range config.PromptStrings {
|
||||||
|
// A model can have a "file.bin.tmpl" file associated with a prompt template prefix
|
||||||
|
templatedInput, err := o.loader.TemplatePrefix(templateFile, struct {
|
||||||
|
Input string
|
||||||
|
}{Input: i})
|
||||||
|
if err == nil {
|
||||||
|
i = templatedInput
|
||||||
|
log.Debug().Msgf("Template found, input modified to: %s", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := ComputeChoices(i, input, config, o.loader, func(s string, c *[]Choice) {
|
||||||
*c = append(*c, Choice{Text: s})
|
*c = append(*c, Choice{Text: s})
|
||||||
}, nil)
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = append(result, r...)
|
||||||
|
}
|
||||||
|
|
||||||
resp := &OpenAIResponse{
|
resp := &OpenAIResponse{
|
||||||
Model: input.Model, // we have to return what the user sent here, due to OpenAI spec.
|
Model: input.Model, // we have to return what the user sent here, due to OpenAI spec.
|
||||||
Choices: result,
|
Choices: result,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue