mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 18:45:00 +00:00
refactor: function argument parsing using named regex (#4708)
Signed-off-by: Maximilian Kenfenheuer <maximilian.kenfenheuer@ksol.it>
This commit is contained in:
parent
91e1ff5a95
commit
b4b67e00bd
1 changed files with 30 additions and 31 deletions
|
@ -331,7 +331,10 @@ func ParseFunctionCall(llmresult string, functionConfig FunctionsConfig) []FuncC
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseFunctionCallArgs(functionArguments string, functionConfig FunctionsConfig) string {
|
func ParseFunctionCallArgs(functionArguments string, functionConfig FunctionsConfig) string {
|
||||||
if len(functionConfig.ArgumentRegex) > 0 {
|
if len(functionConfig.ArgumentRegex) == 0 {
|
||||||
|
return functionArguments
|
||||||
|
}
|
||||||
|
|
||||||
// We use named regexes here to extract the function argument key value pairs and convert this to valid json.
|
// We use named regexes here to extract the function argument key value pairs and convert this to valid json.
|
||||||
// TODO: there might be responses where an object as a value is expected/required. This is currently not handled.
|
// TODO: there might be responses where an object as a value is expected/required. This is currently not handled.
|
||||||
args := make(map[string]string)
|
args := make(map[string]string)
|
||||||
|
@ -358,10 +361,6 @@ func ParseFunctionCallArgs(functionArguments string, functionConfig FunctionsCon
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonBytes, _ := json.Marshal(args)
|
jsonBytes, _ := json.Marshal(args)
|
||||||
jsonString := string(jsonBytes)
|
|
||||||
|
|
||||||
return jsonString
|
return string(jsonBytes)
|
||||||
} else {
|
|
||||||
return functionArguments
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue