mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-12 15:26:55 +08:00
Feature: Add support for custom OpenAI-compatible API
This update enables users to configure any OpenAI-compatible API endpoint, allowing the use of: - OpenAI official API (GPT-4, GPT-4o, etc.) - OpenRouter (access to multiple models) - Local deployed models (Ollama, LM Studio, etc.) - Other OpenAI-format compatible API services Changes: - config: Add custom_api_url, custom_api_key, custom_model_name fields - mcp: Add SetCustomAPI function and ProviderCustom constant - trader: Update AI initialization logic to support custom API - manager: Pass custom API config to trader instances - Add CUSTOM_API.md documentation with usage examples - Update config.json.example with custom API sample Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
@@ -38,6 +38,11 @@ type AutoTraderConfig struct {
|
||||
DeepSeekKey string
|
||||
QwenKey string
|
||||
|
||||
// 自定义AI API配置
|
||||
CustomAPIURL string
|
||||
CustomAPIKey string
|
||||
CustomModelName string
|
||||
|
||||
// 扫描配置
|
||||
ScanInterval time.Duration // 扫描间隔(建议3分钟)
|
||||
|
||||
@@ -91,10 +96,16 @@ func NewAutoTrader(config AutoTraderConfig) (*AutoTrader, error) {
|
||||
}
|
||||
|
||||
// 初始化AI
|
||||
if config.UseQwen {
|
||||
if config.AIModel == "custom" {
|
||||
// 使用自定义API
|
||||
mcp.SetCustomAPI(config.CustomAPIURL, config.CustomAPIKey, config.CustomModelName)
|
||||
log.Printf("🤖 [%s] 使用自定义AI API: %s (模型: %s)", config.Name, config.CustomAPIURL, config.CustomModelName)
|
||||
} else if config.UseQwen || config.AIModel == "qwen" {
|
||||
// 使用Qwen
|
||||
mcp.SetQwenAPIKey(config.QwenKey, "")
|
||||
log.Printf("🤖 [%s] 使用阿里云Qwen AI", config.Name)
|
||||
} else {
|
||||
// 默认使用DeepSeek
|
||||
mcp.SetDeepSeekAPIKey(config.DeepSeekKey)
|
||||
log.Printf("🤖 [%s] 使用DeepSeek AI", config.Name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user