openai

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GPT3Dot5Turbo16k = "gpt-3.5-turbo-16k"
	GPT3Dot5Turbo    = "gpt-3.5-turbo"
	GPT4             = "gpt-4"
	GPT432K          = "gpt-4-32k"
)

Variables

Functions

func MarshalConfig

func MarshalConfig(config *Config) ([]byte, error)

MarshalConfig marshals a Config into a byte slice.

func ValidateApiKey

func ValidateApiKey(apiKey string) error

ValidateApiKey validates the API key for the OpenAI API. It does so by making a request to the models endpoint - if it fails, the API key is invalid.

func ValidateModel

func ValidateModel(model string) error

ValidateModel validates the model for the OpenAI API by checking if the model is in the list of allowed models.

func ValidateTemperature

func ValidateTemperature(temperature float32) error

ValidateTemperature validates the temperature for the OpenAI API.

Types

type AskConfigsCli

type AskConfigsCli interface {
	Execute() (*Config, error)
}

AskConfigsCli is a command line interface that asks the user for the configuration.

func MakeAskConfigsCli

func MakeAskConfigsCli() AskConfigsCli

func NewAskConfigsCli

func NewAskConfigsCli() AskConfigsCli

NewAskConfigsCli creates a new instance of AskConfigsCli.

type AskToChangeModelCli added in v1.4.2

type AskToChangeModelCli interface {
	Execute() (bool, error)
}

func MakeAskToChangeModelCli added in v1.4.2

func MakeAskToChangeModelCli() AskToChangeModelCli

func NewAskToChangeModelCli added in v1.4.2

func NewAskToChangeModelCli() AskToChangeModelCli

type Chat

type Chat interface {
	// Response returns the response from the AI.
	Response(config *Config, system *System, input string) (string, error)
}

Chat is the interface that wraps the Response method.

func NewChat

func NewChat(repo ConfigRepo) Chat

NewChat creates a new instance of Chat.

type ChatCommand

type ChatCommand interface {
	// Execute returns the response from the AI.
	Execute(config *Config, system *System, input string) (string, error)
}

ChatCommand is the interface that wraps the basic Execute method.

func MakeChatCommand added in v1.4.3

func MakeChatCommand() ChatCommand

func NewChatCommand

func NewChatCommand(chat Chat) ChatCommand

NewChatCommand creates a new instance of ChatCommand.

type Config

type Config struct {
	ApiKey      string  `json:"openai_api_key"`
	Temperature float32 `json:"openai_temperature"`
	Model       string  `json:"openai_model"`
}

Config is the configuration for the OpenAI API.

func NewConfig

func NewConfig(apiKey, model string, temperature float32) *Config

NewConfig creates a new Config.

func UnmarshalConfig

func UnmarshalConfig(data []byte) (*Config, error)

UnmarshalConfig unmarshals a Config from a byte slice.

type ConfigRepo added in v1.5.0

type ConfigRepo interface {
	// SaveConfig saves the config file.
	SaveConfig(config *Config) error

	// GetConfig returns the config file.
	GetConfig() (*Config, error)

	// DeleteConfig deletes the config file.
	DeleteConfig() error

	// UpdateConfig updates the config file.
	UpdateConfig(config *Config) error

	// Exists returns true if the config file exists.
	Exists() bool
}

ConfigRepo is the interface that wraps the basic operations with the config file.

func MakeConfigRepo

func MakeConfigRepo() ConfigRepo

func NewConfigRepo added in v1.5.0

func NewConfigRepo(storage *storage.Storage) ConfigRepo

NewConfigRepo creates a new instance of Repo.

type ResetConfigCommand

type ResetConfigCommand interface {
	// Execute will reset the configs.
	Execute() error
}

ResetConfigCommand is the interface that wraps the basic Execute method.

func MakeResetConfigCommand

func MakeResetConfigCommand() ResetConfigCommand

func NewResetConfigCommand

func NewResetConfigCommand(repo ConfigRepo) ResetConfigCommand

NewResetConfigCommand creates a new instance of ResetConfigCommand.

type System

type System struct {
	Message string
	Name    string
}

System is the system configuration for the OpenAI API - the initial message and name.

func NewSystem

func NewSystem(message, name string) *System

NewSystem creates a new System.

type UpdateConfigCommand

type UpdateConfigCommand interface {
	// Execute will update the configs.
	Execute(config *Config) error
}

UpdateConfigCommand is the interface that wraps the basic Execute method.

func MakeUpdateConfigCommand

func MakeUpdateConfigCommand() UpdateConfigCommand

func NewUpdateConfigCommand

func NewUpdateConfigCommand(repo ConfigRepo) UpdateConfigCommand

NewUpdateConfigCommand creates a new instance of UpdateConfigCommand.

type VerifyConfigCommand

type VerifyConfigCommand interface {
	// Execute will verify if the configs were initialized and if not, it will initialize them.
	Execute(getConfigsFn func() (*Config, error)) (*Config, error)
}

VerifyConfigCommand is the interface that wraps the basic Execute method.

func MakeVerifyConfigCommand

func MakeVerifyConfigCommand() VerifyConfigCommand

func NewVerifyConfigCommand

func NewVerifyConfigCommand(repo ConfigRepo) VerifyConfigCommand

NewVerifyConfigCommand creates a new instance of VerifyConfigCommand.

Jump to

Keyboard shortcuts

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