openai

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GPT_35_TURBO_0125     = ModelID("gpt-3.5-turbo-0125")
	GPT_35_TURBO_INSTRUCT = ModelID("gpt-3.5-turbo-instruct")
	GPT_4                 = ModelID("gpt-4")
	GPT_4_32K             = ModelID("gpt-4-32k")
	GPT_4o                = ModelID("gpt-4o")
	GPT_4o_MINI           = ModelID("gpt-4o-mini")
)
View Source
const Version = "openai/v0.0.4"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	http.Stack
	// contains filtered or unexported fields
}

OpenAI client

func New

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

Creates OpenAI Chat (completion) client.

By default OpenAI reads access token from `~/.netrc`, supply custom secret `WithSecret(secret string)` if needed.

The client is configurable using

WithSecret(secret string)
WithNetRC(host string)
WithModel(...)
WithHTTP(opts ...http.Config)

func (*Client) ConsumedTokens

func (c *Client) ConsumedTokens() int

Number of tokens consumed within the session

func (*Client) Prompt added in v0.0.4

func (c *Client) Prompt(ctx context.Context, prompt *chatter.Prompt, opts ...func(*chatter.Options)) (string, error)

Send prompt

type ModelID

type ModelID string

type Option

type Option func(*Client)

Config option for the client

func WithFormatter added in v0.0.4

func WithFormatter(formatter chatter.Formatter) Option

Config Formatter

func WithHTTP

func WithHTTP(opts ...http.Config) Option

Config the http stack

func WithHost

func WithHost(host string) Option

Config the host, api.openai.com is default

func WithModel

func WithModel(id ModelID) Option

Config the model

func WithNetRC

func WithNetRC(host string) Option

Config the secret from .netrc

func WithQuotaTokensInReply added in v0.0.3

func WithQuotaTokensInReply(quota int) Option

Config tokens quota in reply

func WithSecret

func WithSecret(secret string) Option

Config the secret explicitly

Jump to

Keyboard shortcuts

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