Documentation
¶
Index ¶
Constants ¶
const ( ChatMessageRoleUser = "user" ChatMessageRoleSystem = "system" ChatMessageRoleAssistant = "assistant" )
const ( GooglePalm2CodeChatBison = "google/palm-2-codechat-bison" GooglePalm2ChatBison = "google/palm-2-chat-bison" OpenaiGpt35Turbo = "openai/gpt-3.5-turbo" OpenaiGpt35Turbo16k = "openai/gpt-3.5-turbo-16k" OpenaiGpt4 = "openai/gpt-4" OpenaiGpt432K = "openai/gpt-4-32k" OpenaiGpt4oMini = "openai/gpt-4o-mini" AnthropicClaude2 = "anthropic/claude-2" AnthropicClaudeInstantV1 = "anthropic/claude-instant-v1" MetaLlamaLlama213bChat = "meta-llama/llama-2-13b-chat" MetaLlamaLlama270bChat = "meta-llama/llama-2-70b-chat" Palm2CodeChatBison = "palm-2-codechat-bison" Palm2ChatBison = "palm-2-chat-bison" Gpt35Turbo = "gpt-3.5-turbo" Gpt35Turbo16k = "gpt-3.5-turbo-16k" Gpt4 = "gpt-4" G432K = "gpt-4-32k" Claude2 = "claude-2" ClaudeInstantV1 = "claude-instant-v1" Llama213bChat = "llama-2-13b-chat" Llama270bChat = "llama-2-70b-chat" )
Variables ¶
var ( ErrChatCompletionStreamNotSupported = errors.New("streaming is not supported with this method, please use CreateChatCompletionStream") //nolint:lll ErrCompletionUnsupportedModel = errors.New("this model is not supported with this method") //nolint:lll )
var (
ErrTooManyEmptyStreamMessages = errors.New("stream has sent too many empty messages")
)
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct { Code any `json:"code,omitempty"` Message string `json:"message"` Details any `json:"details"` HTTPStatusCode int `json:"-"` }
APIError provides error information returned by the OpenAI API.
func (*APIError) UnmarshalJSON ¶
type ChatCompletionChoice ¶
type ChatCompletionMessage ¶
type ChatCompletionRequest ¶
type ChatCompletionRequest struct { Model string `json:"model"` Messages []ChatCompletionMessage `json:"messages"` MaxTokens int `json:"max_tokens,omitempty"` Stream bool `json:"stream,omitempty"` Temperature *float32 `json:"temperature,omitempty"` TopP *float32 `json:"top_p,omitempty"` TopK *uint `json:"top_k,omitempty"` }
ChatCompletionRequest represents a request structure for chat completion API.
type ChatCompletionResponse ¶
type ChatCompletionResponse struct { ID string `json:"id,omitempty"` Object string `json:"object,omitempty"` Created int64 `json:"created,omitempty"` Model string `json:"model"` Choices []ChatCompletionChoice `json:"choices"` }
ChatCompletionResponse represents a response structure for chat completion API.
type ChatCompletionStream ¶
type ChatCompletionStream struct {
// contains filtered or unexported fields
}
func (*ChatCompletionStream) Recv ¶
func (stream *ChatCompletionStream) Recv() (response *ChatCompletionResponse, err error)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClientWithConfig ¶
func NewClientWithConfig(config ClientConfig) *Client
func (*Client) CreateChatCompletion ¶
func (c *Client) CreateChatCompletion( ctx context.Context, request *ChatCompletionRequest, ) (response *ChatCompletionResponse, err error)
CreateChatCompletion — API call to Create a completion for the chat message.
func (*Client) CreateChatCompletionStream ¶
func (c *Client) CreateChatCompletionStream( ctx context.Context, request *ChatCompletionRequest, ) (stream *ChatCompletionStream, err error)
CreateChatCompletionStream — API call to create a chat completion w/ streaming support. It sets whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.
type ClientConfig ¶
type ClientConfig struct { XTitle string HttpReferer string BaseURL string HTTPClient *http.Client EmptyMessagesLimit uint // contains filtered or unexported fields }
ClientConfig is a configuration of a client. XTitle、HttpRefer your own site url
func DefaultConfig ¶
func DefaultConfig(auth, xTitle, httpReferer string) (ClientConfig, error)
func (ClientConfig) WithHttpClientConfig ¶
func (c ClientConfig) WithHttpClientConfig(client *http.Client) ClientConfig
type ErrorResponse ¶
type ErrorResponse struct {
Error *APIError `json:"error,omitempty"`
}
type RequestError ¶
RequestError provides informations about generic request errors.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
func (*RequestError) Unwrap ¶
func (e *RequestError) Unwrap() error