refactor: function argument parsing using named regex (#4708)

Signed-off-by: Maximilian Kenfenheuer <maximilian.kenfenheuer@ksol.it>
This commit is contained in:
Maximilian Kenfenheuer 2025-01-28 22:58:02 +01:00 committed by GitHub
parent 91e1ff5a95
commit b4b67e00bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -331,7 +331,10 @@ func ParseFunctionCall(llmresult string, functionConfig FunctionsConfig) []FuncC
}
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.
// TODO: there might be responses where an object as a value is expected/required. This is currently not handled.
args := make(map[string]string)
@ -358,10 +361,6 @@ func ParseFunctionCallArgs(functionArguments string, functionConfig FunctionsCon
}
jsonBytes, _ := json.Marshal(args)
jsonString := string(jsonBytes)
return jsonString
} else {
return functionArguments
}
return string(jsonBytes)
}