Documentation ¶
Index ¶
Constants ¶
const ( // DefaultModel is the default AI model used for generating text when no model // is explicitly provided. DefaultModel = openai.GPT3Dot5Turbo // DefaultMaxTokens is the default maximum number of tokens to be generated by // the Service instance when no specific value is provided. DefaultMaxTokens = 512 )
Variables ¶
This section is empty.
Functions ¶
func ChatTokens ¶ added in v0.0.4
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.
func MaxTokensForModel ¶ added in v0.0.4
MaxTokensForModel returns the maximum number of tokens allowed for the specified model. If the model is not recognized, it returns a default value.
Types ¶
type Option ¶
type Option func(*Service)
Option is a function type used to configure a Service instance. It takes a pointer to a Service and modifies its fields as needed. This allows for flexible and customizable configuration of the Service through the use of various Option functions.
func Client ¶ added in v0.0.4
func Client(c *openai.Client) Option
Client sets the OpenAI client for the service to use when making API requests. It is an option function for configuring a new Service instance.
func MaxTokens ¶
MaxTokens sets the maximum number of tokens to be generated by the Service instance. It is an option function for configuring a new Service instance.
func Model ¶
Model is an Option function that sets the model string for the Service struct. It returns an Option that modifies the model field of a given Service instance.
func WithLogger ¶
WithLogger sets the logger for the Service instance using the provided slog.Handler.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is a struct that represents an OpenAI service, providing functionality to generate documents using the OpenAI API. It contains configurable options such as client, model, maxTokens, codec, and logger. It also provides methods to generate documents based on provided context and request configurations.