mirror of
https://github.com/hanzoai/dashscope-go-sdk.git
synced 2026-09-30 21:39:25 +00:00
57 lines
1016 B
Go
57 lines
1016 B
Go
package qwen
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
// TextConent is used for text-generation only.
|
|
type TextContent struct {
|
|
Text string
|
|
}
|
|
|
|
var _ IQwenContentMethods = &TextContent{}
|
|
|
|
func NewTextContent() *TextContent {
|
|
t := TextContent{""}
|
|
return &t
|
|
}
|
|
|
|
func (t *TextContent) ToBytes() []byte {
|
|
return []byte(t.Text)
|
|
}
|
|
|
|
func (t *TextContent) ToString() string {
|
|
return t.Text
|
|
}
|
|
|
|
func (t *TextContent) SetText(text string) {
|
|
if t == nil {
|
|
panic("TextContent is nil")
|
|
}
|
|
t.Text = text
|
|
}
|
|
|
|
func (t *TextContent) AppendText(text string) {
|
|
if t == nil {
|
|
panic("TextContent is nil")
|
|
}
|
|
t.Text += text
|
|
}
|
|
|
|
func (t *TextContent) SetImage(_ string) {
|
|
panic("TextContent does not support SetImage")
|
|
}
|
|
|
|
func (t *TextContent) SetAudio(_ string) {
|
|
panic("TextContent does not support SetAudio")
|
|
}
|
|
|
|
// redifine MarshalJSON and UnmarshalJSON.
|
|
func (t TextContent) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(t.Text)
|
|
}
|
|
|
|
func (t *TextContent) UnmarshalJSON(data []byte) error {
|
|
return json.Unmarshal(data, &t.Text)
|
|
}
|