Documentation
¶
Index ¶
- Constants
- Variables
- func FormatAccountBindings(accounts map[string][]string) string
- func FormatModelMapping(mapping map[string]string) string
- func MapModel(model string) string
- func ModelAliases() map[string]string
- func ParseAPIKeyAccounts(value string, apiKeys string) (map[string][]string, error)
- func ParseModelAccounts(value string) (map[string][]string, error)
- func ParseModelMapping(value string) (map[string]string, error)
- func SetModelMapping(mapping map[string]string)
- func SplitList(value string) []string
- func ValidateFirstEventHedge(value string) error
- func WriteEnv(path string, values map[string]string) error
- type Config
- type InvalidValue
Constants ¶
const MinLogTotalMB = 20
MinLogTotalMB 是日志目录总量上限的最小值,容纳当前文件与一个轮转文件
Variables ¶
var Defaults = map[string]string{
"LISTEN_ADDR": "127.0.0.1:8007", "GEMINI_AUTH_STATES": "auth", "PROXY_API_KEY": "", "PROXY": "",
"ACCOUNT_COOLDOWN": "2m", "SESSION_TTL": "30m", "INIT_TIMEOUT": "20s", "MODEL_MAPPING": "", "GEMINI_SAVE_HISTORY": "false", "GEMINI_CONTINUE_SESSION": "false",
"LOG_LEVEL": "info", "LOG_FORMAT": "text", "REQUEST_BODY_LOG": "false", "LOG_FILE": "true", "LOG_MAX_TOTAL_MB": "500",
"PER_ACCOUNT_CONCURRENCY": "1", "ROUTING_STRATEGY": "round-robin", "ADMIN_AUTH_ENABLED": "false", "ADMIN_USERNAME": "admin",
"ADMIN_PASSWORD": "", "API_KEY_ACCOUNTS": "", "FIRST_EVENT_HEDGE": "auto", "FIRST_EVENT_HEDGE_MODELS": "gemini-4-carbon,gemini-4-argon",
"NONSTREAM_KEEPALIVE": "true", "FAKE_STREAM": "false",
"ACCOUNT_ORDER": "", "MODEL_ACCOUNTS": "",
}
Defaults 是 .env 全部配置项的默认值写法,与默认值相同的项不写入 .env
Functions ¶
func FormatAccountBindings ¶ added in v0.1.9
FormatAccountBindings 把 API key 或模型的账号绑定写成 .env 的取值,按名称排序
func FormatModelMapping ¶ added in v0.1.3
FormatModelMapping 按别名排序输出 MODEL_MAPPING 格式的映射
func ModelAliases ¶ added in v0.1.3
ModelAliases 返回当前模型别名映射的副本
func ParseAPIKeyAccounts ¶ added in v0.1.7
ParseAPIKeyAccounts 解析逗号分隔的“API key:账号|账号”绑定,跳过不在 apiKeys 中的 key,无效项与重复的 key 跳过并返回错误,其余绑定照常返回
func ParseModelAccounts ¶ added in v0.1.9
ParseModelAccounts 解析逗号分隔的“模型 ID:账号|账号”绑定,无效项与重复的模型跳过并返回错误,其余绑定照常返回
func ParseModelMapping ¶ added in v0.1.3
ParseModelMapping 解析逗号分隔的“别名:模型 ID”映射
func ValidateFirstEventHedge ¶ added in v0.1.7
ValidateFirstEventHedge 检查首事件备用请求方式是 off、auto 或正整数秒
Types ¶
type Config ¶
type Config struct {
ListenAddress string
AuthStatePaths []string
ProxyAPIKey string
ProxyURL string
AccountCooldown time.Duration
SessionTTL time.Duration
InitTimeout time.Duration
ModelMapping map[string]string
SaveHistory bool
// ContinueSession 为真时后续请求续接已登记的网页会话,为假时每个请求新建网页会话
ContinueSession bool
// NonstreamKeepalive 为真时非流式请求等待结果期间每 10 秒写出一个换行
NonstreamKeepalive bool
// FakeStream 为真时流式请求收齐完整结果后再按流式输出
FakeStream bool
LogLevel string
LogFormat string
RequestBodyLog bool
// LogFile 为 true 时日志同时写入数据目录的轮转文件,LogMaxTotalMB 是日志目录总量上限
LogFile bool
LogMaxTotalMB int
// PerAccountConcurrency 是每个账号同时进行的上游请求数
PerAccountConcurrency int
// RoutingStrategy 为 round-robin 或 fill-first
RoutingStrategy string
// AdminAuthEnabled 为 true 时管理端要求登录并接受远程访问
AdminAuthEnabled bool
AdminUsername string
AdminPassword string
// APIKeyAccounts 是各 API key 可用的账号 ID,未列出的 key 可用全部账号
APIKeyAccounts map[string][]string
// AccountOrder 是 fill-first 依次使用的账号 ID
AccountOrder []string
// ModelAccounts 是各模型可用的账号 ID,未列出的模型可用全部账号
ModelAccounts map[string][]string
// FirstEventHedge 是首事件备用请求方式:off、auto 或等待秒数
FirstEventHedge string
// FirstEventHedgeModels 是发起首事件备用请求的模型 ID
FirstEventHedgeModels []string
// Invalid 是加载时取值无效、改用默认值启动的配置项
Invalid []InvalidValue
// Locked 是由进程环境变量(env)或启动参数(flag)决定、设置页不能修改的配置项
Locked map[string]string
}
Config 保存服务启动所需的全部配置
type InvalidValue ¶ added in v0.1.7
type InvalidValue struct {
Key string `json:"key"`
Value string `json:"value"`
Reason string `json:"reason"`
}
InvalidValue 是加载时取值无效、改用默认值的配置项,含 API key 的 API_KEY_ACCOUNTS 不记 Value