mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
feat(functions): better free string matching, allow to expect strings after JSON (#2445)
Allow now any non-character, both as suffix and prefix when mixed grammars are enabled Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
5dc6bace49
commit
3f7212c660
4 changed files with 43 additions and 15 deletions
|
@ -29,6 +29,9 @@ type GrammarConfig struct {
|
|||
// Prefix is the suffix to append to the grammar when being generated
|
||||
// This is useful when models prepend a tag before returning JSON
|
||||
Prefix string `yaml:"prefix"`
|
||||
|
||||
// ExpectStringsAfterJSON enables mixed string suffix
|
||||
ExpectStringsAfterJSON bool `yaml:"expect_strings_after_json"`
|
||||
}
|
||||
|
||||
// FunctionsConfig is the configuration for the tool/function call.
|
||||
|
@ -98,6 +101,9 @@ func (g GrammarConfig) Options() []func(o *GrammarOption) {
|
|||
if g.NoMixedFreeString {
|
||||
opts = append(opts, NoMixedFreeString)
|
||||
}
|
||||
if g.ExpectStringsAfterJSON {
|
||||
opts = append(opts, ExpectStringsAfterJSON)
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
|
@ -116,6 +122,9 @@ func CleanupLLMResult(llmresult string, functionConfig FunctionsConfig) string {
|
|||
}
|
||||
|
||||
func ParseTextContent(llmresult string, functionConfig FunctionsConfig) string {
|
||||
log.Debug().Msgf("ParseTextContent: %s", llmresult)
|
||||
log.Debug().Msgf("CaptureLLMResult: %s", functionConfig.CaptureLLMResult)
|
||||
|
||||
for _, r := range functionConfig.CaptureLLMResult {
|
||||
// We use a regex to extract the JSON object from the response
|
||||
var respRegex = regexp.MustCompile(r)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue