-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.go
36 lines (30 loc) · 871 Bytes
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package minds
import (
"encoding/json"
)
type Role string
const (
RoleUser Role = "user"
RoleAssistant Role = "assistant"
RoleSystem Role = "system"
RoleFunction Role = "function"
RoleTool Role = "tool"
RoleAI Role = "ai"
RoleModel Role = "model"
RoleDeveloper Role = "developer"
)
type Message struct {
Role Role `json:"role"`
Content string `json:"content"`
Name string `json:"name,omitempty"` // For function calls
Metadata Metadata `json:"metadata,omitempty"` // For additional context
ToolCallID string `json:"tool_call_id,omitempty"`
ToolCalls []ToolCall `json:"func_response,omitempty"`
}
func (m Message) TokenCount(tokenizer TokenCounter) (int, error) {
wholeMsg, err := json.Marshal(m)
if err != nil {
return 0, err
}
return tokenizer.CountTokens(string(wholeMsg))
}