openai

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultModel = openai.GPT3Dot5Turbo

DefaultModel is the default OpenAI model to use if one is not provided.

Functions

func GetModel added in v0.0.2

func GetModel(model string) string

GetModel returns the model ID corresponding to the given model name. If the model name is not recognized, it returns the default model ID.

Types

type Client

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

Client is a struct that represents an OpenAI client.

func New

func New(opts ...Option) (*Client, error)

New is a function that takes a variadic slice of Option types and returns a pointer to a Client and an error.

func (*Client) Completion

func (c *Client) Completion(
	ctx context.Context,
	content string,
) (*Response, error)

Completion is a method on the Client struct that takes a context.Context and a string argument and returns a string and an error.

func (*Client) CreateChatCompletion

func (c *Client) CreateChatCompletion(
	ctx context.Context,
	content string,
) (resp openai.ChatCompletionResponse, err error)

CreateChatCompletion is an API call to create a completion for a chat message.

func (*Client) CreateCompletion

func (c *Client) CreateCompletion(
	ctx context.Context,
	content string,
) (resp openai.CompletionResponse, err error)

CreateCompletion is an API call to create a completion. This is the main endpoint of the API. It returns new text, as well as, if requested, the probabilities over each alternative token at each position.

If using a fine-tuned model, simply provide the model's ID in the CompletionRequest object, and the server will use the model's parameters to generate the completion.

type Option added in v0.0.5

type Option interface {
	// contains filtered or unexported methods
}

Option is an interface that specifies instrumentation configuration options.

func WithBaseURL added in v0.1.2

func WithBaseURL(val string) Option

WithBaseURL returns a new Option that sets the base URL for the client configuration. It takes a string value representing the base URL to use for requests. It returns an optionFunc that sets the baseURL field of the configuration to the provided

func WithModel added in v0.0.5

func WithModel(val string) Option

WithModel is a function that returns an Option, which sets the model field of the config struct.

func WithOrgID added in v0.0.5

func WithOrgID(val string) Option

WithOrgID is a function that returns an Option, which sets the orgID field of the config struct.

func WithProxyURL added in v0.0.5

func WithProxyURL(val string) Option

WithProxyURL is a function that returns an Option, which sets the proxyURL field of the config struct.

func WithSocksURL added in v0.0.9

func WithSocksURL(val string) Option

WithSocksURL is a function that returns an Option, which sets the socksURL field of the config struct.

func WithTimeout added in v0.1.2

func WithTimeout(val time.Duration) Option

WithTimeout returns a new Option that sets the timeout for the client configuration. It takes a time.Duration value representing the timeout duration. It returns an optionFunc that sets the timeout field of the configuration to the provided value.

func WithToken added in v0.0.5

func WithToken(val string) Option

WithToken is a function that returns an Option, which sets the token field of the config struct.

type Response added in v0.0.9

type Response struct {
	Content string
	Usage   openai.Usage
}

Jump to

Keyboard shortcuts

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