-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.go
37 lines (32 loc) · 1011 Bytes
/
chat.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
37
package ollama
// Chat stores the messages sent from the user and received from the assistant.
type Chat struct {
ID string
Messages []Message
}
// AddMessage adds a new message to the end of the chat.
//
// Parameters:
// - m: The message to add.
func (c *Chat) AddMessage(m Message) {
c.Messages = append(c.Messages, m)
}
// AddMessageTo adds a new message at the specified index.
//
// Parameters:
// - index: The index at which to add the new message.
// - m: The message to add.
func (c *Chat) AddMessageTo(index int, m Message) {
c.Messages = append(c.Messages[:index], append([]Message{m}, c.Messages[index:]...)...)
}
// DeleteMessage deletes a message at the specified index.
//
// Parameters:
// - index: The index of the message to delete.
func (c *Chat) DeleteMessage(index int) {
c.Messages = append(c.Messages[:index], c.Messages[index+1:]...)
}
// DeleteAllMessages deletes all messages in the chat.
func (c *Chat) DeleteAllMessages() {
c.Messages = make([]Message, 0)
}