Documentation
¶
Overview ¶
github.com/dingdinglz/openai 致力于解决对支持openai协议的ai的调用 如国内的deepseek,kimi等,以及gemini通过特定的程式可以转为openai协议
Index ¶
- Constants
- func GenerateImageUrlBase64(file []byte) string
- type ChatRequest
- type ChatToolFuctionDetail
- type ChatToolFuctionPropertie
- type ChatToolFunction
- type ChatToolParameters
- type ChatToolRequest
- type Client
- func (client Client) Chat(model string, messages []Message) (*Message, error)
- func (client Client) ChatReasonStream(model string, messages []Message, think func(string), during func(string)) error
- func (client Client) ChatStream(model string, messages []Message, during func(string)) error
- func (client Client) ChatStreamWithConfig(config ChatRequest, during func(string)) error
- func (client Client) ChatVisionStream(model string, messages []VisionMessage, during func(string)) error
- func (client Client) ChatWithConfig(config ChatRequest) (*Message, error)
- func (client *Client) ChatWithTools(model string, messages []ToolMessage, toolInfo []ChatToolFunction, ...) error
- func (client Client) EasyChat(model string, prompt string, message string) (string, error)
- func (client *Client) Models() ([]Model, error)
- type ClientConfig
- type Message
- type Model
- type ToolMessage
- type VisionChatRequest
- type VisionContent
- type VisionContentImageUrl
- type VisionMessage
Constants ¶
View Source
const ( VISION_MESSAGE_IMAGE_URL = "image_url" VISION_MESSAGE_TEXT = "text" IMAGE_DETAIL_HIGH = "high" IMAGE_DETAIL_LOW = "low" IMAGE_DETAIL_AUTO = "auto" )
Variables ¶
This section is empty.
Functions ¶
func GenerateImageUrlBase64 ¶ added in v1.1.0
Types ¶
type ChatRequest ¶
type ChatRequest struct { Messages []Message `json:"messages"` Model string `json:"model"` FrequencyPenalty int `json:"frequency_penalty"` MaxTokens int `json:"max_tokens,omitempty"` PresencePenalty int `json:"presence_penalty"` ResponseFormat struct { Type string `json:"type"` } `json:"response_format"` Stop []string `json:"stop"` Stream bool `json:"stream"` Temperature float32 `json:"temperature"` TopP int `json:"top_p"` }
type ChatToolFuctionDetail ¶ added in v1.0.3
type ChatToolFuctionDetail struct { Name string `json:"name"` Description string `json:"description"` Parameters ChatToolParameters `json:"parameters"` }
type ChatToolFuctionPropertie ¶ added in v1.0.3
type ChatToolFunction ¶ added in v1.0.3
type ChatToolFunction struct { Type string `json:"type"` Function ChatToolFuctionDetail `json:"function"` }
type ChatToolParameters ¶ added in v1.0.3
type ChatToolParameters struct { Type string `json:"type"` Properties map[string]ChatToolFuctionPropertie `json:"properties"` Required []string `json:"required"` }
type ChatToolRequest ¶ added in v1.0.3
type ChatToolRequest struct { Messages []ToolMessage `json:"messages"` Model string `json:"model"` FrequencyPenalty int `json:"frequency_penalty"` MaxTokens int `json:"max_tokens,omitempty"` PresencePenalty int `json:"presence_penalty"` ResponseFormat struct { Type string `json:"type"` } `json:"response_format"` Stop []string `json:"stop"` Stream bool `json:"stream"` Temperature float32 `json:"temperature"` TopP int `json:"top_p"` Tools []ChatToolFunction `json:"tools"` }
type Client ¶
type Client struct {
Config *ClientConfig
}
Client 是请求客户端,可以通过client调用不同的api
func NewClient ¶
func NewClient(config *ClientConfig) *Client
func (Client) ChatReasonStream ¶ added in v1.0.1
func (client Client) ChatReasonStream(model string, messages []Message, think func(string), during func(string)) error
相比于ChatStream,ChatReasonStream支持了深度思考的模型
func (Client) ChatStream ¶
api /chat/completions 的流式实现
func (Client) ChatStreamWithConfig ¶
func (client Client) ChatStreamWithConfig(config ChatRequest, during func(string)) error
api /chat/completions 的高自定义度流式实现
func (Client) ChatVisionStream ¶ added in v1.1.0
func (client Client) ChatVisionStream(model string, messages []VisionMessage, during func(string)) error
func (Client) ChatWithConfig ¶
func (client Client) ChatWithConfig(config ChatRequest) (*Message, error)
api /chat/completions 的高自定义度实现
func (*Client) ChatWithTools ¶ added in v1.0.3
func (client *Client) ChatWithTools(model string, messages []ToolMessage, toolInfo []ChatToolFunction, functionMap map[string](func(map[string]interface{}) string), during func(string)) error
type ClientConfig ¶
type ClientConfig struct { // 模型api的地址,例如:https://api.deepseek.com // // 请不要在结尾处加上/ 例如:https://api.deepseek.com合法,而https://api.deepseek.com/不合法 BaseUrl string ApiKey string // api key }
type ToolMessage ¶ added in v1.0.3
type VisionChatRequest ¶ added in v1.1.0
type VisionChatRequest struct { Messages []VisionMessage `json:"messages"` Model string `json:"model"` FrequencyPenalty int `json:"frequency_penalty"` MaxTokens int `json:"max_tokens,omitempty"` PresencePenalty int `json:"presence_penalty"` ResponseFormat struct { Type string `json:"type"` } `json:"response_format"` Stop []string `json:"stop"` Stream bool `json:"stream"` Temperature float32 `json:"temperature"` TopP int `json:"top_p"` }
type VisionContent ¶ added in v1.1.0
type VisionContent struct { // VISION_MESSAGE_ Type string `json:"type"` Text string `json:"text,omitempty"` ImageUrl *VisionContentImageUrl `json:"image_url,omitempty"` }
type VisionContentImageUrl ¶ added in v1.1.0
type VisionMessage ¶ added in v1.1.0
type VisionMessage struct { Content []VisionContent `json:"content"` Role string `json:"role"` }
Source Files
¶
Click to show internal directories.
Click to hide internal directories.