Skip to content

Commit

Permalink
refactor: Generalize message addition with AddRoleContent method
Browse files Browse the repository at this point in the history
  • Loading branch information
presbrey committed Jan 27, 2025
1 parent d41e3d8 commit 0b250ed
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ type Chat struct {
Options Options `json:"-"`
}

// AddUserMessage adds a user message to the session
func (s *Chat) AddUserMessage(content string) {
// AddRoleContent adds a role and content to the session
func (s *Chat) AddRoleContent(role string, content any) {
s.Messages = append(s.Messages, Message{
Role: "user",
Role: role,
Content: content,
})
s.LastUpdated = time.Now()
}

// AddUserMessage adds a user message to the session
func (s *Chat) AddUserMessage(content any) {
s.AddRoleContent("user", content)
}

// AddAssistantMessage adds an assistant message to the session
func (s *Chat) AddAssistantMessage(content string) {
s.Messages = append(s.Messages, Message{
Role: "assistant",
Content: content,
})
s.LastUpdated = time.Now()
func (s *Chat) AddAssistantMessage(content any) {
s.AddRoleContent("assistant", content)
}

// AddAssistantToolCall adds an assistant message with tool calls
Expand Down

0 comments on commit 0b250ed

Please sign in to comment.