Documentation
¶
Index ¶
- func DefaultCProxyConfigPath() string
- func DefaultConfigDir() string
- func DefaultSProxyConfigPath() string
- type AdminConfig
- type CProxyAuth
- type CProxyConfig
- type ClusterConfig
- type DashboardConfig
- type DatabaseConfig
- type LLMConfig
- type LLMTarget
- type ListenConfig
- type LogConfig
- type ModelPrice
- type PricingConfig
- type SProxyAuth
- type SProxyFullConfig
- type SProxySect
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultCProxyConfigPath ¶
func DefaultCProxyConfigPath() string
DefaultCProxyConfigPath 返回跨平台默认的 c-proxy 配置文件路径
func DefaultConfigDir ¶
func DefaultConfigDir() string
DefaultConfigDir 返回跨平台配置目录 Windows: %APPDATA%\pairproxy Linux: ~/.config/pairproxy macOS: ~/Library/Application Support/pairproxy
func DefaultSProxyConfigPath ¶
func DefaultSProxyConfigPath() string
DefaultSProxyConfigPath 返回跨平台默认的 s-proxy 配置文件路径
Types ¶
type AdminConfig ¶
type AdminConfig struct {
PasswordHash string `yaml:"password_hash"` // bcrypt hash,支持 ${ENV_VAR}
}
AdminConfig s-proxy 管理员配置
type CProxyAuth ¶
type CProxyAuth struct {
TokenDir string `yaml:"token_dir"` // 默认 DefaultTokenDir()
AutoRefresh bool `yaml:"auto_refresh"` // 默认 true
RefreshThreshold time.Duration `yaml:"refresh_threshold"` // 默认 30m
}
CProxyAuth c-proxy 认证配置
type CProxyConfig ¶
type CProxyConfig struct {
Listen ListenConfig `yaml:"listen"`
SProxy SProxySect `yaml:"sproxy"`
Auth CProxyAuth `yaml:"auth"`
Log LogConfig `yaml:"log"`
}
CProxyConfig c-proxy 完整配置
func LoadCProxyConfig ¶
func LoadCProxyConfig(path string) (*CProxyConfig, []string, error)
LoadCProxyConfig 从文件加载 c-proxy 配置,并展开环境变量 返回配置结构体和所有缺失的环境变量名列表(调用方决定是否 fatal)
type ClusterConfig ¶
type ClusterConfig struct {
Role string `yaml:"role"` // "primary" | "worker"
Primary string `yaml:"primary"` // worker 用:sp-1 的地址
SelfAddr string `yaml:"self_addr"` // 本节点对外地址
SelfWeight int `yaml:"self_weight"` // 建议权重,默认 50
AlertThreshold int `yaml:"alert_threshold"` // active_req 超过此值触发告警,默认 80
AlertWebhook string `yaml:"alert_webhook"` // 可选 Webhook URL
ReportInterval time.Duration `yaml:"report_interval"` // worker 用量上报间隔,默认 30s
PeerMonitorInterval time.Duration `yaml:"peer_monitor_interval"` // primary 监控 peer 间隔,默认 30s
}
ClusterConfig 集群配置(s-proxy)
type DashboardConfig ¶
type DashboardConfig struct {
Enabled bool `yaml:"enabled"` // 默认 true(primary 节点)
}
DashboardConfig Dashboard 配置
type DatabaseConfig ¶
type DatabaseConfig struct {
Path string `yaml:"path"` // SQLite 文件路径
WriteBufferSize int `yaml:"write_buffer_size"` // 批量写入 buffer 大小,默认 200
FlushInterval time.Duration `yaml:"flush_interval"` // 强制 flush 间隔,默认 5s
}
DatabaseConfig SQLite 数据库配置
type LLMConfig ¶
type LLMConfig struct {
LBStrategy string `yaml:"lb_strategy"` // "round_robin"
RequestTimeout time.Duration `yaml:"request_timeout"` // 默认 300s
Targets []LLMTarget `yaml:"targets"`
}
LLMConfig s-proxy 上游 LLM 配置
type LLMTarget ¶
type LLMTarget struct {
URL string `yaml:"url"` // e.g. "https://api.anthropic.com"
APIKey string `yaml:"api_key"` // 支持 ${ENV_VAR} 替换
Weight int `yaml:"weight"` // 默认 1
}
LLMTarget 单个 LLM 上游节点
type ListenConfig ¶
type ListenConfig struct {
Host string `yaml:"host"` // 默认 "127.0.0.1"(c-proxy)/ "0.0.0.0"(s-proxy)
Port int `yaml:"port"` // c-proxy 默认 8080,s-proxy 默认 9000
}
ListenConfig 监听地址配置
type LogConfig ¶
type LogConfig struct {
Level string `yaml:"level"` // "debug" | "info" | "warn" | "error",默认 "info"
}
LogConfig 日志配置
type ModelPrice ¶
type ModelPrice struct {
InputPer1K float64 `yaml:"input_per_1k"` // USD per 1K input tokens
OutputPer1K float64 `yaml:"output_per_1k"` // USD per 1K output tokens
}
ModelPrice 单个模型的定价
type PricingConfig ¶
type PricingConfig struct {
// Models 按模型名称自定义定价(key = 完整模型名)
Models map[string]ModelPrice `yaml:"models"`
// 未匹配模型的默认定价(USD per 1000 tokens)
DefaultInputPer1K float64 `yaml:"default_input_per_1k"`
DefaultOutputPer1K float64 `yaml:"default_output_per_1k"`
}
PricingConfig 模型定价配置(用于估算费用)
func (*PricingConfig) ComputeCost ¶
func (p *PricingConfig) ComputeCost(model string, inputTokens, outputTokens int) float64
ComputeCost 根据模型和 token 数估算费用(USD)
type SProxyAuth ¶
type SProxyAuth struct {
JWTSecret string `yaml:"jwt_secret"` // 支持 ${ENV_VAR}
AccessTokenTTL time.Duration `yaml:"access_token_ttl"` // 默认 24h
RefreshTokenTTL time.Duration `yaml:"refresh_token_ttl"` // 默认 168h (7d)
}
SProxyAuth s-proxy JWT 配置
type SProxyFullConfig ¶
type SProxyFullConfig struct {
Listen ListenConfig `yaml:"listen"`
LLM LLMConfig `yaml:"llm"`
Database DatabaseConfig `yaml:"database"`
Auth SProxyAuth `yaml:"auth"`
Admin AdminConfig `yaml:"admin"`
Cluster ClusterConfig `yaml:"cluster"`
Dashboard DashboardConfig `yaml:"dashboard"`
Pricing PricingConfig `yaml:"pricing"`
Log LogConfig `yaml:"log"`
}
SProxyFullConfig s-proxy 完整配置
func LoadSProxyConfig ¶
func LoadSProxyConfig(path string) (*SProxyFullConfig, []string, error)
LoadSProxyConfig 从文件加载 s-proxy 配置,并展开环境变量
type SProxySect ¶
type SProxySect struct {
Primary string `yaml:"primary"` // 初始 sp-1 地址(种子节点)
LBStrategy string `yaml:"lb_strategy"` // 当前固定 "weighted_random"
HealthCheckInterval time.Duration `yaml:"health_check_interval"` // 默认 30s
RequestTimeout time.Duration `yaml:"request_timeout"` // 默认 300s
}
SProxySect c-proxy 中关于 s-proxy 的配置节