Documentation
¶
Index ¶
- Constants
- Variables
- func GiteeAIModels() []string
- func HttpPost(ai IAI)
- type AI
- type Choices
- type FuncParameter
- type FuncParameterType
- type FuncParameters
- type Function
- type GiteeAI
- func (m *GiteeAI) API() string
- func (m *GiteeAI) APIKey() string
- func (m *GiteeAI) Chat(content string)
- func (m *GiteeAI) ChatRole(content string, role Role)
- func (m *GiteeAI) ChatStream(content string)
- func (m *GiteeAI) ChatStreamRole(content string, role Role)
- func (m *GiteeAI) Header() http.Header
- func (m *GiteeAI) IsSupportTool() bool
- func (m *GiteeAI) MetaData() *MetaData
- func (m *GiteeAI) Model() string
- func (m *GiteeAI) Options() *Options
- func (m *GiteeAI) Request()
- func (m *GiteeAI) SetModel(name GiteeAIModelNameEnum)
- type GiteeAIModelNameEnum
- type IAI
- type IGiteeAI
- type LogitBias
- type Message
- type Messages
- type MetaData
- type Options
- type ResponseFormat
- type Role
- type TChoice
- type TDelta
- type TMessage
- type TOnFail
- type TOnReceive
- type TResponse
- type TResponseError
- type TResponseErrorOther
- type TUsage
- type Tool
- type Tools
Constants ¶
View Source
const ( AUTHORIZATION = "Authorization" CONTENT_TYPE = "Content-Type" )
View Source
const ( RoleUser = "user" // RoleSystem = "system" // RoleAssistant = "assistant" // )
View Source
const ENV_AI_API_KEY = "AI_API_KEY"
View Source
const GITEE_AI = "https://ai.gitee.com/v1"
服务地址
View Source
const GITEE_AI_API = "/chat/completions"
服务接口
Variables ¶
View Source
var Debug bool
View Source
var DefaultGiteeAIMetaData = MetaData{ Model: GITEE_AI_DEEPSEEK_R1_DISTILL_QWEN_32B.Value(), Messages: make(Messages, 0), }
DefaultGiteeAIMetaData 默认模型参数配置
View Source
var DefaultGiteeAIOptions = Options{ BaseURL: GITEE_AI, API: GITEE_AI_API, APIKey: os.Getenv(ENV_AI_API_KEY), }
DefaultGiteeAIOptions 默认选项配置
Functions ¶
func GiteeAIModels ¶ added in v1.0.1
func GiteeAIModels() []string
Types ¶
type AI ¶ added in v1.0.2
type AI struct {
// contains filtered or unexported fields
}
AI 基础实现
func (*AI) OnReceive ¶ added in v1.0.2
func (m *AI) OnReceive() TOnReceive
func (*AI) SetOnReceive ¶ added in v1.0.2
func (m *AI) SetOnReceive(fn TOnReceive)
type FuncParameter ¶
type FuncParameter struct {
Type FuncParameterType `json:"type,omitempty"`
Description string `json:"description,omitempty"`
}
FuncParameter 模型调用的工具函数参数
type FuncParameterType ¶
type FuncParameterType string
FuncParameterType 工具函数参数类型
const ( FptInteger FuncParameterType = "integer" FptString FuncParameterType = "string" FptFloat FuncParameterType = "float" )
type FuncParameters ¶
type FuncParameters map[string]FuncParameter
FuncParameters 模型调用的工具函数参数列表
func (*FuncParameters) Add ¶
func (m *FuncParameters) Add(name string, type_ FuncParameterType, description string)
func (*FuncParameters) AddFloat ¶
func (m *FuncParameters) AddFloat(name string, description string)
func (*FuncParameters) AddInteger ¶
func (m *FuncParameters) AddInteger(name string, description string)
func (*FuncParameters) AddString ¶
func (m *FuncParameters) AddString(name string, description string)
type Function ¶
type Function struct {
Name string `json:"name,omitempty"` // 函数的名称 required
Description string `json:"description,omitempty"` // 函数的描述
Parameters FuncParameters `json:"parameters,omitempty"` // 函数接受的参数
}
Function 模型调用的工具函数
type GiteeAI ¶
type GiteeAI struct {
AI
// contains filtered or unexported fields
}
GiteeAI Gitee AI 实现
func (*GiteeAI) ChatStream ¶
func (*GiteeAI) ChatStreamRole ¶
func (*GiteeAI) IsSupportTool ¶
func (*GiteeAI) SetModel ¶
func (m *GiteeAI) SetModel(name GiteeAIModelNameEnum)
type GiteeAIModelNameEnum ¶
type GiteeAIModelNameEnum string
gitee ai 模型列表
const ( GITEE_AI_YI_34B_CHAT GiteeAIModelNameEnum = "Yi-34B-Chat" GITEE_AI_INTERNVL2_8B GiteeAIModelNameEnum = "InternVL2-8B" GITEE_AI_INTERNVL2_5_78B GiteeAIModelNameEnum = "InternVL2.5-78B" GITEE_AI_DEEPSEEK_CODER_33B_INSTRUCT GiteeAIModelNameEnum = "deepseek-coder-33B-instruct" GITEE_AI_INTERNVL2_5_26B GiteeAIModelNameEnum = "InternVL2.5-26B" GITEE_AI_DEEPSEEK_R1_DISTILL_QWEN_1_5B GiteeAIModelNameEnum = "DeepSeek-R1-Distill-Qwen-1.5B" GITEE_AI_QWEN2_VL_72B GiteeAIModelNameEnum = "Qwen2-VL-72B" GITEE_AI_QWEN2_5_32B_INSTRUCT GiteeAIModelNameEnum = "Qwen2.5-32B-Instruct" GITEE_AI_GLM_4_9B_CHAT GiteeAIModelNameEnum = "glm-4-9b-chat" GITEE_AI_QWQ_32B_PREVIEW GiteeAIModelNameEnum = "QwQ-32B-Preview" GITEE_AI_CODEGEEX4_ALL_9B GiteeAIModelNameEnum = "codegeex4-all-9b" GITEE_AI_QWEN2_5_CODER_32B_INSTRUCT GiteeAIModelNameEnum = "Qwen2.5-Coder-32B-Instruct" GITEE_AI_DEEPSEEK_R1 GiteeAIModelNameEnum = "DeepSeek-R1" GITEE_AI_QWEN2_5_72B_INSTRUCT GiteeAIModelNameEnum = "Qwen2.5-72B-Instruct" GITEE_AI_QWEN2_5_7B_INSTRUCT GiteeAIModelNameEnum = "Qwen2.5-7B-Instruct" GITEE_AI_DEEPSEEK_R1_DISTILL_QWEN_7B GiteeAIModelNameEnum = "DeepSeek-R1-Distill-Qwen-7B" GITEE_AI_QWEN2_5_CODER_14B_INSTRUCT GiteeAIModelNameEnum = "Qwen2.5-Coder-14B-Instruct" GITEE_AI_DEEPSEEK_R1_DISTILL_QWEN_32B GiteeAIModelNameEnum = "DeepSeek-R1-Distill-Qwen-32B" GITEE_AI_QWEN2_72B_INSTRUCT GiteeAIModelNameEnum = "Qwen2-72B-Instruct" GITEE_AI_CODE_RACCOON_V1 GiteeAIModelNameEnum = "code-raccoon-v1" GITEE_AI_QWEN2_7B_INSTRUCT GiteeAIModelNameEnum = "Qwen2-7B-Instruct" GITEE_AI_DEEPSEEK_V3 GiteeAIModelNameEnum = "DeepSeek-V3" GITEE_AI_QWEN2_5_14B_INSTRUCT GiteeAIModelNameEnum = "Qwen2.5-14B-Instruct" GITEE_AI_DEEPSEEK_R1_DISTILL_QWEN_14B GiteeAIModelNameEnum = "DeepSeek-R1-Distill-Qwen-14B" )
type IAI ¶
type IAI interface {
API() string // AI API 服务地址
Model() string // 模型名称
APIKey() string // 服务商 API KEY
IsSupportTool() bool // 模型是否支持工具
MetaData() *MetaData // 模型源数据参数
Header() http.Header // 请求头
History() *Messages // 历史消息列表, 包括当前消息
OnFail() TOnFail // 消息接收时, 返回失败时回调函数
OnReceive() TOnReceive // 消息接收时, 返回成功时消息接收
SetOnFail(fn TOnFail) // 设置 失败回调函数
SetOnReceive(fn TOnReceive) // 设置 消息接收回调函数
System(content string) // 用于预先定义模型的基础行为框架和响应风格
}
IAI 基础接口
type IGiteeAI ¶
type IGiteeAI interface {
IAI
SetModel(name GiteeAIModelNameEnum) // 设置当前模型
ChatRole(content string, role Role) // 带有角色的聊天, 发送消息并以普通方式全量返回
ChatStreamRole(content string, role Role) // 带有角色的聊天, 发送消息并以流方式返回
Chat(content string) // 发送消息并以普通方式全量返回
ChatStream(content string) // 发送消息并以流方式返回
Options() *Options // 返回当前选项
}
IGiteeAI gitee ai 模型接口
func NewGiteeAI ¶
NewGiteeAI 创建一个 Gitee AI
type MetaData ¶
type MetaData struct {
Model string `json:"model,omitempty"` // 模型 required
Messages Messages `json:"messages,omitempty"` // 包含当前会话所有消息的列表
Stream bool `json:"stream"` // 是否是流式输出
MaxTokens int `json:"max_tokens,omitempty"` // 最大生成长度 default: 0
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"` // 频率惩罚 default: 0
PresencePenalty float32 `json:"presence_penalty,omitempty"` // 存在惩罚 default: 0
Stop []string `json:"stop,omitempty"` // 停止词
Temperature float32 `json:"temperature,omitempty"` // 温度 default: 1
TopP float32 `json:"top_p,omitempty"` // Top p default: 1
TopLogprobs int `json:"top_logprobs,omitempty"` // Top Logprobs default: 0
ResponseFormat ResponseFormat `json:"response_format,omitempty"` // 响应格式
Seed int `json:"seed,omitempty"` // 随机种子 default: 0
N int `json:"n,omitempty"` // 生成数量 default: 1
LogitBias LogitBias `json:"logit_bias,omitempty"` // 对数偏差 additional properties double min: -100 max: 100 default: {"1000": 99.9, "1001": -99.9}
User string `json:"user,omitempty"` // 客户侧的用户标识 string | nullable
Tools Tools `json:"tools,omitempty"` // 模型可以调用的工具列表。目前仅支持函数作为工具 array object[]
GuidedJSON any `json:"guided_json,omitempty"` // 如果指定,输出将遵循JSON模式 anyof
GuidedChoice []string `json:"guided_choice,omitempty"` // 如果指定,输出将恰好是其中一个选项
}
MetaData 元数据参数配置
type ResponseFormat ¶
ResponseFormat 响应格式
func (*ResponseFormat) Add ¶
func (m *ResponseFormat) Add(name, value string)
type TResponseError ¶
type TResponseError struct {
Code string
Message string
Type string
Other TResponseErrorOther
}
type TResponseErrorOther ¶
func (*TResponseErrorOther) Get ¶
func (m *TResponseErrorOther) Get(name string) string
Click to show internal directories.
Click to hide internal directories.