openai

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultModel specifies the default language model used for generating
	// completions.
	DefaultModel = openai.GPT3Dot5Turbo

	// DefaultMaxTokens specifies the default maximum number of tokens for a
	// request.
	DefaultMaxTokens = 512
)

Variables

This section is empty.

Functions

func ChatTokens added in v0.0.4

func ChatTokens(model string, messages []openai.ChatCompletionMessage) (int, error)

ChatTokens calculates the total number of tokens used by a list of openai.ChatCompletionMessage for a given model.

func MaxTokensForModel added in v0.0.4

func MaxTokensForModel(model string) int

MaxTokensForModel retrieves the maximum number of tokens allowed for a specified model.

func PromptTokens added in v0.0.4

func PromptTokens(model string, prompt string) (int, error)

PromptTokens calculates the number of tokens in a given prompt based on the specified model and returns the token count along with any error encountered during encoding.

Types

type Option

type Option func(*Service)

Option modifies the configuration of a Service.

func Client added in v0.0.4

func Client(c *openai.Client) Option

Client sets the *openai.Client for the Service.

func MaxTokens

func MaxTokens(max int) Option

MaxTokens sets the maximum number of tokens that can be used in a request.

func Model

func Model(model string) Option

Model sets the model to be used by the Service.

func WithLogger

func WithLogger(h slog.Handler) Option

WithLogger configures the service to use a specified logger. Returns an Option.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides functionalities for generating text completions using OpenAI models, with options to customize the model, maximum tokens, and logging behavior.

func New

func New(apiKey string, opts ...Option) (*Service, error)

New initializes and returns a new *Service configured with the provided API key and options.

func (*Service) GenerateDoc

func (svc *Service) GenerateDoc(ctx generate.Context) (string, error)

GenerateDoc creates documentation text based on the provided context and returns it as a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