config

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIKeysFile  = "api_keys.json"
	APIUsageFile = "api_usage.json"
)
View Source
const (
	DefaultServerURL         = "https://hub.opencsg.com"
	DefaultDisplayURL        = "https://opencsg.com"
	DefaultListenAddr        = ":11435"
	DefaultCloudProviderName = "csghub"
	EnvServerURL             = "CSGHUB_LITE_SERVER_URL"
	EnvAIGatewayURL          = "CSGHUB_LITE_AI_GATEWAY_URL"
	EnvCloudProviderName     = "CSGHUB_LITE_CLOUD_PROVIDER_NAME"
	AppDir                   = ".csghub-lite"
	ConfigFile               = "config.json"
	ModelsDir                = "models"
	DatasetsDir              = "datasets"
	TmpDir                   = "tmp"
)
View Source
const (
	LogsDir                = "logs"
	ServerLogFileName      = "csghub-lite.log"
	LlamaServerLogFileName = "llama-server.log"

	LogStderrEnv          = "CSGHUB_LITE_LOG_STDERR"
	DisableFileLoggingEnv = "CSGHUB_LITE_DISABLE_FILE_LOGGING"
)
View Source
const ProviderModelAllowlistFile = "provider_model_allowlist.json"
View Source
const ProvidersFile = "providers.json"

ProvidersFile is the filename for storing third-party providers

Variables

View Source
var ErrProviderModelSelectionDuplicate = errors.New("provider model id already exists")

Functions

func AddProviderModelAllowlist

func AddProviderModelAllowlist(providerID, modelID string) error

func AddProviderModelSelection

func AddProviderModelSelection(providerID string, selection ProviderModelSelection) error

func AppHome

func AppHome() (string, error)

func ApplyEnvironmentDefaults

func ApplyEnvironmentDefaults(cfg *Config)

func ConfigPath

func ConfigPath() (string, error)

func DatasetDirForStorage

func DatasetDirForStorage(storageDir string) string

func DefaultDatasetDir

func DefaultDatasetDir() (string, error)

func DefaultModelDir

func DefaultModelDir() (string, error)

func DefaultStorageDir

func DefaultStorageDir() (string, error)

func DeleteProviderModelAllowlist

func DeleteProviderModelAllowlist(providerID string) error

func FileLoggingEnabled

func FileLoggingEnabled() bool

func GenerateProviderID

func GenerateProviderID() string

GenerateProviderID generates a random ID for a new provider

func GetProviderModelAllowlist

func GetProviderModelAllowlist(providerID string) []string

func HasProviderModelSelections added in v0.9.7

func HasProviderModelSelections(providerID string) bool

func LlamaServerLogPath

func LlamaServerLogPath() (string, error)

func LogDir

func LogDir() (string, error)

func LogStderrEnabled

func LogStderrEnabled() bool

func ModelDirForStorage

func ModelDirForStorage(storageDir string) string

func NormalizeCloudProviderName

func NormalizeCloudProviderName(name string) string

func ProviderModelAllowlistPath

func ProviderModelAllowlistPath() (string, error)

func ProvidersPath

func ProvidersPath() (string, error)

ProvidersPath returns the path to the providers config file

func RemoveProviderModelAllowlist

func RemoveProviderModelAllowlist(providerID, modelID string) (bool, error)

func ReplaceProviderModelAllowlist

func ReplaceProviderModelAllowlist(providerID string, models []string) error

func ReplaceProviderModelSelections

func ReplaceProviderModelSelections(providerID string, models []ProviderModelSelection) error

func Reset

func Reset()

func ResetProviderModelAllowlist

func ResetProviderModelAllowlist()

func ResetProviders

func ResetProviders()

ResetProviders resets the providers state (for testing)

func Save

func Save(cfg *Config) error

func SaveProviders

func SaveProviders(provs []ThirdPartyProvider) error

SaveProviders saves the providers to the config file

func ServerLogPath

func ServerLogPath() (string, error)

func StorageDir

func StorageDir(modelDir, datasetDir string) string

func TempDirForStorage

func TempDirForStorage(storageDir string) string

Types

type APIKeyRecord

type APIKeyRecord struct {
	ID         string    `json:"id"`
	Name       string    `json:"name"`
	Prefix     string    `json:"prefix"`
	Hash       string    `json:"hash"`
	CreatedAt  time.Time `json:"created_at"`
	LastUsedAt time.Time `json:"last_used_at,omitempty"`
}

type APIKeyState

type APIKeyState struct {
	AuthEnabled bool           `json:"auth_enabled"`
	Keys        []APIKeyRecord `json:"keys"`
}

type APIKeyStore

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

func NewAPIKeyStore

func NewAPIKeyStore(appHome string) *APIKeyStore

func (*APIKeyStore) Create

func (s *APIKeyStore) Create(name string) (APIKeyRecord, string, error)

func (*APIKeyStore) Delete

func (s *APIKeyStore) Delete(id string) (bool, error)

func (*APIKeyStore) SetAuthEnabled

func (s *APIKeyStore) SetAuthEnabled(enabled bool) (APIKeyState, error)

func (*APIKeyStore) State

func (s *APIKeyStore) State() (APIKeyState, error)

func (*APIKeyStore) Validate

func (s *APIKeyStore) Validate(plain string) (APIKeyRecord, bool, error)

type APIUsageEvent

type APIUsageEvent struct {
	APIKeyID     string
	APIKeyName   string
	Model        string
	Source       string
	SourceType   string
	SourceName   string
	InputTokens  int64
	OutputTokens int64
	CreatedAt    time.Time
}

