mirror of
https://github.com/coaidev/coai.git
synced 2025-05-20 05:20:15 +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 {
|
func getChoice(choice *api.ChatResp) *globals.Chunk {
|
||||||
if choice == nil || choice.Choice == nil || choice.Choice.Message == nil {
|
if choice == nil || choice.Choice == nil || choice.Choice.Message == nil {
|
||||||
return &globals.Chunk{Content: ""}
|
return &globals.Chunk{Content: ""}
|
||||||
}
|
}
|
||||||
|
|
||||||
message := choice.Choice.Message
|
message := choice.Choice.Message
|
||||||
|
|
||||||
calls := message.FunctionCall
|
|
||||||
return &globals.Chunk{
|
return &globals.Chunk{
|
||||||
Content: message.Content,
|
Content: message.Content,
|
||||||
ToolCall: utils.Multi(calls != nil, &globals.ToolCalls{
|
ToolCall: getToolCalls(choice),
|
||||||
globals.ToolCall{
|
|
||||||
Type: "function",
|
|
||||||
Id: fmt.Sprintf("%s-%s", calls.Name, choice.ReqId),
|
|
||||||
Function: globals.ToolCallFunction{
|
|
||||||
Name: calls.Name,
|
|
||||||
Arguments: calls.Arguments,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, nil),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
func getChoice(form *ChatResponse) *globals.Chunk {
|
||||||
if form == nil || len(form.Payload.Choices.Text) == 0 {
|
if form == nil || len(form.Payload.Choices.Text) == 0 {
|
||||||
return &globals.Chunk{Content: ""}
|
return &globals.Chunk{Content: ""}
|
||||||
@ -80,17 +97,8 @@ func getChoice(form *ChatResponse) *globals.Chunk {
|
|||||||
choice := choices[0]
|
choice := choices[0]
|
||||||
|
|
||||||
return &globals.Chunk{
|
return &globals.Chunk{
|
||||||
Content: choice.Content,
|
Content: choice.Content,
|
||||||
ToolCall: utils.Multi(choice.FunctionCall != nil, &globals.ToolCalls{
|
ToolCall: getFunctionCall(choice.FunctionCall),
|
||||||
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),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user