Documentation
¶
Index ¶
- Constants
- func ChatTokens(model string, messages []openai.ChatCompletionMessage) (int, error)
- func PromptTokens(model string, prompt string) (int, error)
- type Client
- type Option
- func ChunkTimeout(timeout time.Duration) Option
- func MaxTokens(maxTokens int) Option
- func Model(model string) Option
- func ResponseFormat[Format string | openai.ChatCompletionResponseFormatType](format Format) Option
- func Stream(stream io.Writer) Option
- func Temperature(temperature float32) Option
- func Timeout(timeout time.Duration) Option
- func TopP(topP float32) Option
- func Verbose(verbose bool) Option
Constants ¶
const ( // DefaultModel is the default language model used for generating text when no // specific model is set during the client creation. DefaultModel = openai.GPT3Dot5Turbo // DefaultTemperature is the default value for the temperature parameter in the // AI model. It affects the randomness of the model's output. DefaultTemperature = 0.3 // DefaultTopP is the default value for the "Top P" parameter used in OpenAI's // language models. DefaultTopP = 0.3 // DefaultTimeout specifies the default duration to wait before timing out // requests to the OpenAI API. This value can be changed by using the Timeout // option when creating a new client. DefaultTimeout = 3 * time.Minute // DefaultChunkTimeout specifies the default duration for waiting on a chunk of // data during streaming operations before timing out. This value can be // adjusted to control how long the system will wait for a chunk before // considering the operation timed out. DefaultChunkTimeout = 5 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func ChatTokens ¶
func ChatTokens(model string, messages []openai.ChatCompletionMessage) (int, error)
ChatTokens computes the total number of tokens in a list of ChatCompletionMessages for a given model. It returns an integer representing the total token count and an error if any issues are encountered during tokenization or if the model is unsupported.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a configurable interface to the OpenAI API. It allows for the generation of text completions using various models, with adjustable parameters for token count, temperature, and topP. A specified timeout can be set for API requests.
func New ¶
New creates a new Client instance with the specified API token and optional configuration options. The Client allows for the generation of text completions using various models, with adjustable parameters for token count, temperature, and topP. The default values for these parameters are used if not explicitly set. The Client also supports setting a timeout duration for API requests.
type Option ¶
type Option func(*Client)
Option is a function type used to configure a Client. It allows for setting various parameters such as the model, maximum tokens, temperature, topP, and timeout. These options are applied to a Client instance during its creation with the New function.
func ChunkTimeout ¶ added in v0.9.2
ChunkTimeout sets the maximum duration a Client should wait for a chunk of data during streaming operations before timing out. This is configured as an Option that modifies the chunkTimeout field of a Client instance.
func MaxTokens ¶
MaxTokens configures the maximum number of tokens that the Client can use for generating text completions. It accepts an integer value and returns an Option to modify a Client instance.
func Model ¶
Model is a function that returns an Option which sets the model string field of a Client object when called. The model string represents the specific OpenAI model to be used for text generation tasks.
func ResponseFormat ¶ added in v0.6.3
func ResponseFormat[Format string | openai.ChatCompletionResponseFormatType](format Format) Option
ResponseFormat configures the format of the response received from the OpenAI API when generating text completions. It specifies how the response should be structured, which can be either plain text or a structured format that includes additional metadata. This option is passed to a Client instance during its creation and influences how the Client processes and returns generated content. The function accepts format types that can be either a string or an openai.ChatCompletionResponseFormatType.
func Stream ¶ added in v0.5.5
Stream is an option function that sets the writer to which the generated text completions will be streamed. This allows for real-time processing and display of the generated text.
func Temperature ¶
Temperature sets the temperature parameter for the Client. The temperature affects the randomness of the model's output during text generation tasks.
func Timeout ¶
Timeout is a function that sets the timeout duration for the Client. It returns an Option that, when provided to the New function, modifies the timeout duration of the created Client instance. The timeout duration determines how long the Client waits for a response before it cancels the request.