mirror of
https://github.com/alibaba/higress.git
synced 2026-06-07 11:47:30 +08:00
feat: add ai-agent plugin (#1192)
This commit is contained in:
46
plugins/wasm-go/extensions/ai-agent/dashscope/message.go
Normal file
46
plugins/wasm-go/extensions/ai-agent/dashscope/message.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package dashscope
|
||||
|
||||
var MessageStore ChatMessages
|
||||
|
||||
func init() {
|
||||
MessageStore = make(ChatMessages, 0)
|
||||
MessageStore.Clear() //清理和初始化
|
||||
|
||||
}
|
||||
|
||||
type ChatMessages []Message
|
||||
|
||||
// 枚举出角色
|
||||
const (
|
||||
RoleUser = "user"
|
||||
RoleAssistant = "assistant"
|
||||
RoleSystem = "system"
|
||||
)
|
||||
|
||||
func (cm *ChatMessages) Clear() {
|
||||
*cm = make([]Message, 0) //重新初始化
|
||||
}
|
||||
|
||||
// 添加角色和对应的prompt
|
||||
func (cm *ChatMessages) AddFor(msg string, role string) {
|
||||
*cm = append(*cm, Message{
|
||||
Role: role,
|
||||
Content: msg,
|
||||
})
|
||||
}
|
||||
|
||||
// 添加Assistant角色的prompt
|
||||
func (cm *ChatMessages) AddForAssistant(msg string) {
|
||||
cm.AddFor(msg, RoleAssistant)
|
||||
|
||||
}
|
||||
|
||||
// 添加System角色的prompt
|
||||
func (cm *ChatMessages) AddForSystem(msg string) {
|
||||
cm.AddFor(msg, RoleSystem)
|
||||
}
|
||||
|
||||
// 添加User角色的prompt
|
||||
func (cm *ChatMessages) AddForUser(msg string) {
|
||||
cm.AddFor(msg, RoleUser)
|
||||
}
|
||||
Reference in New Issue
Block a user