diff --git a/adapter/skylark/chat.go b/adapter/skylark/chat.go index 6fb0478..e034bab 100644 --- a/adapter/skylark/chat.go +++ b/adapter/skylark/chat.go @@ -66,26 +66,33 @@ func (c *ChatInstance) CreateRequest(props *ChatProps) *api.ChatReq { } } +func getToolCalls(choice *api.ChatResp) *globals.ToolCalls { + calls := choice.Choice.Message.FunctionCall + if calls == nil { + return nil + } + + return &globals.ToolCalls{ + globals.ToolCall{ + Type: "function", + Id: fmt.Sprintf("%s-%s", calls.Name, choice.ReqId), + Function: globals.ToolCallFunction{ + Name: calls.Name, + Arguments: calls.Arguments, + }, + }, + } +} + func getChoice(choice *api.ChatResp) *globals.Chunk { if choice == nil || choice.Choice == nil || choice.Choice.Message == nil { return &globals.Chunk{Content: ""} } message := choice.Choice.Message - - calls := message.FunctionCall return &globals.Chunk{ - Content: message.Content, - ToolCall: utils.Multi(calls != nil, &globals.ToolCalls{ - globals.ToolCall{ - Type: "function", - Id: fmt.Sprintf("%s-%s", calls.Name, choice.ReqId), - Function: globals.ToolCallFunction{ - Name: calls.Name, - Arguments: calls.Arguments, - }, - }, - }, nil), + Content: message.Content, + ToolCall: getToolCalls(choice), } } diff --git a/adapter/sparkdesk/chat.go b/adapter/sparkdesk/chat.go index e1f9b81..a6df841 100644 --- a/adapter/sparkdesk/chat.go +++ b/adapter/sparkdesk/chat.go @@ -67,6 +67,23 @@ func (c *ChatInstance) GetFunctionCalling(props *ChatProps) *FunctionsPayload { } } +func getFunctionCall(call *FunctionCall) *globals.ToolCalls { + if call == nil { + return nil + } + + return &globals.ToolCalls{ + globals.ToolCall{ + Type: "function", + Id: fmt.Sprintf("%s-%s", call.Name, call.Arguments), + Function: globals.ToolCallFunction{ + Name: call.Name, + Arguments: call.Arguments, + }, + }, + } +} + func getChoice(form *ChatResponse) *globals.Chunk { if form == nil || len(form.Payload.Choices.Text) == 0 { return &globals.Chunk{Content: ""} @@ -80,17 +97,8 @@ func getChoice(form *ChatResponse) *globals.Chunk { choice := choices[0] return &globals.Chunk{ - Content: choice.Content, - ToolCall: utils.Multi(choice.FunctionCall != nil, &globals.ToolCalls{ - globals.ToolCall{ - Type: "function", - Id: fmt.Sprintf("%s-%s", choice.FunctionCall.Name, choice.FunctionCall.Arguments), - Function: globals.ToolCallFunction{ - Name: choice.FunctionCall.Name, - Arguments: choice.FunctionCall.Arguments, - }, - }, - }, nil), + Content: choice.Content, + ToolCall: getFunctionCall(choice.FunctionCall), } }