Documentation
¶
Index ¶
- func SetArrMsgContentItemMatcher(matcher ArrMsgContentItemMatcher)
- type AIClient
- func (c *AIClient) DeleteFile(fileID string) (*DeleteFileResp, error)
- func (c *AIClient) ListFiles(param OpenAIListFilesParam) (*ListFilesResp, error)
- func (c *AIClient) MakeChatReqBytes(param OpenAIChatParam) (reqByts []byte, err error)
- func (c *AIClient) MakeChatRequest(method string, param OpenAIChatParam) (*AIRequest, error)
- func (c *AIClient) RetrieveFile(method string, fileID string) (*FileInfo, error)
- func (c *AIClient) UpdateFile(method string, param OpenAIFileCreateParam) (*FileInfo, error)
- func (c *AIClient) WithOptions(opts ...ClientOption) *AIClient
- type AIError
- type AIReqOption
- type AIRequest
- type ArrMsgContentItemMatcher
- type ChatChoice
- type ChatCompletionStreamChoiceDelta
- type ChatUsage
- type ClientDefaultParamOption
- type ClientHTTPClientOption
- type ClientOption
- type ContentFilterResults
- type DefaultArrMsgContentItemMatcher
- type DeleteFileResp
- type FileInfo
- type FileResp
- type FinishReason
- type Hate
- type HeadOption
- type ImgURL
- type ListFilesResp
- type Message
- type MsgBase
- type MsgContent
- type OpenAIChatParam
- type OpenAIFileCreateParam
- type OpenAIListFilesParam
- type PromptAnnotation
- type PromptFilterResult
- type RespAIChat
- type RespAIChatStream
- type RespOpenAI
- type Role
- type SelfHarm
- type Sexual
- type StreamChatChoice
- type TextContent
- type ToolFunc
- type UserArrContent
- type UserArrContentItem
- type UserImgContent
- type UserTextContent
- type Violence
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetArrMsgContentItemMatcher ¶
func SetArrMsgContentItemMatcher(matcher ArrMsgContentItemMatcher)
Types ¶
type AIClient ¶
type AIClient struct { Key string BaseURL string DefaultMaxToken int64 DefaultTemperature float64 // contains filtered or unexported fields }
func NewAIClient ¶
func NewAIClient(key string, baseURL string, opts ...ClientOption) *AIClient
func (*AIClient) DeleteFile ¶ added in v1.0.3
func (c *AIClient) DeleteFile(fileID string) (*DeleteFileResp, error)
func (*AIClient) ListFiles ¶ added in v1.0.3
func (c *AIClient) ListFiles(param OpenAIListFilesParam) (*ListFilesResp, error)
func (*AIClient) MakeChatReqBytes ¶ added in v1.0.1
func (c *AIClient) MakeChatReqBytes(param OpenAIChatParam) (reqByts []byte, err error)
func (*AIClient) MakeChatRequest ¶
func (c *AIClient) MakeChatRequest(method string, param OpenAIChatParam) (*AIRequest, error)
func (*AIClient) RetrieveFile ¶ added in v1.0.1
func (*AIClient) UpdateFile ¶ added in v1.0.1
func (c *AIClient) UpdateFile(method string, param OpenAIFileCreateParam) (*FileInfo, error)
func (*AIClient) WithOptions ¶
func (c *AIClient) WithOptions(opts ...ClientOption) *AIClient
type AIError ¶
type AIReqOption ¶
type AIReqOption interface {
Set(r *AIRequest)
}
type AIRequest ¶
type AIRequest struct { IsStream bool // contains filtered or unexported fields }
func (*AIRequest) WithOptions ¶
func (r *AIRequest) WithOptions(opts ...AIReqOption) *AIRequest
type ArrMsgContentItemMatcher ¶
type ArrMsgContentItemMatcher interface {
MatchContentItem(keyword string) UserArrContentItem
}
array消息内容元素匹配器,用于解析array型content字段时,匹配到合适的元素类型
type ChatChoice ¶
type ChatChoice struct { Index int `json:"index"` Message Message `json:"message"` FinishReason FinishReason `json:"finish_reason"` }
type ClientDefaultParamOption ¶
func (ClientDefaultParamOption) Set ¶
func (o ClientDefaultParamOption) Set(c *AIClient)
type ClientHTTPClientOption ¶
func (ClientHTTPClientOption) Set ¶
func (o ClientHTTPClientOption) Set(c *AIClient)
type ClientOption ¶
type ClientOption interface {
Set(c *AIClient)
}
type ContentFilterResults ¶
type DefaultArrMsgContentItemMatcher ¶
type DefaultArrMsgContentItemMatcher struct{}
func (DefaultArrMsgContentItemMatcher) MatchContentItem ¶
func (DefaultArrMsgContentItemMatcher) MatchContentItem(keyword string) UserArrContentItem
type DeleteFileResp ¶ added in v1.0.3
type FileInfo ¶ added in v1.0.1
type FileInfo struct { ID string `json:"id"` // The file identifier, which can be referenced in the API endpoints. Bytes int `json:"bytes"` // The size of the file, in bytes. CreatedAt int64 `json:"created_at"` //The Unix timestamp (in seconds) for when the file was created. FileName string `json:"filename"` // The name of the file. Object string `json:"object"` // The object type, which is always file. Purpose string `json:"purpose"` // The intended purpose of the file. Supported values are assistants, assistants_output, batch, batch_output, fine-tune, fine-tune-results and vision. Status string `json:"status"` // Deprecated StatusDetails string `json:"status_details"` // Deprecated }
type FinishReason ¶
type FinishReason string
const ( // The reason the model stopped generating tokens. // This will be stop if the model hit a natural stop point or a provided stop sequence, // length if the maximum number of tokens specified in the request was reached, // content_filter if content was omitted due to a flag from our content filters, // tool_calls if the model called a tool, // or function_call (deprecated) if the model called a function. FinishReasonStop FinishReason = "stop" FinishReasonLength FinishReason = "length" FinishReasonFunctionCall FinishReason = "function_call" FinishReasonToolCalls FinishReason = "tool_calls" FinishReasonContentFilter FinishReason = "content_filter" FinishReasonNull FinishReason = "null" )
type HeadOption ¶
func (HeadOption) Set ¶
func (o HeadOption) Set(r *AIRequest)
type ListFilesResp ¶ added in v1.0.3
type Message ¶
type Message struct { Role Role `json:"role"` Name string `json:"name,omitempty"` Content MsgContent `json:"content"` Refusal string `json:"refusal,omitempty"` // The refusal message generated by the model. ToolCalls []ToolFunc `json:"tool_calls,omitempty"` ToolCallID string `json:"tool_call_id,omitempty"` }
func (*Message) UnmarshalJSON ¶
type MsgContent ¶
type MsgContent interface { ContentType() string MatchRole(role Role) bool Text() []string CastToTextContent() (TextContent, bool) CastToUserArrContent() (UserArrContent, bool) }
type OpenAIChatParam ¶
type OpenAIChatParam struct { Model string `json:"model"` Message []Message `json:"messages"` Temperature float64 `json:"temperature,omitempty"` // An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. // So 0.1 means only the tokens comprising the top 10% probability mass are considered. // We generally recommend altering this or temperature but not both. TopP float64 `json:"top_p,omitempty"` N int `json:"n,omitempty"` Stream bool `json:"stream"` Stop []string `json:"stop,omitempty"` MaxTokens int64 `json:"max_tokens,omitempty"` FrequencyPenalty int `json:"frequency_penalty"` PresencePenalty float64 `json:"presence_penalty"` Seed uint64 `json:"seed,omitempty"` User string `json:"user,omitempty"` }
type OpenAIFileCreateParam ¶ added in v1.0.1
type OpenAIListFilesParam ¶ added in v1.0.3
func (OpenAIListFilesParam) ToQuery ¶ added in v1.0.3
func (o OpenAIListFilesParam) ToQuery() string
type PromptAnnotation ¶
type PromptAnnotation struct { PromptIndex int `json:"prompt_index,omitempty"` ContentFilterResults ContentFilterResults `json:"content_filter_results,omitempty"` }
type PromptFilterResult ¶
type PromptFilterResult struct { Index int `json:"index"` ContentFilterResults ContentFilterResults `json:"content_filter_results,omitempty"` }
type RespAIChat ¶
type RespAIChat struct { ID string `json:"id"` Object string `json:"object"` Created int64 `json:"created"` Model string `json:"model"` Choices []ChatChoice `json:"choices"` SystemFingerprint string `json:"system_fingerprint"` PromptAnnotations []PromptAnnotation `json:"prompt_annotations,omitempty"` PromptFilterResults []PromptFilterResult `json:"prompt_filter_results,omitempty"` Usage *ChatUsage `json:"usage,omitempty"` Error *AIError `json:"error,omitempty"` }
type RespAIChatStream ¶
type RespAIChatStream struct { ID string `json:"id"` Object string `json:"object"` Created int64 `json:"created"` Model string `json:"model"` Choices []StreamChatChoice `json:"choices"` SystemFingerprint string `json:"system_fingerprint"` PromptAnnotations []PromptAnnotation `json:"prompt_annotations,omitempty"` PromptFilterResults []PromptFilterResult `json:"prompt_filter_results,omitempty"` Usage *ChatUsage `json:"usage,omitempty"` Error *AIError `json:"error,omitempty"` }
type RespOpenAI ¶
type RespOpenAI struct { IsStream bool EmptyMsgLineLimit int // contains filtered or unexported fields }
func (*RespOpenAI) Close ¶
func (r *RespOpenAI) Close() error
func (*RespOpenAI) Get ¶
func (r *RespOpenAI) Get() (*RespAIChat, error)
func (*RespOpenAI) HttpStatus ¶ added in v1.0.3
func (r *RespOpenAI) HttpStatus() int
func (*RespOpenAI) Recv ¶
func (r *RespOpenAI) Recv() (*RespAIChatStream, error)
type StreamChatChoice ¶
type StreamChatChoice struct { Index int `json:"index"` FinishReason FinishReason `json:"finish_reason"` Delta ChatCompletionStreamChoiceDelta `json:"delta"` // A chat completion delta generated by streamed model responses. }
https://platform.openai.com/docs/api-reference/chat/streaming
type TextContent ¶
type TextContent string
implement MsgContent
func (TextContent) CastToTextContent ¶
func (c TextContent) CastToTextContent() (TextContent, bool)
func (TextContent) CastToUserArrContent ¶
func (c TextContent) CastToUserArrContent() (UserArrContent, bool)
func (TextContent) ContentType ¶
func (c TextContent) ContentType() string
func (TextContent) MatchRole ¶
func (c TextContent) MatchRole(role Role) bool
func (TextContent) Text ¶
func (c TextContent) Text() []string
type ToolFunc ¶
type ToolFunc struct { ID string `json:"id"` Type string `json:"type"` Function struct { Name string `json:"name"` // The name of the function to call. Arguments string `json:"arguments"` // The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. } `json:"function"` }
type UserArrContent ¶
type UserArrContent []UserArrContentItem
implement MsgContent
func (UserArrContent) CastToTextContent ¶
func (c UserArrContent) CastToTextContent() (TextContent, bool)
func (UserArrContent) CastToUserArrContent ¶
func (c UserArrContent) CastToUserArrContent() (UserArrContent, bool)
func (UserArrContent) ContentType ¶
func (c UserArrContent) ContentType() string
func (UserArrContent) MatchRole ¶
func (c UserArrContent) MatchRole(role Role) bool
func (UserArrContent) Text ¶
func (c UserArrContent) Text() []string
type UserArrContentItem ¶
type UserArrContentItem interface { GetType() string Keyword() string GetText() string CastToUserArrTextContent() (UserTextContent, bool) CastToUserArrImgContent() (UserImgContent, bool) }
type UserImgContent ¶
type UserImgContent struct { Type string `json:"type,omitempty"` ImageURL ImgURL `json:"image_url"` }
implement UserArrContentItem
func (UserImgContent) CastToUserArrImgContent ¶
func (i UserImgContent) CastToUserArrImgContent() (UserImgContent, bool)
func (UserImgContent) CastToUserArrTextContent ¶
func (i UserImgContent) CastToUserArrTextContent() (UserTextContent, bool)
func (UserImgContent) GetText ¶
func (i UserImgContent) GetText() string
func (UserImgContent) GetType ¶
func (i UserImgContent) GetType() string
func (UserImgContent) Keyword ¶
func (i UserImgContent) Keyword() string
type UserTextContent ¶
implement UserArrContentItem
func (UserTextContent) CastToUserArrImgContent ¶
func (i UserTextContent) CastToUserArrImgContent() (UserImgContent, bool)
func (UserTextContent) CastToUserArrTextContent ¶
func (i UserTextContent) CastToUserArrTextContent() (UserTextContent, bool)
func (UserTextContent) GetText ¶
func (i UserTextContent) GetText() string
func (UserTextContent) GetType ¶
func (i UserTextContent) GetType() string
func (UserTextContent) Keyword ¶
func (i UserTextContent) Keyword() string
Click to show internal directories.
Click to hide internal directories.