Documentation
¶
Index ¶
- Constants
- func NewClient(apiKey string, debug ...bool)
- func SetDebug(debug bool)
- func SetMaxEmptyMessageCount(count int)
- type ChatRequest
- type ChatResponse
- type Choices
- type Client
- type Input
- type MessageInfo
- type Output
- type Parameters
- type StreamReader
- func (streamReader *StreamReader) Close()
- func (streamReader *StreamReader) IsFinish() bool
- func (streamReader *StreamReader) IsMaxEmptyLimit() bool
- func (streamReader *StreamReader) Reader() *bufio.Reader
- func (streamReader *StreamReader) Receive() ([]byte, error)
- func (streamReader *StreamReader) ReceiveFormat() (*ChatResponse, error)
- func (streamReader *StreamReader) Response() *ghttp.Response
- type Usage
Constants ¶
View Source
const ( // CHAT_MESSAGE_ROLE_USER 用户 CHAT_MESSAGE_ROLE_USER string = "user" // CHAT_MESSAGE_ROLE_ASSISTANT 对话助手 CHAT_MESSAGE_ROLE_ASSISTANT string = "assistant" // CHAT_MESSAGE_ROLE_SYSTEM 对话背景 CHAT_MESSAGE_ROLE_SYSTEM string = "system" // CHAT_MESSAGE_ROLE_TOOL 工具调用 CHAT_MESSAGE_ROLE_TOOL string = "tools" )
View Source
const ( // MODEL_VERSION_TURBO MODEL_VERSION_TURBO = "qwen-turbo" // MODEL_VERSION_PLUS MODEL_VERSION_PLUS = "qwen-plus" // MODEL_VERSION_MAX MODEL_VERSION_MAX = "qwen-max" // MODEL_VERSION_MAX_0403 MODEL_VERSION_MAX_0403 = "qwen-max-0403" // MODEL_VERSION_MAX_0107 MODEL_VERSION_MAX_0107 = "qwen-max-0107" // MODEL_VERSION_MAX_1201 MODEL_VERSION_MAX_1201 = "qwen-max-1201" // MODEL_VERSION_MAX_LONGTEXT MODEL_VERSION_MAX_LONGTEXT = "qwen-max-longcontext" )
View Source
const ( // RESULT_FORMAT_TEXT 旧版format RESULT_FORMAT_TEXT = "text" // RESULT_FORMAT_MESSAGE 兼容openai的message RESULT_FORMAT_MESSAGE = "message" )
Variables ¶
This section is empty.
Functions ¶
func SetMaxEmptyMessageCount ¶
func SetMaxEmptyMessageCount(count int)
SetMaxEmptyMessageCount 最大空消息数量
Types ¶
type ChatRequest ¶
type ChatRequest struct {
/*
指定用于对话的通义千问模型名
目前可选择:
qwen-turbo
qwen-plus
qwen-max
qwen-max-0403
qwen-max-0107
qwen-max-1201
qwen-max-longcontext
*/
Model string `json:"model"`
// 输入参数
Input Input `json:"input,omitempty"`
// 模型参数设置
Parameters Parameters `json:"parameters,omitempty"`
}
ChatRequest
type ChatResponse ¶
type ChatResponse struct {
// 本次输出
Output Output `json:"output"`
// 请求ID
RequestId string `json:"request_id"`
}
ChatResponse
type Choices ¶
type Choices struct {
/*
停止原因,null:生成过程中
stop:stop token导致结束
length:生成长度导致结束
*/
FinishReason string `json:"finish_reason"`
// 消息数据
Message MessageInfo `json:"message"`
}
Choices
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client API请求客户端
func (*Client) Chat ¶
func (c *Client) Chat(chatRequest *ChatRequest) (*ChatResponse, error)
Chat 对话方法
func (*Client) ChatStream ¶
func (c *Client) ChatStream(chatRequest *ChatRequest) (*StreamReader, error)
ChatStream 流式对话方法
type Input ¶
type Input struct {
// 提示词
Prompt string `json:"prompt"`
// 历史消息列表
Messages []MessageInfo `json:"messages,omitempty"`
}
Input
type MessageInfo ¶
type MessageInfo struct {
// system、user、assistant和tool
Role string `json:"role,omitempty"`
// 消息内容
Content string `json:"content,omitempty"`
}
MessageInfo
type Output ¶
type Output struct {
// 本次算法输出内容
Text string `json:"text"`
// 有三种情况:正在生成时为null,生成结束时如果由于停止token导致则为stop,生成结束时如果因为生成长度过长导致则为length。
FinishReason string `json:"finish_reason"`
// 入参result_format=message时候的返回值
Choices []Choices `json:"choices"`
}
Output
type Parameters ¶
type Parameters struct {
// "text"表示旧版本的text
// "message"表示兼容openai的message
ResultFormat string `json:"result_format,omitempty"`
// 随机种子
Seed int64 `json:"seed,omitempty"`
// 输出最大token限制
MaxTokens int64 `json:"max_tokens,omitempty"`
// 概率阀值
TopP float32 `json:"top_p,omitempty"`
// 候选集大小
TopK int `json:"top_k,omitempty"`
// 模型重复度控制
RepetitionPenalty float32 `json:"repetition_penalty,omitempty"`
// 多样性程度控制
Temperature float32 `json:"temperature,omitempty"`
// 停止生成标识
Stop []string `json:"stop,omitempty"`
// 是否启用联网搜索
EnableSearch bool `json:"enable_search,omitempty"`
// 控制流输出模式,如果设置为true,那么采用的就是增量输出
IncrementalOutput bool `json:"incremental_output,omitempty"`
}
Parameters
type StreamReader ¶
type StreamReader struct {
// contains filtered or unexported fields
}
func ChatStream ¶
func ChatStream(chatRequest *ChatRequest) (*StreamReader, error)
ChatStream 流式对话接口
func (*StreamReader) IsMaxEmptyLimit ¶
func (streamReader *StreamReader) IsMaxEmptyLimit() bool
IsFinish
func (*StreamReader) ReceiveFormat ¶
func (streamReader *StreamReader) ReceiveFormat() (*ChatResponse, error)
ReceiveFormat
func (*StreamReader) Response ¶
func (streamReader *StreamReader) Response() *ghttp.Response
Response
Click to show internal directories.
Click to hide internal directories.