Skip to content

Commit

Permalink
fix: auto get role
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Feb 18, 2024
1 parent e2b10f9 commit 72c55d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions globals/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
User = "user"
Assistant = "assistant"
Tool = "tool"
Function = "function"
)

const (
Expand Down
13 changes: 13 additions & 0 deletions manager/chat_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ func getFinishReason(buffer *utils.Buffer, end bool) interface{} {
return ReasonStop
}

func getRole(data *globals.Chunk) string {
if data.Content != "" {
return globals.Assistant
} else if data.ToolCall != nil {
return globals.Tool
} else if data.FunctionCall != nil {
return globals.Function
}

return ""
}

func getStreamTranshipmentForm(id string, created int64, form RelayForm, data *globals.Chunk, buffer *utils.Buffer, end bool, err error) RelayStreamResponse {
return RelayStreamResponse{
Id: fmt.Sprintf("chatcmpl-%s", id),
Expand All @@ -166,6 +178,7 @@ func getStreamTranshipmentForm(id string, created int64, form RelayForm, data *g
{
Index: 0,
Delta: Message{
Role: getRole(data),
Content: data.Content,
ToolCalls: data.ToolCall,
FunctionCall: data.FunctionCall,
Expand Down

0 comments on commit 72c55d8

Please sign in to comment.