bootstrap

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetKey

func GetKey(profile string) (string, error)

func GetOrReadKey

func GetOrReadKey(profile string) (string, error)

func GetVersion

func GetVersion(ctx context.Context) string

func IsDebug

func IsDebug(ctx context.Context) bool

IsDebug gets a value indicating whether debugging is enabled for this session.

func LoadConfigFile

func LoadConfigFile(path string, config *ConfigFile, isGlobal bool) error

LoadConfigFile reads a YAML configuration file and updates combined config.

func NewContext

func NewContext(config *Config) context.Context

func ReadKey

func ReadKey(profile string, force bool) (string, error)

func ReadKeyAndUpdate

func ReadKeyAndUpdate(profile string, force bool) (string, error)

Types

type App

type App struct {
	Config *Config

	Clients []*ClientRef
}

Aggregates global context for the application.

func GetApp

func GetApp(ctx context.Context) *App

func NewApp

func NewApp(config *Config) *App

func (*App) PrimaryClient

func (a *App) PrimaryClient() *ClientRef

type ClientRef

type ClientRef struct {
	Config *ConfigService
	Client *openai.Client
}

func NewClientRef

func NewClientRef(config *ConfigService) *ClientRef

func (*ClientRef) Request

func (c *ClientRef) Request(ctx context.Context, cb RequestCallback) error

type Config

type Config struct {
	Dir     string
	Debug   bool
	Version bool

	Services []*ConfigService
}

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig reads configuration from flags, environment variables, and config files.

type ConfigFile

type ConfigFile struct {
	Default  *string                       `yaml:"default"`
	Profiles map[string]*ConfigFileProfile `yaml:"profiles"`
}

type ConfigFileProfile

type ConfigFileProfile struct {
	Context ConfigFileProfileContext `yaml:"-"`

	Preset *string `yaml:"preset"`

	BaseURL string `yaml:"baseurl"`
	Key     string `yaml:"key"`
	Model   string `yaml:"model"`

	Prompt *ConfigFilePrompt `yaml:"prompt"`

	Retries        int `yaml:"retries"`
	Concurrency    int `yaml:"concurrency"`
	CompactionToks int `yaml:"compactionToks"`
}

type ConfigFileProfileContext

type ConfigFileProfileContext struct {
	IsGlobal bool   // Indicates whether profile came from a global config
	Dir      string // Directory where the config is located
}

type ConfigFilePrompt

type ConfigFilePrompt struct {
	Path    *string `json:"path"`
	Content *string `json:"content"`
}

type ConfigService

type ConfigService struct {
	Profile string

	BaseURL string
	Key     ConfigValue[string]
	Model   string

	Prompt string

	Retries        int
	Concurrency    int
	CompactionToks int
}

type ConfigSource

type ConfigSource int
const (
	CfNone ConfigSource = iota
	CfConfigFile
	CfKeyChain
	CfEnvironment
)

type ConfigValue

type ConfigValue[V any] struct {
	Value  V
	Source ConfigSource
}

type ContextKey

type ContextKey string
const (
	CtxApp     ContextKey = "app"
	CtxVersion ContextKey = "version"
)

type RequestCallback

type RequestCallback func(client *openai.Client) error

Jump to

Keyboard shortcuts

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