Documentation ¶
Index ¶
Constants ¶
View Source
const ( RoleUser = "user" RoleSystem = "system" RoleFunction = "function" RoleAssistant = "assistant" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AzureOpenAI ¶ added in v1.0.12
type AzureOpenAI struct { Domain string Apikey string Apiver string Deployment string Transport http.RoundTripper Timeout time.Duration Logger log.Logger MaxRetries int RetryAfter time.Duration AbortOnRetry func() bool AbortInterval time.Duration }
func (*AzureOpenAI) CreateChatCompletion ¶ added in v1.0.12
func (aoai *AzureOpenAI) CreateChatCompletion(req *ChatCompeletionRequest) (*ChatCompeletionResponse, error)
func (*AzureOpenAI) CreateTextEmbeddings ¶ added in v1.0.12
func (aoai *AzureOpenAI) CreateTextEmbeddings(req *TextEmbeddingsRequest) (*TextEmbeddingsResponse, error)
https://platform.openai.com/docs/api-reference/embeddings/create
type ChatChoice ¶
type ChatChoice struct { Index int `json:"index"` Message ChatMessage `json:"message"` FinishReason string `json:"finish_reason"` }
type ChatCompeletionRequest ¶
type ChatCompeletionRequest struct { // ID of the model to use. See the model endpoint compatibility table for details on which models work with the Chat API. Model string `json:"model,omitempty"` // A list of messages comprising the conversation so far. Messages []*ChatMessage `json:"messages,omitempty"` // A list of functions the model may generate JSON inputs for. Functions []*ChatFunction `json:"functions,omitempty"` // Controls how the model responds to function calls. "none" means the model does not call a function, and responds to the end-user. "auto" means the model can pick between an end-user or calling a function. Specifying a particular function via {"name":\ "my_function"} forces the model to call that function. "none" is the default when no functions are present. "auto" is the default if functions are present. FunctionCall string `json:"function_call,omitempty"` // What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. // We generally recommend altering this or top_p but not both. // Defaults to 1 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. // Defaults to 1 TopP float64 `json:"top_p,omitempty"` // How many chat completion choices to generate for each input message. // Defaults to 1 N int `json:"n,omitempty"` // If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. // Defaults to false Stream bool `json:"stream,omitempty"` // Up to 4 sequences where the API will stop generating further tokens. Stop any `json:"stop,omitempty"` // The maximum number of tokens to generate in the chat completion. // The total length of input tokens and generated tokens is limited by the model's context length. MaxTokens int `json:"max_tokens,omitempty"` // Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. // Defaults to 0 PresencePenalty float64 `json:"presence_penalty,omitempty"` // Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. // Defaults to 0 FrequencyPenalty float64 `json:"frequency_penalty,omitempty"` // Modify the likelihood of specified tokens appearing in the completion. // Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. // Defaults to null LogitBias any `json:"logit_bias,omitempty"` // A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. User string `json:"user,omitempty"` }
func (*ChatCompeletionRequest) AddMessage ¶ added in v1.0.12
func (cc *ChatCompeletionRequest) AddMessage(cm *ChatMessage)
func (*ChatCompeletionRequest) MessageRuneCount ¶ added in v1.0.12
func (cc *ChatCompeletionRequest) MessageRuneCount() int
func (*ChatCompeletionRequest) String ¶
func (cc *ChatCompeletionRequest) String() string
type ChatCompeletionResponse ¶
type ChatCompeletionResponse struct { ID string `json:"id,omitempty"` Object string `json:"object,omitempty"` Created int64 `json:"created,omitempty"` Model string `json:"model,omitempty"` SystemFingerprint string `json:"system_fingerprint,omitempty"` Choices []*ChatChoice `json:"choices,omitempty"` Usage ChatUsage `json:"usage,omitempty"` }
func (*ChatCompeletionResponse) Answer ¶ added in v1.0.12
func (cc *ChatCompeletionResponse) Answer() string
Answer return first choice content
func (*ChatCompeletionResponse) ChoiceRuneCount ¶ added in v1.0.12
func (cc *ChatCompeletionResponse) ChoiceRuneCount() int
func (*ChatCompeletionResponse) String ¶ added in v1.0.12
func (cc *ChatCompeletionResponse) String() string
type ChatFunction ¶
type ChatFunction struct { // The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. Name string `json:"name,omitempty"` // A description of what the function does, used by the model to choose when and how to call the function. Description string `json:"description,omitempty"` // The parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format. // To describe a function that accepts no parameters, provide the value {"type": "object", "properties": {}}. Parameters map[string]any `json:"parameters,omitempty"` }
type ChatMessage ¶
type ChatMessage struct { // The role of the messages author. One of system, user, assistant, or function. Role string `json:"role,omitempty"` // The contents of the message. content is required for all messages, and may be null for assistant messages with function calls. Content string `json:"content,omitempty"` // The name of the author of this message. name is required if role is function, and it should be the name of the function whose response is in the content. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters. Name string `json:"name,omitempty"` // The name and arguments of a function that should be called, as generated by the model. FunctionCall string `json:"function_call,omitempty"` }
type ChatUsage ¶
type EmbeddingData ¶ added in v1.0.12
type EmbeddingUsage ¶ added in v1.0.12
type ErrorDetail ¶
type ErrorDetail struct { Type string `json:"type,omitempty"` Code any `json:"code,omitempty"` Param any `json:"param,omitempty"` Message string `json:"message,omitempty"` }
func (*ErrorDetail) String ¶
func (ed *ErrorDetail) String() string
type ErrorResult ¶
type ErrorResult struct { StatusCode int `json:"-"` // http status code Status string `json:"-"` // http status Detail *ErrorDetail `json:"error,omitempty"` // contains filtered or unexported fields }
func (*ErrorResult) Error ¶
func (er *ErrorResult) Error() string
func (*ErrorResult) RetryAfter ¶ added in v1.0.11
func (er *ErrorResult) RetryAfter() time.Duration
type OpenAI ¶
type OpenAI struct { Domain string Apikey string Transport http.RoundTripper Timeout time.Duration Logger log.Logger MaxRetries int RetryAfter time.Duration AbortOnRetry func() bool AbortInterval time.Duration }
func (*OpenAI) CreateChatCompletion ¶
func (oai *OpenAI) CreateChatCompletion(req *ChatCompeletionRequest) (*ChatCompeletionResponse, error)
func (*OpenAI) CreateTextEmbeddings ¶ added in v1.0.12
func (oai *OpenAI) CreateTextEmbeddings(req *TextEmbeddingsRequest) (*TextEmbeddingsResponse, error)
https://platform.openai.com/docs/api-reference/embeddings/create
type TextEmbeddingsRequest ¶ added in v1.0.12
type TextEmbeddingsRequest struct { // Input Input text to embed (required) Input []string `json:"input,omitempty"` // ID of the model to use (required) Model string `json:"model,omitempty"` // A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. User string `json:"user,omitempty"` }
func (*TextEmbeddingsRequest) InputRuneCount ¶ added in v1.0.13
func (te *TextEmbeddingsRequest) InputRuneCount() int
func (*TextEmbeddingsRequest) String ¶ added in v1.0.12
func (te *TextEmbeddingsRequest) String() string
type TextEmbeddingsResponse ¶ added in v1.0.12
type TextEmbeddingsResponse struct { Data []*EmbeddingData `json:"data"` Model string `json:"model"` Object string `json:"object"` Usage ChatUsage `json:"usage"` }
func (*TextEmbeddingsResponse) Embedding ¶ added in v1.0.13
func (te *TextEmbeddingsResponse) Embedding() []float64
func (*TextEmbeddingsResponse) String ¶ added in v1.0.12
func (te *TextEmbeddingsResponse) String() string
Click to show internal directories.
Click to hide internal directories.