Skip to content

Commit

Permalink
support tools calling in chat_completions relay
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Feb 16, 2024
1 parent c5ab97a commit dfec399
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions manager/chat_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ func sendTranshipmentResponse(c *gin.Context, form RelayForm, messages []globals
Model: form.Model,
Choices: []Choice{
{
Index: 0,
Message: globals.Message{Role: globals.Assistant, Content: buffer.ReadWithDefault(defaultMessage)},
Index: 0,
Message: globals.Message{
Role: globals.Assistant,
Content: buffer.ReadWithDefault(defaultMessage),
ToolCalls: buffer.GetToolCalls(),
},
FinishReason: "stop",
},
},
Expand All @@ -133,6 +137,11 @@ func sendTranshipmentResponse(c *gin.Context, form RelayForm, messages []globals
}

func getStreamTranshipmentForm(id string, created int64, form RelayForm, data string, buffer *utils.Buffer, end bool, err error) RelayStreamResponse {
var toolsCalling *globals.ToolCalls
if end {
toolsCalling = buffer.GetToolCalls()
}

return RelayStreamResponse{
Id: fmt.Sprintf("chatcmpl-%s", id),
Object: "chat.completion.chunk",
Expand All @@ -142,8 +151,9 @@ func getStreamTranshipmentForm(id string, created int64, form RelayForm, data st
{
Index: 0,
Delta: globals.Message{
Role: globals.Assistant,
Content: data,
Role: globals.Assistant,
Content: data,
ToolCalls: toolsCalling,
},
FinishReason: utils.Multi[interface{}](end, "stop", nil),
},
Expand Down

0 comments on commit dfec399

Please sign in to comment.