Matt Low
3fde58b77d
- More emphasis on `api` package. It now holds database model structs from `lmcli/models` (which is now gone) as well as the tool spec, call, and result types. `tools.Tool` is now `api.ToolSpec`. `api.ChatCompletionClient` was renamed to `api.ChatCompletionProvider`. - Change ChatCompletion interface and implementations to no longer do automatic tool call recursion - they simply return a ToolCall message which the caller can decide what to do with (e.g. prompt for user confirmation before executing) - `api.ChatCompletionProvider` functions have had their ReplyCallback parameter removed, as now they only return a single reply. - Added a top-level `agent` package, moved the current built-in tools implementations under `agent/toolbox`. `tools.ExecuteToolCalls` is now `agent.ExecuteToolCalls`. - Fixed request context handling in openai, google, ollama (use `NewRequestWithContext`), cleaned up request cancellation in TUI - Fix tool call tui persistence bug (we were skipping message with empty content) - Now handle tool calling from TUI layer TODO: - Prompt users before executing tool calls - Automatically send tool results to the model (or make this toggleable)
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package api
|
|
|
|
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 {
|
|
ID uint `gorm:"primaryKey"`
|
|
ConversationID *uint `gorm:"index"`
|
|
Conversation *Conversation `gorm:"foreignKey:ConversationID"`
|
|
Content string
|
|
Role MessageRole
|
|
CreatedAt time.Time
|
|
ToolCalls ToolCalls // a json array of tool calls (from the model)
|
|
ToolResults ToolResults // a json array of tool results
|
|
ParentID *uint
|
|
Parent *Message `gorm:"foreignKey:ParentID"`
|
|
Replies []Message `gorm:"foreignKey:ParentID"`
|
|
|
|
SelectedReplyID *uint
|
|
SelectedReply *Message `gorm:"foreignKey:SelectedReplyID"`
|
|
}
|
|
|
|
func (m *MessageRole) IsAssistant() bool {
|
|
switch *m {
|
|
case MessageRoleAssistant, MessageRoleToolCall:
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// FriendlyRole returns a human friendly signifier for the message's role.
|
|
func (m MessageRole) FriendlyRole() string {
|
|
switch m {
|
|
case MessageRoleUser:
|
|
return "You"
|
|
case MessageRoleSystem:
|
|
return "System"
|
|
case MessageRoleAssistant:
|
|
return "Assistant"
|
|
case MessageRoleToolCall:
|
|
return "Tool Call"
|
|
case MessageRoleToolResult:
|
|
return "Tool Result"
|
|
default:
|
|
return string(m)
|
|
}
|
|
}
|