Documentation
¶
Index ¶
- Constants
- Variables
- func AddProviderModelAllowlist(providerID, modelID string) error
- func AddProviderModelSelection(providerID string, selection ProviderModelSelection) error
- func AppHome() (string, error)
- func ApplyEnvironmentDefaults(cfg *Config)
- func ConfigPath() (string, error)
- func DatasetDirForStorage(storageDir string) string
- func DefaultDatasetDir() (string, error)
- func DefaultModelDir() (string, error)
- func DefaultStorageDir() (string, error)
- func DeleteProviderModelAllowlist(providerID string) error
- func FileLoggingEnabled() bool
- func GenerateProviderID() string
- func GetProviderModelAllowlist(providerID string) []string
- func HasProviderModelSelections(providerID string) bool
- func LlamaServerLogPath() (string, error)
- func LogDir() (string, error)
- func LogStderrEnabled() bool
- func ModelDirForStorage(storageDir string) string
- func NormalizeCloudProviderName(name string) string
- func ProviderModelAllowlistPath() (string, error)
- func ProvidersPath() (string, error)
- func RemoveProviderModelAllowlist(providerID, modelID string) (bool, error)
- func ReplaceProviderModelAllowlist(providerID string, models []string) error
- func ReplaceProviderModelSelections(providerID string, models []ProviderModelSelection) error
- func Reset()
- func ResetProviderModelAllowlist()
- func ResetProviders()
- func Save(cfg *Config) error
- func SaveProviders(provs []ThirdPartyProvider) error
- func ServerLogPath() (string, error)
- func StorageDir(modelDir, datasetDir string) string
- func TempDirForStorage(storageDir string) string
- type APIKeyRecord
- type APIKeyState
- type APIKeyStore
- func (s *APIKeyStore) Create(name string) (APIKeyRecord, string, error)
- func (s *APIKeyStore) Delete(id string) (bool, error)
- func (s *APIKeyStore) SetAuthEnabled(enabled bool) (APIKeyState, error)
- func (s *APIKeyStore) State() (APIKeyState, error)
- func (s *APIKeyStore) Validate(plain string) (APIKeyRecord, bool, error)
- type APIUsageEvent
- type APIUsageEventRecord
- type APIUsageListOptions
- type APIUsageRecord
- type APIUsageState
- type APIUsageStore
- type Config
- type ProviderModelAllowlist
- type ProviderModelSelection
- type ProviderModelSelectionUpdate
- type ThirdPartyProvider
- type WebSearchConfig
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 AddProviderModelSelection ¶
func AddProviderModelSelection(providerID string, selection ProviderModelSelection) error
func ApplyEnvironmentDefaults ¶
func ApplyEnvironmentDefaults(cfg *Config)
func ConfigPath ¶
func DatasetDirForStorage ¶
func DefaultDatasetDir ¶
func DefaultModelDir ¶
func DefaultStorageDir ¶
func FileLoggingEnabled ¶
func FileLoggingEnabled() bool
func GenerateProviderID ¶
func GenerateProviderID() string
GenerateProviderID generates a random ID for a new provider
func HasProviderModelSelections ¶ added in v0.9.7
func LlamaServerLogPath ¶
func LogStderrEnabled ¶
func LogStderrEnabled() bool
func ModelDirForStorage ¶
func ProvidersPath ¶
ProvidersPath returns the path to the providers config file
func ReplaceProviderModelSelections ¶
func ReplaceProviderModelSelections(providerID string, models []ProviderModelSelection) error
func ResetProviderModelAllowlist ¶
func ResetProviderModelAllowlist()
func SaveProviders ¶
func SaveProviders(provs []ThirdPartyProvider) error
SaveProviders saves the providers to the config file
func ServerLogPath ¶
func StorageDir ¶
func TempDirForStorage ¶
Types ¶
type APIKeyRecord ¶
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) 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 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 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 ¶
func (s *APIUsageStore) List(options APIUsageListOptions) (APIUsageState, error)
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 (*Config) DisplayURL ¶
func (*Config) StorageDir ¶
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 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
Click to show internal directories.
Click to hide internal directories.