/
content_audio.go
83 lines (66 loc) · 1.79 KB
/
content_audio.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package qwen
type AudioContent struct {
Audio string `json:"audio,omitempty"`
Text string `json:"text,omitempty"`
}
var _ IBlobContent = AudioContent{}
func (ac AudioContent) GetBlob() string {
return ac.Audio
}
// AudioContentList is used for multi-modal generation.
type AudioContentList []AudioContent
var _ IQwenContentMethods = &AudioContentList{}
func NewAudioContentList() *AudioContentList {
ac := AudioContentList(make([]AudioContent, 0))
return &ac
}
func (acList *AudioContentList) ToBytes() []byte {
if acList == nil || len(*acList) == 0 {
return []byte("")
}
return []byte((*acList)[0].Text)
}
func (acList *AudioContentList) ToString() string {
if acList == nil || len(*acList) == 0 {
return ""
}
return (*acList)[0].Text
}
func (acList *AudioContentList) SetText(s string) {
if acList == nil {
panic("AudioContentList is nil")
}
*acList = append(*acList, AudioContent{Text: s})
}
func (acList *AudioContentList) AppendText(s string) {
if acList == nil || len(*acList) == 0 {
panic("AudioContentList is nil or empty")
}
(*acList)[0].Text += s
}
func (acList *AudioContentList) SetAudio(url string) {
acList.SetBlob(url)
}
func (acList *AudioContentList) SetBlob(url string) {
if acList == nil {
panic("AudioContentList is nil or empty")
}
*acList = append(*acList, AudioContent{Audio: url})
}
func (acList *AudioContentList) PopAudioContent() (AudioContent, bool) {
blobContent, hasAudio := popBlobContent(acList)
if content, ok := blobContent.(AudioContent); ok {
return content, hasAudio
}
return AudioContent{}, false
}
func (acList *AudioContentList) ConvertToBlobList() []IBlobContent {
if acList == nil {
panic("VLContentList is nil or empty")
}
list := make([]IBlobContent, len(*acList))
for i, v := range *acList {
list[i] = v
}
return list
}