mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
feat(functions): don't use yaml.MapSlice (#2354)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
7a480bb16f
commit
5a6d120a56
2 changed files with 11 additions and 8 deletions
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/go-skynet/LocalAI/pkg/utils"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// FunctionsConfig is the configuration for the tool/function call.
|
||||
|
@ -44,7 +43,7 @@ type FunctionsConfig struct {
|
|||
GrammarPrefix string `yaml:"grammar_prefix"`
|
||||
|
||||
// ReplaceResults allow to replace strings in the results before parsing them
|
||||
ReplaceResults yaml.MapSlice `yaml:"replace_results"`
|
||||
ReplaceResults []ReplaceResult `yaml:"replace_results"`
|
||||
|
||||
// FunctionName enable the LLM to return { "name": "function_name", "arguments": { "arg1": "value1", "arg2": "value2" } }
|
||||
// instead of { "function": "function_name", "arguments": { "arg1": "value1", "arg2": "value2" } }.
|
||||
|
@ -52,6 +51,11 @@ type FunctionsConfig struct {
|
|||
FunctionName bool `yaml:"return_name_in_function_response"`
|
||||
}
|
||||
|
||||
type ReplaceResult struct {
|
||||
Key string `yaml:"key"`
|
||||
Value string `yaml:"value"`
|
||||
}
|
||||
|
||||
type FuncCallResults struct {
|
||||
Name string
|
||||
Arguments string
|
||||
|
@ -61,7 +65,7 @@ func ParseFunctionCall(llmresult string, functionConfig FunctionsConfig) []FuncC
|
|||
log.Debug().Msgf("LLM result: %s", llmresult)
|
||||
|
||||
for _, item := range functionConfig.ReplaceResults {
|
||||
k, v := item.Key.(string), item.Value.(string)
|
||||
k, v := item.Key, item.Value
|
||||
log.Debug().Msgf("Replacing %s with %s", k, v)
|
||||
re := regexp.MustCompile(k)
|
||||
llmresult = re.ReplaceAllString(llmresult, v)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue