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 DiffusersWorkerLogPath() (string, error)
- func EmbeddingWorkerLogPath() (string, error)
- func FileLoggingEnabled() bool
- func GenerateProviderID() string
- func GetProviderModelAllowlist(providerID string) []string
- func HasProviderModelSelections(providerID string) bool
- func IsSupportedMarketplaceDatasetSource(value string) bool
- func IsSupportedMarketplaceModelSource(value string) bool
- func LlamaServerLogPath() (string, error)
- func LogDir() (string, error)
- func LogStderrEnabled() bool
- func ModelDirForStorage(storageDir string) string
- func NormalizeCloudProviderName(name string) string
- func NormalizeMarketplaceDatasetSource(value string) string
- func NormalizeMarketplaceModelSource(value string) string
- func NormalizeProviderPoolPolicy(policy string) string
- func ObservabilityRetentionDays(cfg ObservabilityConfig) int
- func ProviderModelAllowlistPath() (string, error)
- func ProviderPoolsPath() (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 ResetProviderPools()
- func ResetProviders()
- func ResolveHuggingFaceEndpoint(configured string) string
- func Save(cfg *Config) error
- func SaveProviderPools(pools []ProviderPool) 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 InferenceConfig
- type ObservabilityConfig
- type ProviderHeader
- type ProviderModelAllowlist
- type ProviderModelSelection
- type ProviderModelSelectionUpdate
- type ProviderPool
- type ProviderPoolMember
- type ThirdPartyProvider
- type WebSearchConfig
Constants ¶
const ( APIKeysFile = "api_keys.json" APIUsageFile = "api_usage.json" )
const ( DefaultServerURL = "https://hub.opencsg.com" DefaultDisplayURL = "https://opencsg.com" DefaultListenAddr = ":11435" DefaultDesktopAPIAddr = "127.0.0.1:11436" DefaultDesktopAPIBindAddr = "0.0.0.0:11436" DefaultAuthCallbackAddr = "127.0.0.1:11437" DefaultCloudProviderName = "csghub" DefaultMarketplaceSource = "opencsg" DefaultHuggingFaceEndpoint = "https://huggingface.co" ChinaHuggingFaceEndpoint = "https://hf-mirror.com" DefaultModelScopeEndpoint = "https://modelscope.cn" EnvServerURL = "CSGHUB_LITE_SERVER_URL" EnvAIGatewayURL = "CSGHUB_LITE_AI_GATEWAY_URL" EnvCloudProviderName = "CSGHUB_LITE_CLOUD_PROVIDER_NAME" EnvOpenAIStreamDefault = "CSGHUB_LITE_OPENAI_STREAM_DEFAULT" EnvHuggingFaceEndpoint = "HF_ENDPOINT" EnvHuggingFaceToken = "HF_TOKEN" EnvHuggingFaceHubToken = "HUGGING_FACE_HUB_TOKEN" EnvModelScopeEndpoint = "MODELSCOPE_ENDPOINT" EnvModelScopeToken = "MODELSCOPE_API_TOKEN" EnvModelScopeAPIKey = "MODELSCOPE_API_KEY" AppDir = ".csghub-lite" ConfigFile = "config.json" ModelsDir = "models" DatasetsDir = "datasets" TmpDir = "tmp" )
const ( LogsDir = "logs" ServerLogFileName = "csghub-lite.log" LlamaServerLogFileName = "llama-server.log" EmbeddingWorkerLogFileName = "embedding-worker.log" DiffusersWorkerLogFileName = "diffusers-worker.log" LogStderrEnv = "CSGHUB_LITE_LOG_STDERR" DisableFileLoggingEnv = "CSGHUB_LITE_DISABLE_FILE_LOGGING" )
const ( ProviderPoolPolicyPriorityWeight = "priority_weight" ProviderPoolPolicySemantic = "semantic" )
const DefaultObservabilityRetentionDays = 30
const ProviderModelAllowlistFile = "provider_model_allowlist.json"
const ProviderPoolsFile = "provider_pools.json"
ProviderPoolsFile stores user-defined model pools separately from provider credentials so existing providers.json remains backward compatible.
const ProvidersFile = "providers.json"
ProvidersFile is the filename for storing third-party providers
Variables ¶
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 DiffusersWorkerLogPath ¶ added in v0.9.13
func EmbeddingWorkerLogPath ¶ added in v0.9.13
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 IsSupportedMarketplaceDatasetSource ¶ added in v0.9.53
func IsSupportedMarketplaceModelSource ¶ added in v0.9.53
func LlamaServerLogPath ¶
func LogStderrEnabled ¶
func LogStderrEnabled() bool
func ModelDirForStorage ¶
func NormalizeMarketplaceDatasetSource ¶ added in v0.9.53
func NormalizeMarketplaceModelSource ¶ added in v0.9.53
func NormalizeProviderPoolPolicy ¶ added in v0.9.57
func ObservabilityRetentionDays ¶ added in v0.9.40
func ObservabilityRetentionDays(cfg ObservabilityConfig) int
func ProviderPoolsPath ¶ added in v0.9.36
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 ResetProviderPools ¶ added in v0.9.36
func ResetProviderPools()
func ResolveHuggingFaceEndpoint ¶ added in v0.9.54
func SaveProviderPools ¶ added in v0.9.36
func SaveProviderPools(pools []ProviderPool) error
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 APIUsageEvent struct {
APIKeyID string
APIKeyName string
Model string
Source string
SourceType string
SourceName string
PoolID string
PoolName string
PoolModel string
ActualMemberID string
MemberModel string
EstimatedCost float64
CostCurrency string
CostKnown bool
FallbackCount int64
LimitedCount int64
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"`
PoolID string `json:"pool_id,omitempty"`
PoolName string `json:"pool_name,omitempty"`
PoolModel string `json:"pool_model,omitempty"`
ActualMemberID string `json:"actual_member_id,omitempty"`
MemberModel string `json:"member_model,omitempty"`
EstimatedCost float64 `json:"estimated_cost,omitempty"`
CostCurrency string `json:"cost_currency,omitempty"`
CostKnown bool `json:"cost_known"`
FallbackCount int64 `json:"fallback_count,omitempty"`
LimitedCount int64 `json:"limited_count,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"`
PoolID string `json:"pool_id,omitempty"`
PoolName string `json:"pool_name,omitempty"`
PoolModel string `json:"pool_model,omitempty"`
ActualMemberID string `json:"actual_member_id,omitempty"`
MemberModel string `json:"member_model,omitempty"`
EstimatedCost float64 `json:"estimated_cost,omitempty"`
CostCurrency string `json:"cost_currency,omitempty"`
CostKnown bool `json:"cost_known"`
FallbackCount int64 `json:"fallback_count,omitempty"`
LimitedCount int64 `json:"limited_count,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"`
HuggingFaceEndpoint string `json:"huggingface_endpoint,omitempty"`
HuggingFaceToken string `json:"huggingface_token,omitempty"`
ModelScopeEndpoint string `json:"modelscope_endpoint,omitempty"`
ModelScopeToken string `json:"modelscope_token,omitempty"`
MarketplaceModelSource string `json:"marketplace_model_source,omitempty"`
MarketplaceDatasetSource string `json:"marketplace_dataset_source,omitempty"`
ListenAddr string `json:"listen_addr"`
ModelDir string `json:"model_dir"`
DatasetDir string `json:"dataset_dir"`
OpenAIStreamDefault bool `json:"-"`
AIAppPreferredModels map[string]string `json:"ai_app_preferred_models,omitempty"`
AIAppPreferredSources map[string]string `json:"ai_app_preferred_sources,omitempty"`
AIAppModelBindings map[string][]api.AIAppModelBinding `json:"ai_app_model_bindings,omitempty"`
WebSearch WebSearchConfig `json:"web_search,omitempty"`
Observability ObservabilityConfig `json:"observability,omitempty"`
Inference InferenceConfig `json:"inference,omitempty"`
DesktopMode bool `json:"-"`
DesktopToken string `json:"-"`
DesktopSessionToken string `json:"-"`
DesktopControlToken string `json:"-"`
DesktopInstanceID string `json:"-"`
ListenAddrOverride string `json:"-"`
BoundAddr string `json:"-"`
DesktopAPIAddr string `json:"-"`
DesktopAPIBindAddr string `json:"-"`
DesktopAPIBoundAddr string `json:"-"`
AuthCallbackAddr string `json:"-"`
}
func (*Config) DisplayURL ¶
func (*Config) EffectiveListenAddr ¶ added in v0.9.31
func (*Config) RuntimeAPIAddr ¶ added in v0.9.31
func (*Config) RuntimeDockerAPIAddr ¶ added in v0.9.31
func (*Config) RuntimeListenAddr ¶ added in v0.9.31
func (*Config) StorageDir ¶
type InferenceConfig ¶ added in v0.9.54
type InferenceConfig struct {
LlamaUseModelMaxCtx bool `json:"llama_use_model_max_ctx,omitempty"`
// ModelNumCtx holds per-model context windows keyed by model ID. A model
// listed here overrides the global default but still loses to a context
// length sent with the request. It lives in the app config rather than in
// the model directory so that re-downloading a model keeps the setting.
ModelNumCtx map[string]int `json:"model_num_ctx,omitempty"`
}
InferenceConfig groups process-wide inference defaults that apply equally to the Web UI and external API clients.
type ObservabilityConfig ¶ added in v0.9.40
type ObservabilityConfig struct {
// RetentionDays is nil for legacy configurations and 0 for unlimited retention.
RetentionDays *int `json:"retention_days,omitempty"`
}
type ProviderHeader ¶ added in v0.9.43
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 ProviderPool ¶ added in v0.9.36
type ProviderPool struct {
ID string `json:"id"`
Name string `json:"name"`
Model string `json:"model"`
Enabled bool `json:"enabled"`
Policy string `json:"policy,omitempty"`
Members []ProviderPoolMember `json:"members"`
}
ProviderPool exposes one public model ID and routes it to member models.
func GetProviderPools ¶ added in v0.9.36
func GetProviderPools() []ProviderPool
func LoadProviderPools ¶ added in v0.9.36
func LoadProviderPools() ([]ProviderPool, error)
type ProviderPoolMember ¶ added in v0.9.36
type ProviderPoolMember struct {
ID string `json:"id"`
Source string `json:"source"`
Model string `json:"model"`
Priority int `json:"priority,omitempty"`
Weight int `json:"weight,omitempty"`
RequestsPM int `json:"requests_per_minute,omitempty"`
TokensPM int `json:"tokens_per_minute,omitempty"`
MaxConcurrent int `json:"max_concurrent,omitempty"`
}
ProviderPoolMember identifies a concrete model source. Source is local, cloud, or provider:<provider-id>; Model is the model ID sent upstream.
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"`
Headers []ProviderHeader `json:"headers,omitempty"`
}
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