mirror of
https://github.com/hanzoai/dashscopego.git
synced 2026-10-30 18:41:14 +00:00
55 lines
932 B
Go
55 lines
932 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{
|
|
Text: "",
|
|
}
|
|
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) SetBlob(_ string) {
|
|
panic("TextContent does not support SetBlob")
|
|
}
|
|
|
|
// 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)
|
|
}
|