Documentation ¶
Index ¶
- Constants
- Variables
- func URLQwen() string
- func URLQwenAudio() string
- func URLQwenVL() string
- func UploadFileFromURL(ctx context.Context, fileURL, model, apiKey string) (string, error)
- func UploadLocalFile(ctx context.Context, filePath, model, apiKey string) (string, error)
- type AudioContent
- type AudioContentList
- func (acList *AudioContentList) AppendText(s string)
- func (acList *AudioContentList) PopAudioContent() (AudioContent, bool)
- func (acList *AudioContentList) SetAudio(url string)
- func (acList *AudioContentList) SetImage(_ string)
- func (acList *AudioContentList) SetText(s string)
- func (acList *AudioContentList) ToBytes() []byte
- func (acList *AudioContentList) ToString() string
- type CertOutput
- type CertResponse
- type Choice
- type IQwenContent
- type IQwenContentMethods
- type Input
- type Message
- type ModelQwen
- type Output
- type OutputResponse
- type Parameters
- func (p *Parameters) SetEnableSearch(value bool) *Parameters
- func (p *Parameters) SetIncrementalOutput(value bool) *Parameters
- func (p *Parameters) SetMaxTokens(value int) *Parameters
- func (p *Parameters) SetResultFormat(value string) *Parameters
- func (p *Parameters) SetSeed(value int) *Parameters
- func (p *Parameters) SetTemperature(value float64) *Parameters
- func (p *Parameters) SetTopK(value int) *Parameters
- func (p *Parameters) SetTopP(value float64) *Parameters
- type Request
- type StreamOutput
- type StreamingFunc
- type TextContent
- func (t *TextContent) AppendText(text string)
- func (t TextContent) MarshalJSON() ([]byte, error)
- func (t *TextContent) SetAudio(_ string)
- func (t *TextContent) SetImage(_ string)
- func (t *TextContent) SetText(text string)
- func (t *TextContent) ToBytes() []byte
- func (t *TextContent) ToString() string
- func (t *TextContent) UnmarshalJSON(data []byte) error
- type UploadRequest
- type Usage
- type VLContent
- type VLContentList
- func (vlist *VLContentList) AppendText(s string)
- func (vlist *VLContentList) PopImageContent() (VLContent, bool)
- func (vlist *VLContentList) SetAudio(_ string)
- func (vlist *VLContentList) SetImage(url string)
- func (vlist *VLContentList) SetText(s string)
- func (vlist *VLContentList) ToBytes() []byte
- func (vlist *VLContentList) ToString() string
- type WrapMessageError
Constants ¶
View Source
const ( DashScopeBaseURL = "https://dashscope.aliyuncs.com/api" QwenSubURL = "/v1/services/aigc/text-generation/generation" QwenVLSubURL = "/v1/services/aigc/multimodal-generation/generation" QwenAudioSubURL = QwenVLSubURL )
View Source
const DefaultTemperature = 1.0
Variables ¶
View Source
var ErrEmptyResponse = errors.New("empty response")
View Source
var ErrModelNotSet = errors.New("model is not set")
Functions ¶
func URLQwenAudio ¶
func URLQwenAudio() string
func UploadFileFromURL ¶
download and uploading a online image to aliyun oss, a oss url will be returned.
Types ¶
type AudioContent ¶
type AudioContentList ¶
type AudioContentList []AudioContent
func NewAudioContentList ¶
func NewAudioContentList() *AudioContentList
func (*AudioContentList) AppendText ¶
func (acList *AudioContentList) AppendText(s string)
func (*AudioContentList) PopAudioContent ¶
func (acList *AudioContentList) PopAudioContent() (AudioContent, bool)
func (*AudioContentList) SetAudio ¶
func (acList *AudioContentList) SetAudio(url string)
func (*AudioContentList) SetImage ¶
func (acList *AudioContentList) SetImage(_ string)
func (*AudioContentList) SetText ¶
func (acList *AudioContentList) SetText(s string)
func (*AudioContentList) ToBytes ¶
func (acList *AudioContentList) ToBytes() []byte
func (*AudioContentList) ToString ¶
func (acList *AudioContentList) ToString() string
type CertOutput ¶
type CertOutput struct { Policy string `json:"policy"` Signature string `json:"signature"` UploadDir string `json:"upload_dir"` UploadHost string `json:"upload_host"` ExpireInSeconds int `json:"expire_in_seconds"` MaxFileSizeMB int `json:"max_file_size_mb"` CapacityLimitMB int `json:"capacity_limit_mb"` OSSAccessKeyID string `json:"oss_access_key_id"` XOSSObjectACL string `json:"x_oss_object_acl"` XOSSForbidOverwrite string `json:"x_oss_forbid_overwrite"` }
type CertResponse ¶
type CertResponse struct { RequestID string `json:"request_id"` Data CertOutput `json:"data"` }
func (*CertResponse) JSONString ¶
func (c *CertResponse) JSONString() string
type Choice ¶
type Choice[T IQwenContent] struct { Message Message[T] `json:"message"` FinishReason string `json:"finish_reason"` }
type IQwenContent ¶
type IQwenContent interface { *TextContent | *VLContentList | *AudioContentList IQwenContentMethods }
qwen(text-generation) and qwen-vl(multi-modal) have different data format so define generic interfaces for them.
type IQwenContentMethods ¶
type IQwenContentMethods interface { ToBytes() []byte ToString() string SetText(text string) AppendText(text string) SetImage(url string) SetAudio(url string) }
TODO: langchaingo 中有使用这个 interface, 稍后看看是否需要重新设计.
type Input ¶
type Input[T IQwenContent] struct { Messages []Message[T] `json:"messages"` }
type Message ¶
type Message[T IQwenContent] struct { Role string `json:"role"` Content T `json:"content"` }
type ModelQwen ¶
type ModelQwen = string
const ( // text-generation model. QwenTurbo ModelQwen = "qwen-turbo" QwenPlus ModelQwen = "qwen-plus" QwenMax ModelQwen = "qwen-max" QwenMax1201 ModelQwen = "qwen-max-1201" QwenMaxLongContext ModelQwen = "qwen-max-longcontext" // multi-modal model. QwenVLPlus ModelQwen = "qwen-vl-plus" QwenAudioTurbo ModelQwen = "qwen-audio-turbo" )
type Output ¶
type Output[T IQwenContent] struct { Choices []Choice[T] `json:"choices"` }
new version response format.
type OutputResponse ¶
type OutputResponse[T IQwenContent] struct { Output Output[T] `json:"output"` Usage Usage `json:"usage"` RequestID string `json:"request_id"` }
func SendMessage ¶
func SendMessage[T IQwenContent](ctx context.Context, payload *Request[T], cli httpclient.IHttpClient, url, token string) (*OutputResponse[T], error)
func SendMessageStream ¶
func SendMessageStream[T IQwenContent](ctx context.Context, payload *Request[T], cli httpclient.IHttpClient, url, token string) (*OutputResponse[T], error)
func (*OutputResponse[T]) GetChoices ¶
func (t *OutputResponse[T]) GetChoices() []Choice[T]
func (*OutputResponse[T]) GetRequestID ¶
func (t *OutputResponse[T]) GetRequestID() string
func (*OutputResponse[T]) GetUsage ¶
func (t *OutputResponse[T]) GetUsage() Usage
type Parameters ¶
type Parameters struct { ResultFormat string `json:"result_format,omitempty"` Seed int `json:"seed,omitempty"` MaxTokens int `json:"max_tokens,omitempty"` TopP float64 `json:"top_p,omitempty"` TopK int `json:"top_k,omitempty"` Temperature float64 `json:"temperature,omitempty"` EnableSearch bool `json:"enable_search,omitempty"` IncrementalOutput bool `json:"incremental_output,omitempty"` }
func DefaultParameters ¶
func DefaultParameters() *Parameters
func NewParameters ¶
func NewParameters() *Parameters
func (*Parameters) SetEnableSearch ¶
func (p *Parameters) SetEnableSearch(value bool) *Parameters
func (*Parameters) SetIncrementalOutput ¶
func (p *Parameters) SetIncrementalOutput(value bool) *Parameters
func (*Parameters) SetMaxTokens ¶
func (p *Parameters) SetMaxTokens(value int) *Parameters
func (*Parameters) SetResultFormat ¶
func (p *Parameters) SetResultFormat(value string) *Parameters
func (*Parameters) SetSeed ¶
func (p *Parameters) SetSeed(value int) *Parameters
func (*Parameters) SetTemperature ¶
func (p *Parameters) SetTemperature(value float64) *Parameters
func (*Parameters) SetTopK ¶
func (p *Parameters) SetTopK(value int) *Parameters
func (*Parameters) SetTopP ¶
func (p *Parameters) SetTopP(value float64) *Parameters
type Request ¶
type Request[T IQwenContent] struct { Model string `json:"model"` Input Input[T] `json:"input"` Parameters *Parameters `json:"parameters,omitempty"` // streaming callback function. StreamingFn StreamingFunc `json:"-"` // qwen-vl model need to upload image to oss for recognition. HasUploadOss bool `json:"-"` }
func (*Request[T]) SetParameters ¶
func (q *Request[T]) SetParameters(value *Parameters) *Request[T]
type StreamOutput ¶
type StreamOutput[T IQwenContent] struct { ID string `json:"id"` Event string `json:"event"` HTTPStatus int `json:"http_status"` Output OutputResponse[T] `json:"output"` Err error `json:"error"` }
type TextContent ¶
type TextContent struct {
Text string
}
TextConent is used for text-generation only.
func NewTextContent ¶
func NewTextContent() *TextContent
func (*TextContent) AppendText ¶
func (t *TextContent) AppendText(text string)
func (TextContent) MarshalJSON ¶
func (t TextContent) MarshalJSON() ([]byte, error)
redifine MarshalJSON and UnmarshalJSON.
func (*TextContent) SetAudio ¶
func (t *TextContent) SetAudio(_ string)
func (*TextContent) SetImage ¶
func (t *TextContent) SetImage(_ string)
func (*TextContent) SetText ¶
func (t *TextContent) SetText(text string)
func (*TextContent) ToBytes ¶
func (t *TextContent) ToBytes() []byte
func (*TextContent) ToString ¶
func (t *TextContent) ToString() string
func (*TextContent) UnmarshalJSON ¶
func (t *TextContent) UnmarshalJSON(data []byte) error
type UploadRequest ¶
type UploadRequest struct {
File []byte `json:"file"`
}
type VLContentList ¶
type VLContentList []VLContent
VLContentList is used for multi-modal generation.
func NewVLContentList ¶
func NewVLContentList() *VLContentList
func (*VLContentList) AppendText ¶
func (vlist *VLContentList) AppendText(s string)
func (*VLContentList) PopImageContent ¶
func (vlist *VLContentList) PopImageContent() (VLContent, bool)
func (*VLContentList) SetAudio ¶
func (vlist *VLContentList) SetAudio(_ string)
func (*VLContentList) SetImage ¶
func (vlist *VLContentList) SetImage(url string)
func (*VLContentList) SetText ¶
func (vlist *VLContentList) SetText(s string)
func (*VLContentList) ToBytes ¶
func (vlist *VLContentList) ToBytes() []byte
func (*VLContentList) ToString ¶
func (vlist *VLContentList) ToString() string
type WrapMessageError ¶
func (*WrapMessageError) Error ¶
func (e *WrapMessageError) Error() string
Click to show internal directories.
Click to hide internal directories.