From 3cc2263dc756c6f42be89c01c03a4dfa24272664 Mon Sep 17 00:00:00 2001 From: RockYang Date: Thu, 30 May 2024 09:59:44 +0800 Subject: [PATCH] fixed bug for function call error None is not of type 'array' --- api/core/types/function.go | 1 - api/handler/chatimpl/chat_handler.go | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/api/core/types/function.go b/api/core/types/function.go index 30ac03cf..0897a7d8 100644 --- a/api/core/types/function.go +++ b/api/core/types/function.go @@ -24,5 +24,4 @@ type Function struct { Name string `json:"name"` Description string `json:"description"` Parameters map[string]interface{} `json:"parameters"` - Required interface{} `json:"required,omitempty"` } diff --git a/api/handler/chatimpl/chat_handler.go b/api/handler/chatimpl/chat_handler.go index c181e12b..4ad6965a 100644 --- a/api/handler/chatimpl/chat_handler.go +++ b/api/handler/chatimpl/chat_handler.go @@ -241,8 +241,6 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio if err != nil { continue } - required := parameters["required"] - delete(parameters, "required") tool := types.Tool{ Type: "function", Function: types.Function{ @@ -251,10 +249,8 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio Parameters: parameters, }, } - - // Fixed: compatible for gpt4-turbo-xxx model - if !strings.HasPrefix(req.Model, "gpt-4-turbo-") { - tool.Function.Required = required + if v, ok := parameters["required"]; v == nil || !ok { + tool.Function.Parameters["required"] = []string{} } tools = append(tools, tool) }