type APIUsageEventRecord

type APIUsageEventRecord struct {
	APIKeyID     string    `json:"api_key_id"`
	APIKeyName   string    `json:"api_key_name"`
	Model        string    `json:"model"`
	Source       string    `json:"source,omitempty"`
	SourceType   string    `json:"source_type,omitempty"`
	SourceName   string    `json:"source_name,omitempty"`
	Requests     int64     `json:"requests,omitempty"`
	InputTokens  int64     `json:"input_tokens"`
	OutputTokens int64     `json:"output_tokens"`
	TotalTokens  int64     `json:"total_tokens"`
	CreatedAt    time.Time `json:"created_at"`
}

type APIUsageListOptions

type APIUsageListOptions struct {
	Since    *time.Time
	Until    *time.Time
	Provider string
}

type APIUsageRecord

type APIUsageRecord struct {
	APIKeyID     string    `json:"api_key_id"`
	APIKeyName   string    `json:"api_key_name"`
	Model        string    `json:"model"`
	Source       string    `json:"source,omitempty"`
	SourceType   string    `json:"source_type,omitempty"`
	SourceName   string    `json:"source_name,omitempty"`
	Requests     int64     `json:"requests"`
	InputTokens  int64     `json:"input_tokens"`
	OutputTokens int64     `json:"output_tokens"`
	TotalTokens  int64     `json:"total_tokens"`
	LastUsedAt   time.Time `json:"last_used_at"`
}

type APIUsageState

type APIUsageState struct {
	Records []APIUsageRecord      `json:"records"`
	Events  []APIUsageEventRecord `json:"events,omitempty"`
}

type APIUsageStore

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

func NewAPIUsageStore

func NewAPIUsageStore(appHome string) *APIUsageStore

func (*APIUsageStore) Add

func (s *APIUsageStore) Add(event APIUsageEvent) error

func (*APIUsageStore) List

type Config

type Config struct {
	ServerURL            string            `json:"server_url"`
	AIGatewayURL         string            `json:"ai_gateway_url,omitempty"`
	CloudProviderName    string            `json:"cloud_provider_name,omitempty"`
	Token                string            `json:"token,omitempty"`
	OpenCSGAPIKey        string            `json:"opencsg_api_key,omitempty"`
	ListenAddr           string            `json:"listen_addr"`
	ModelDir             string            `json:"model_dir"`
	DatasetDir           string            `json:"dataset_dir"`
	AIAppPreferredModels map[string]string `json:"ai_app_preferred_models,omitempty"`
	WebSearch            WebSearchConfig   `json:"web_search,omitempty"`
}

func Get

func Get() *Config

func Load

func Load() (*Config, error)

func (*Config) DisplayURL

func (c *Config) DisplayURL() string

func (*Config) StorageDir

func (c *Config) StorageDir() string

func (*Config) TempDir

func (c *Config) TempDir() string

type ProviderModelAllowlist

type ProviderModelAllowlist struct {
	Version   int                                 `json:"version"`
	Providers map[string][]ProviderModelSelection `json:"providers"`
}

func LoadProviderModelAllowlist

func LoadProviderModelAllowlist() (ProviderModelAllowlist, error)

type ProviderModelSelection

type ProviderModelSelection struct {
	Model              string   `json:"model"`
	OriginalModel      string   `json:"original_model,omitempty"`
	CatalogDisplayName string   `json:"catalog_display_name,omitempty"`
	DisplayName        string   `json:"display_name,omitempty"`
	Description        string   `json:"description,omitempty"`
	PipelineTag        string   `json:"pipeline_tag,omitempty"`
	InputModalities    []string `json:"input_modalities,omitempty"`
	OutputModalities   []string `json:"output_modalities,omitempty"`
}

func GetProviderModelSelections

func GetProviderModelSelections(providerID string) []ProviderModelSelection

func UpdateProviderModelSelection

func UpdateProviderModelSelection(providerID, modelID string, update ProviderModelSelectionUpdate) (ProviderModelSelection, bool, error)

func (*ProviderModelSelection) UnmarshalJSON

func (s *ProviderModelSelection) UnmarshalJSON(data []byte) error

type ProviderModelSelectionUpdate

type ProviderModelSelectionUpdate struct {
	Model       *string
	DisplayName *string
	Description *string
}

type ThirdPartyProvider

type ThirdPartyProvider struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	BaseURL  string `json:"base_url"`
	APIKey   string `json:"api_key"`
	Provider string `json:"provider,omitempty"`
	Enabled  bool   `json:"enabled"`
}

ThirdPartyProvider represents a third-party API provider configuration

func GetProviders

func GetProviders() []ThirdPartyProvider

GetProviders returns the loaded third-party providers

func LoadProviders

func LoadProviders() ([]ThirdPartyProvider, error)

LoadProviders loads third-party providers from the config file

type WebSearchConfig

type WebSearchConfig struct {
	Enabled        bool     `json:"enabled,omitempty"`
	MaxResults     int      `json:"max_results,omitempty"`
	Language       string   `json:"language,omitempty"`
	Providers      []string `json:"providers,omitempty"`
	SafeSearch     int      `json:"safe_search,omitempty"`
	TimeoutSeconds int      `json:"timeout_seconds,omitempty"`
}

func DefaultWebSearchConfig

func DefaultWebSearchConfig() WebSearchConfig

func NormalizeWebSearchConfig

func NormalizeWebSearchConfig(cfg WebSearchConfig) WebSearchConfig

Jump to

Keyboard shortcuts

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