From 6b06d4e0af4db7a8aa8e131ec2b3af171934862e Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Tue, 16 Apr 2024 23:20:11 +0200 Subject: [PATCH] fix(fncall): fix regression introduced in #1963 (#2048) Signed-off-by: Dave --------- Signed-off-by: Ettore Di Giacinto Signed-off-by: Dave Co-authored-by: Dave --- core/services/openai.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/services/openai.go b/core/services/openai.go index 3fa041f5..7a2679ad 100644 --- a/core/services/openai.go +++ b/core/services/openai.go @@ -778,13 +778,16 @@ func parseFunctionCall(llmresult string, multipleResults bool) []funcCallResults // As we have to change the result before processing, we can't stream the answer token-by-token (yet?) ss := map[string]interface{}{} // This prevent newlines to break JSON parsing for clients - // s := utils.EscapeNewLines(llmresult) - json.Unmarshal([]byte(llmresult), &ss) + s := utils.EscapeNewLines(llmresult) + if err := json.Unmarshal([]byte(s), &ss); err != nil { + log.Error().Msgf("error unmarshalling JSON: %s", err.Error()) + return results + } // The grammar defines the function name as "function", while OpenAI returns "name" func_name, ok := ss["function"] if !ok { - log.Debug().Msg("ss[function] is not OK!") + log.Debug().Msgf("ss[function] is not OK!, llm result: %q", llmresult) return results } // Similarly, while here arguments is a map[string]interface{}, OpenAI actually want a stringified object