fix(fncall): fix regression introduced in #1963 (#2048)

Signed-off-by: Dave <dave@gray101.com>

---------

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: Dave <dave@gray101.com>
Co-authored-by: Dave <dave@gray101.com>
This commit is contained in:
Ettore Di Giacinto 2024-04-16 23:20:11 +02:00 committed by GitHub
parent bcaa320f36
commit 6b06d4e0af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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?) // As we have to change the result before processing, we can't stream the answer token-by-token (yet?)
ss := map[string]interface{}{} ss := map[string]interface{}{}
// This prevent newlines to break JSON parsing for clients // This prevent newlines to break JSON parsing for clients
// s := utils.EscapeNewLines(llmresult) s := utils.EscapeNewLines(llmresult)
json.Unmarshal([]byte(llmresult), &ss) 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" // The grammar defines the function name as "function", while OpenAI returns "name"
func_name, ok := ss["function"] func_name, ok := ss["function"]
if !ok { if !ok {
log.Debug().Msg("ss[function] is not OK!") log.Debug().Msgf("ss[function] is not OK!, llm result: %q", llmresult)
return results return results
} }
// Similarly, while here arguments is a map[string]interface{}, OpenAI actually want a stringified object // Similarly, while here arguments is a map[string]interface{}, OpenAI actually want a stringified object