openai

package
v0.0.10-beta1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 13 Imported by: 5

Documentation

Overview

Package openai provides a wrapper around the OpenAI API.

Index

Constants

View Source
const (
	DefaultOpenAIMaxTokens   = 256
	DefaultOpenAITemperature = 0.7
	DefaultOpenAINumResults  = 1
	DefaultOpenAITopP        = 1.0
	DefaultMaxIterations     = 3
)

Variables

View Source
var (
	ErrOpenAICompletion = fmt.Errorf("openai completion error")
	ErrOpenAIChat       = fmt.Errorf("openai chat error")
)

Functions

This section is empty.

Types

type Function added in v0.0.8

type Function struct {
	Name        string
	Description string
	Parameters  map[string]interface{}
	Fn          interface{}
}

type FunctionParameterOption added in v0.0.8

type FunctionParameterOption func(map[string]interface{}) error

type Model

type Model string
const (
	GPT432K0613             Model = openai.GPT432K0613
	GPT432K0314             Model = openai.GPT432K0314
	GPT432K                 Model = openai.GPT432K
	GPT40613                Model = openai.GPT40613
	GPT40314                Model = openai.GPT40314
	GPT4                    Model = openai.GPT4
	GPT3Dot5Turbo0613       Model = openai.GPT3Dot5Turbo0613
	GPT3Dot5Turbo0301       Model = openai.GPT3Dot5Turbo0301
	GPT3Dot5Turbo16K        Model = openai.GPT3Dot5Turbo16K
	GPT3Dot5Turbo16K0613    Model = openai.GPT3Dot5Turbo16K0613
	GPT3Dot5Turbo           Model = openai.GPT3Dot5Turbo
	GPT3TextDavinci003      Model = openai.GPT3TextDavinci003
	GPT3TextDavinci002      Model = openai.GPT3TextDavinci002
	GPT3TextCurie001        Model = openai.GPT3TextCurie001
	GPT3TextBabbage001      Model = openai.GPT3TextBabbage001
	GPT3TextAda001          Model = openai.GPT3TextAda001
	GPT3TextDavinci001      Model = openai.GPT3TextDavinci001
	GPT3DavinciInstructBeta Model = openai.GPT3DavinciInstructBeta
	GPT3Davinci             Model = openai.GPT3Davinci
	GPT3CurieInstructBeta   Model = openai.GPT3CurieInstructBeta
	GPT3Curie               Model = openai.GPT3Curie
	GPT3Ada                 Model = openai.GPT3Ada
	GPT3Babbage             Model = openai.GPT3Babbage
)

type OpenAI

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

func New

func New(model Model, temperature float32, maxTokens int, verbose bool) *OpenAI

func NewChat added in v0.0.5

func NewChat() *OpenAI

func NewCompletion added in v0.0.5

func NewCompletion() *OpenAI

func (*OpenAI) BatchCompletion added in v0.0.10

func (o *OpenAI) BatchCompletion(ctx context.Context, prompts []string) ([]string, error)

BatchCompletion returns multiple completions for the given prompts.

func (*OpenAI) BatchCompletionStream added in v0.0.10

func (o *OpenAI) BatchCompletionStream(ctx context.Context, callbackFn []OpenAIStreamCallback, prompts []string) error

BatchCompletionStream returns multiple completion streams for the given prompts.

func (*OpenAI) BindFunction added in v0.0.9

func (o *OpenAI) BindFunction(
	fn interface{},
	name string,
	description string,
	functionParamenterOptions ...FunctionParameterOption,
) error

func (*OpenAI) CalledFunctionName added in v0.0.9

func (o *OpenAI) CalledFunctionName() *string

CalledFunctionName returns the name of the function that was called.

func (*OpenAI) Chat

func (o *OpenAI) Chat(ctx context.Context, prompt *chat.Chat) (string, error)

Chat returns a single chat completion for the given prompt.

func (*OpenAI) ChatStream added in v0.0.9

func (o *OpenAI) ChatStream(ctx context.Context, callbackFn OpenAIStreamCallback, prompt *chat.Chat) error

ChatStream returns a single chat stream for the given prompt.

func (*OpenAI) Completion

func (o *OpenAI) Completion(ctx context.Context, prompt string) (string, error)

Completion returns a single completion for the given prompt.

func (*OpenAI) CompletionStream added in v0.0.9

func (o *OpenAI) CompletionStream(ctx context.Context, callbackFn OpenAIStreamCallback, prompt string) error

CompletionStream returns a single completion stream for the given prompt.

func (*OpenAI) FinishReason added in v0.0.9

func (o *OpenAI) FinishReason() string

FinishReason returns the LLM finish reason.

func (*OpenAI) SetStop added in v0.0.9

func (o *OpenAI) SetStop(stop []string)

SetStop sets the stop sequences for the completion.

func (*OpenAI) WithCallback added in v0.0.9

func (o *OpenAI) WithCallback(callback OpenAIUsageCallback) *OpenAI

WithUsageCallback sets the usage callback to use for the OpenAI instance.

func (*OpenAI) WithClient added in v0.0.9

func (o *OpenAI) WithClient(client *openai.Client) *OpenAI

WithClient sets the client to use for the OpenAI instance.

func (*OpenAI) WithMaxTokens added in v0.0.9

func (o *OpenAI) WithMaxTokens(maxTokens int) *OpenAI

WithMaxTokens sets the max tokens to use for the OpenAI instance.

func (*OpenAI) WithModel added in v0.0.9

func (o *OpenAI) WithModel(model Model) *OpenAI

WithModel sets the model to use for the OpenAI instance.

func (*OpenAI) WithStop added in v0.0.9

func (o *OpenAI) WithStop(stop []string) *OpenAI

WithStop sets the stop sequences to use for the OpenAI instance.

func (*OpenAI) WithTemperature added in v0.0.9

func (o *OpenAI) WithTemperature(temperature float32) *OpenAI

WithTemperature sets the temperature to use for the OpenAI instance.

func (*OpenAI) WithVerbose added in v0.0.9

func (o *OpenAI) WithVerbose(verbose bool) *OpenAI

WithVerbose sets the verbose flag to use for the OpenAI instance.

type OpenAIStreamCallback added in v0.0.7

type OpenAIStreamCallback func(string)

type OpenAIUsageCallback added in v0.0.7

type OpenAIUsageCallback func(types.Meta)

Jump to

Keyboard shortcuts

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