/
Conversation.go
37 lines (32 loc) · 1.05 KB
/
Conversation.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 alihealth2
import (
"sync"
)
// Conversation 结构体
type Conversation struct {
// PATIENT("患者"), DOCTOR("医生"), SYSTEM("系统")
Role string `json:"role,omitempty" xml:"role,omitempty"`
// YYYY-MM-DD HH:mm:ss格式的时间
Time string `json:"time,omitempty" xml:"time,omitempty"`
// TEXT("文本"), IMG("图片"), VOICE("语音")
ContentType string `json:"content_type,omitempty" xml:"content_type,omitempty"`
// 聊天内容,如果是图片或者语音,需要通过base64编码为String后传入。
Content string `json:"content,omitempty" xml:"content,omitempty"`
}
var poolConversation = sync.Pool{
New: func() any {
return new(Conversation)
},
}
// GetConversation() 从对象池中获取Conversation
func GetConversation() *Conversation {
return poolConversation.Get().(*Conversation)
}
// ReleaseConversation 释放Conversation
func ReleaseConversation(v *Conversation) {
v.Role = ""
v.Time = ""
v.ContentType = ""
v.Content = ""
poolConversation.Put(v)
}