mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-09 22:10:57 +08:00
- Delete llm/ dead code (3 files, zero references) - Split mcp/ into sub-packages: mcp/provider/ (8 providers) and mcp/payment/ (4 payment clients) with registry pattern - Export Client internal fields and ClientHooks interface for sub-package access - Split api/server.go (3892 lines) into 8 domain-specific handler files - Split trader/auto_trader.go (2296 lines) into 5 focused files - Reorganize web/src/components/ flat files into auth/, charts/, trader/, common/, modals/, backtest/ subdirectories - Update all consumer imports to use registry-based provider creation
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package provider
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"nofx/mcp"
|
|
)
|
|
|
|
const (
|
|
DefaultQwenBaseURL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
DefaultQwenModel = "qwen3-max"
|
|
)
|
|
|
|
func init() {
|
|
mcp.RegisterProvider(mcp.ProviderQwen, func(opts ...mcp.ClientOption) mcp.AIClient {
|
|
return NewQwenClientWithOptions(opts...)
|
|
})
|
|
}
|
|
|
|
type QwenClient struct {
|
|
*mcp.Client
|
|
}
|
|
|
|
func (c *QwenClient) BaseClient() *mcp.Client { return c.Client }
|
|
|
|
// NewQwenClient creates Qwen client (backward compatible)
|
|
//
|
|
// Deprecated: Recommend using NewQwenClientWithOptions for better flexibility
|
|
func NewQwenClient() mcp.AIClient {
|
|
return NewQwenClientWithOptions()
|
|
}
|
|
|
|
// NewQwenClientWithOptions creates Qwen client (supports options pattern)
|
|
func NewQwenClientWithOptions(opts ...mcp.ClientOption) mcp.AIClient {
|
|
qwenOpts := []mcp.ClientOption{
|
|
mcp.WithProvider(mcp.ProviderQwen),
|
|
mcp.WithModel(DefaultQwenModel),
|
|
mcp.WithBaseURL(DefaultQwenBaseURL),
|
|
}
|
|
|
|
allOpts := append(qwenOpts, opts...)
|
|
baseClient := mcp.NewClient(allOpts...).(*mcp.Client)
|
|
|
|
qwenClient := &QwenClient{
|
|
Client: baseClient,
|
|
}
|
|
|
|
baseClient.Hooks = qwenClient
|
|
return qwenClient
|
|
}
|
|
|
|
func (qwenClient *QwenClient) SetAPIKey(apiKey string, customURL string, customModel string) {
|
|
qwenClient.APIKey = apiKey
|
|
|
|
if len(apiKey) > 8 {
|
|
qwenClient.Log.Infof("🔧 [MCP] Qwen API Key: %s...%s", apiKey[:4], apiKey[len(apiKey)-4:])
|
|
}
|
|
if customURL != "" {
|
|
qwenClient.BaseURL = customURL
|
|
qwenClient.Log.Infof("🔧 [MCP] Qwen using custom BaseURL: %s", customURL)
|
|
} else {
|
|
qwenClient.Log.Infof("🔧 [MCP] Qwen using default BaseURL: %s", qwenClient.BaseURL)
|
|
}
|
|
if customModel != "" {
|
|
qwenClient.Model = customModel
|
|
qwenClient.Log.Infof("🔧 [MCP] Qwen using custom Model: %s", customModel)
|
|
} else {
|
|
qwenClient.Log.Infof("🔧 [MCP] Qwen using default Model: %s", qwenClient.Model)
|
|
}
|
|
}
|
|
|
|
func (qwenClient *QwenClient) SetAuthHeader(reqHeaders http.Header) {
|
|
qwenClient.Client.SetAuthHeader(reqHeaders)
|
|
}
|