mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 21:10:18 +09:00
fix: fix sparkdesk and skylark function calling pointer is nil fatal (#96)
This commit is contained in:
parent
e8d5c3548c
commit
5adc0fd815
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user