Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var BaseURL = "https://api.openai.com"
BaseURL is the base URL for the GPT API.
var Paths = paths{
Completion: "/v1/chat/completions",
}
Paths contains the paths for the different GPT API endpoints. It is used to construct the full URL for each endpoint.
Functions ¶
This section is empty.
Types ¶
type Choice ¶
type Choice struct { Index int `json:"index"` // Index is the position of the choice in the list. Message Message `json:"message"` // Message contains the generated output. FinishReason string `json:"finish_reason"` // FinishReason indicates why the generation was stopped. }
Choice represents a single generated output.
type Client ¶
type Client interface { // Complete sends a request to the GPT API to generate a completion based on the provided input. // It returns a response containing the model's output or an error if something went wrong. Complete(CompletionRequest) (*CompletionResponse, error) }
Client defines the interface for interacting with the GPT API. It provides a method to generate completions based on the provided input.
type Completion ¶
type Completion struct { PromptTokens int `json:"prompt_tokens"` // PromptTokens is the number of tokens used in the input. CompletionTokens int `json:"completion_tokens"` // CompletionTokens is the number of tokens in the generated output. TotalTokens int `json:"total_tokens"` // TotalTokens is the total number of tokens used. }
Completion provides details about token usage for a request.
type CompletionRequest ¶
type CompletionRequest struct { Model Model `json:"model"` // Model specifies the GPT model to be used for generating the completion. Messages []Message `json:"messages"` // Messages contains the conversation history. Temperature float32 `json:"temperature"` // Temperature controls the randomness of the model's output. MaxTokens int `json:"max_tokens"` // MaxTokens limits the length of the generated output. TopP float32 `json:"top_p"` // TopP controls the diversity of the model's output. FrequencyPenalty float32 `json:"frequency_penalty"` // FrequencyPenalty penalizes more frequent tokens. PresencePenalty float32 `json:"presence_penalty"` // PresencePenalty penalizes new tokens. }
CompletionRequest represents the input data required to generate completions using the GPT API.
type CompletionResponse ¶
type CompletionResponse struct { Id string `json:"id"` // Id is a unique identifier for the response. Object string `json:"object"` // Object indicates the type of the response. Created int `json:"created"` // Created is a timestamp of when the response was generated. Model Model `json:"model"` // Model specifies which GPT model was used. Choices []Choice `json:"choices"` // Choices contains the generated outputs. Usage Completion `json:"usage"` // Usage provides details about token usage for the request. }
CompletionResponse represents the model's output for a given CompletionRequest.
type Message ¶
type Message struct { Role Role `json:"role"` // Role indicates who sent the message (e.g., user, bot). Content string `json:"content"` // Content contains the text of the message. }
Message represents a single message in a conversation.
type Model ¶
type Model string
Model represents the different GPT models available for generating completions.
const ( ModelGpt3Turbo Model = "gpt-3.5-turbo" // ModelGpt3Turbo represents the GPT-3.5 Turbo model. ModelGpt3Turbo16K0613 Model = "gpt-3.5-turbo-16k-0613" // ModelGpt3Turbo16K0613 represents the GPT-3.5 Turbo 16K 0613 model. ModelGpt3Turbo16K Model = "gpt-3.5-turbo-16k" // ModelGpt3Turbo16K represents the GPT-3.5 Turbo 16K model. ModelGpt3Turbo0613 Model = "gpt-3.5-turbo-0613" // ModelGpt3Turbo0613 represents the GPT-3.5 Turbo 0613 model. ModelGpt3Turbo0301 Model = "gpt-3.5-turbo-0301" // ModelGpt3Turbo0301 represents the GPT-3.5 Turbo 0301 model. ModelGpt4 Model = "gpt-4" // ModelGpt4 represents the GPT-4 model. ModelGpt40314 Model = "gpt-4-0314" // ModelGpt40314 represents the GPT-4 0314 model. ModelGpt40613 Model = "gpt-4-0613" // ModelGpt40613 represents the GPT-4 0613 model. )
type Object ¶
type Object string
Object represents the different types of responses that can be received from the GPT API.
const (
ObjectChatCompletion Object = "chat.completion" // ObjectChatCompletion indicates a completion response.
)