mirror of
https://github.com/mudler/LocalAI.git
synced 2025-06-17 14:38:08 +00:00
refactor: function argument parsing using named regex (#4708)
Signed-off-by: Maximilian Kenfenheuer <maximilian.kenfenheuer@ksol.it>
This commit is contained in:
committed by
GitHub
parent
91e1ff5a95
commit
b4b67e00bd
@ -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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user