@@ -331,37 +331,36 @@ func ParseFunctionCall(llmresult string, functionConfig FunctionsConfig) []FuncC
331
331
}
332
332
333
333
func ParseFunctionCallArgs (functionArguments string , functionConfig FunctionsConfig ) string {
334
- if len (functionConfig .ArgumentRegex ) > 0 {
335
- // We use named regexes here to extract the function argument key value pairs and convert this to valid json.
336
- // TODO: there might be responses where an object as a value is expected/required. This is currently not handled.
337
- args := make (map [string ]string )
338
-
339
- agrsRegexKeyName := "key"
340
- agrsRegexValueName := "value"
334
+ if len (functionConfig .ArgumentRegex ) == 0 {
335
+ return functionArguments
336
+ }
341
337
342
- if functionConfig .ArgumentRegexKey != "" {
343
- agrsRegexKeyName = functionConfig .ArgumentRegexKey
344
- }
345
- if functionConfig .ArgumentRegexValue != "" {
346
- agrsRegexValueName = functionConfig .ArgumentRegexValue
347
- }
338
+ // We use named regexes here to extract the function argument key value pairs and convert this to valid json.
339
+ // TODO: there might be responses where an object as a value is expected/required. This is currently not handled.
340
+ args := make (map [string ]string )
348
341
349
- for _ , r := range functionConfig .ArgumentRegex {
350
- var respRegex = regexp .MustCompile (r )
351
- var nameRange []string = respRegex .SubexpNames ()
352
- var keyIndex = slices .Index (nameRange , agrsRegexKeyName )
353
- var valueIndex = slices .Index (nameRange , agrsRegexValueName )
354
- matches := respRegex .FindAllStringSubmatch (functionArguments , - 1 )
355
- for _ , match := range matches {
356
- args [match [keyIndex ]] = match [valueIndex ]
357
- }
358
- }
342
+ agrsRegexKeyName := "key"
343
+ agrsRegexValueName := "value"
359
344
360
- jsonBytes , _ := json .Marshal (args )
361
- jsonString := string (jsonBytes )
345
+ if functionConfig .ArgumentRegexKey != "" {
346
+ agrsRegexKeyName = functionConfig .ArgumentRegexKey
347
+ }
348
+ if functionConfig .ArgumentRegexValue != "" {
349
+ agrsRegexValueName = functionConfig .ArgumentRegexValue
350
+ }
362
351
363
- return jsonString
364
- } else {
365
- return functionArguments
352
+ for _ , r := range functionConfig .ArgumentRegex {
353
+ var respRegex = regexp .MustCompile (r )
354
+ var nameRange []string = respRegex .SubexpNames ()
355
+ var keyIndex = slices .Index (nameRange , agrsRegexKeyName )
356
+ var valueIndex = slices .Index (nameRange , agrsRegexValueName )
357
+ matches := respRegex .FindAllStringSubmatch (functionArguments , - 1 )
358
+ for _ , match := range matches {
359
+ args [match [keyIndex ]] = match [valueIndex ]
360
+ }
366
361
}
362
+
363
+ jsonBytes , _ := json .Marshal (args )
364
+
365
+ return string (jsonBytes )
367
366
}
0 commit comments