api

package
v2.14.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultModel is the default model used for chat completions.
	DefaultModel = strings.Clone(openai.GPT3Dot5Turbo)
	// ErrMissingAPIKey is returned, if the OPENAI_API_KEY environment variable is not set.
	ErrMissingAPIKey = fmt.Errorf("%s env variable is not set", envKeyOpenAIApi)
)

Functions

This section is empty.

Types

type OpenAIClient

type OpenAIClient struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

OpenAIClient is a client for the OpenAI API.

func CreateClient

func CreateClient(config *viper.Viper, out io.Writer) (*OpenAIClient, error)

CreateClient creates a new OpenAI client with the given config and output writer.

func (*OpenAIClient) CreateCompletion

func (c *OpenAIClient) CreateCompletion(ctx context.Context, chatID string, prompt []string, modifier string, input []string) (string, error)

CreateCompletion creates a completion for the given prompt and modifier. If chatID is provided, the chat is reused and the completion is added to the chat with this ID. If no chatID is provided, only the modifier and prompt are used to create the completion. The completion is printed to the out writer of the client and returned as a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL