2024-06-12 02:35:07 -06:00
|
|
|
package api
|
2024-02-21 21:55:38 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MessageRole string
|
|
|
|
|
|
|
|
const (
|
|
|
|
MessageRoleSystem MessageRole = "system"
|
|
|
|
MessageRoleUser MessageRole = "user"
|
|
|
|
MessageRoleAssistant MessageRole = "assistant"
|
|
|
|
MessageRoleToolCall MessageRole = "tool_call"
|
|
|
|
MessageRoleToolResult MessageRole = "tool_result"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Message struct {
|
2024-06-09 12:45:22 -06:00
|
|
|
ID uint `gorm:"primaryKey"`
|
|
|
|
ConversationID *uint `gorm:"index"`
|
|
|
|
Conversation *Conversation `gorm:"foreignKey:ConversationID"`
|
2024-02-21 21:55:38 -07:00
|
|
|
Content string
|
|
|
|
Role MessageRole
|
|
|
|
CreatedAt time.Time
|
2024-05-20 12:12:44 -06:00
|
|
|
ToolCalls ToolCalls // a json array of tool calls (from the model)
|
2024-02-21 21:55:38 -07:00
|
|
|
ToolResults ToolResults // a json array of tool results
|
2024-05-20 12:12:44 -06:00
|
|
|
ParentID *uint
|
2024-06-09 12:45:22 -06:00
|
|
|
Parent *Message `gorm:"foreignKey:ParentID"`
|
|
|
|
Replies []Message `gorm:"foreignKey:ParentID"`
|
2024-05-20 12:12:44 -06:00
|
|
|
|
|
|
|
SelectedReplyID *uint
|
|
|
|
SelectedReply *Message `gorm:"foreignKey:SelectedReplyID"`
|
2024-02-21 21:55:38 -07:00
|
|
|
}
|
|
|
|
|
2024-03-22 11:51:01 -06:00
|
|
|
func (m *MessageRole) IsAssistant() bool {
|
|
|
|
switch *m {
|
|
|
|
case MessageRoleAssistant, MessageRoleToolCall:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-02-21 21:55:38 -07:00
|
|
|
// FriendlyRole returns a human friendly signifier for the message's role.
|
2024-03-26 01:59:39 -06:00
|
|
|
func (m MessageRole) FriendlyRole() string {
|
|
|
|
switch m {
|
2024-02-21 21:55:38 -07:00
|
|
|
case MessageRoleUser:
|
2024-03-22 11:51:01 -06:00
|
|
|
return "You"
|
2024-02-21 21:55:38 -07:00
|
|
|
case MessageRoleSystem:
|
2024-03-22 11:51:01 -06:00
|
|
|
return "System"
|
2024-02-21 21:55:38 -07:00
|
|
|
case MessageRoleAssistant:
|
2024-03-22 11:51:01 -06:00
|
|
|
return "Assistant"
|
|
|
|
case MessageRoleToolCall:
|
|
|
|
return "Tool Call"
|
|
|
|
case MessageRoleToolResult:
|
|
|
|
return "Tool Result"
|
2024-02-21 21:55:38 -07:00
|
|
|
default:
|
2024-03-26 01:59:39 -06:00
|
|
|
return string(m)
|
2024-02-21 21:55:38 -07:00
|
|
|
}
|
|
|
|
}
|