fix(completionEndpoint): don't remove existing functionality

This commit is contained in:
samm81 2023-06-02 13:52:18 -04:00
parent cd6a0b1ff8
commit 493828b9d7
No known key found for this signature in database

View file

@ -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,