配置文件
通过配置文件管理 GPT-Load 的详细设置,支持 JSON 和 YAML 格式。
配置文件位置
GPT-Load 按以下优先级查找配置文件:
./config.json
./config.yaml
~/.gpt-load/config.json
/etc/gpt-load/config.json
JSON 配置示例
{
"server": {
"host": "0.0.0.0",
"port": 3000,
"cors": {
"origin": "*",
"credentials": true
}
},
"providers": {
"openai": {
"enabled": true,
"apiKeys": [
"sk-key1",
"sk-key2",
"sk-key3"
],
"baseURL": "https://api.openai.com",
"timeout": 30000
},
"azure": {
"enabled": false,
"endpoint": "https://your-resource.openai.azure.com",
"apiKey": "your-azure-key",
"apiVersion": "2023-12-01-preview"
}
},
"loadBalancing": {
"strategy": "round-robin",
"healthCheck": {
"enabled": true,
"interval": 60000,
"timeout": 5000
},
"retryConfig": {
"maxRetries": 3,
"retryDelay": 1000,
"backoffMultiplier": 2
}
},
"rateLimit": {
"enabled": true,
"windowMs": 60000,
"maxRequests": 100,
"keyGenerator": "ip"
},
"monitoring": {
"enabled": true,
"endpoints": {
"health": "/health",
"stats": "/stats",
"metrics": "/metrics"
}
},
"logging": {
"level": "info",
"format": "json",
"file": {
"enabled": true,
"path": "./logs/gpt-load.log",
"maxSize": "10MB",
"maxFiles": 5
}
}
}
YAML 配置示例
server:
host: "0.0.0.0"
port: 3000
cors:
origin: "*"
credentials: true
providers:
openai:
enabled: true
apiKeys:
- "sk-key1"
- "sk-key2"
- "sk-key3"
baseURL: "https://api.openai.com"
timeout: 30000
azure:
enabled: false
endpoint: "https://your-resource.openai.azure.com"
apiKey: "your-azure-key"
apiVersion: "2023-12-01-preview"
loadBalancing:
strategy: "round-robin"
healthCheck:
enabled: true
interval: 60000
timeout: 5000
retryConfig:
maxRetries: 3
retryDelay: 1000
backoffMultiplier: 2
rateLimit:
enabled: true
windowMs: 60000
maxRequests: 100
keyGenerator: "ip"
monitoring:
enabled: true
endpoints:
health: "/health"
stats: "/stats"
metrics: "/metrics"
logging:
level: "info"
format: "json"
file:
enabled: true
path: "./logs/gpt-load.log"
maxSize: "10MB"
maxFiles: 5
主要配置项说明
Server 配置
- •
host
: 服务器监听地址 - •
port
: 服务器端口 - •
cors
: CORS 跨域配置
Providers 配置
- •
openai.apiKeys
: OpenAI API 密钥数组 - •
azure.endpoint
: Azure OpenAI 端点 - •
timeout
: 请求超时时间(毫秒)
Load Balancing 配置
- •
strategy
: 负载均衡策略(round-robin, random, least-connections) - •
healthCheck
: 健康检查配置 - •
retryConfig
: 重试配置
动态重载配置
GPT-Load 支持动态重载配置文件,无需重启服务:
# 发送 SIGHUP 信号重载配置
kill -HUP $(pgrep gpt-load)
# 或通过管理接口
curl -X POST http://localhost:3000/admin/reload