93 lines
1.9 KiB
Go
93 lines
1.9 KiB
Go
package ai
|
|
|
|
import "apigo.cc/ai/agent"
|
|
|
|
type ChatMessage = agent.ChatMessage
|
|
type ChatMessageContent = agent.ChatMessageContent
|
|
type ChatModelConfig struct {
|
|
Model string
|
|
MaxTokens int
|
|
Temperature float64
|
|
TopP float64
|
|
Tools map[string]any
|
|
}
|
|
|
|
type MessagesMaker struct {
|
|
list []ChatMessage
|
|
}
|
|
|
|
func Messages() *MessagesMaker {
|
|
return &MessagesMaker{
|
|
list: make([]ChatMessage, 0),
|
|
}
|
|
}
|
|
|
|
func (m *MessagesMaker) Make() []ChatMessage {
|
|
return m.list
|
|
}
|
|
|
|
func (m *MessagesMaker) User(contents ...ChatMessageContent) *MessagesMaker {
|
|
m.list = append(m.list, ChatMessage{
|
|
Role: RoleUser,
|
|
Contents: contents,
|
|
})
|
|
return m
|
|
}
|
|
|
|
func (m *MessagesMaker) Assistant(contents ...ChatMessageContent) *MessagesMaker {
|
|
m.list = append(m.list, ChatMessage{
|
|
Role: RoleAssistant,
|
|
Contents: contents,
|
|
})
|
|
return m
|
|
}
|
|
|
|
func (m *MessagesMaker) System(contents ...ChatMessageContent) *MessagesMaker {
|
|
m.list = append(m.list, ChatMessage{
|
|
Role: RoleSystem,
|
|
Contents: contents,
|
|
})
|
|
return m
|
|
}
|
|
|
|
func (m *MessagesMaker) Tool(contents ...ChatMessageContent) *MessagesMaker {
|
|
m.list = append(m.list, ChatMessage{
|
|
Role: RoleTool,
|
|
Contents: contents,
|
|
})
|
|
return m
|
|
}
|
|
|
|
func (m *MessagesMaker) Text(text string) *MessagesMaker {
|
|
if len(m.list) > 0 {
|
|
lastIndex := len(m.list) - 1
|
|
m.list[lastIndex].Contents = append(m.list[lastIndex].Contents, ChatMessageContent{
|
|
Type: TypeText,
|
|
Content: text,
|
|
})
|
|
}
|
|
return m
|
|
}
|
|
|
|
func (m *MessagesMaker) Image(text string) *MessagesMaker {
|
|
if len(m.list) > 0 {
|
|
lastIndex := len(m.list) - 1
|
|
m.list[lastIndex].Contents = append(m.list[lastIndex].Contents, ChatMessageContent{
|
|
Type: TypeText,
|
|
Content: text,
|
|
})
|
|
}
|
|
return m
|
|
}
|
|
|
|
func (m *MessagesMaker) Video(text string) *MessagesMaker {
|
|
if len(m.list) > 0 {
|
|
lastIndex := len(m.list) - 1
|
|
m.list[lastIndex].Contents = append(m.list[lastIndex].Contents, ChatMessageContent{
|
|
Type: TypeText,
|
|
Content: text,
|
|
})
|
|
}
|
|
return m
|
|
}
|