mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-05 12:00:59 +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
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
package provider
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"nofx/mcp"
|
|
)
|
|
|
|
const (
|
|
DefaultGeminiBaseURL = "https://generativelanguage.googleapis.com/v1beta/openai"
|
|
DefaultGeminiModel = "gemini-3-pro-preview"
|
|
)
|
|
|
|
func init() {
|
|
mcp.RegisterProvider(mcp.ProviderGemini, func(opts ...mcp.ClientOption) mcp.AIClient {
|
|
return NewGeminiClientWithOptions(opts...)
|
|
})
|
|
}
|
|
|
|
type GeminiClient struct {
|
|
*mcp.Client
|
|
}
|
|
|
|
func (c *GeminiClient) BaseClient() *mcp.Client { return c.Client }
|
|
|
|
// NewGeminiClient creates Gemini client (backward compatible)
|
|
func NewGeminiClient() mcp.AIClient {
|
|
return NewGeminiClientWithOptions()
|
|
}
|
|
|
|
// NewGeminiClientWithOptions creates Gemini client (supports options pattern)
|
|
func NewGeminiClientWithOptions(opts ...mcp.ClientOption) mcp.AIClient {
|
|
geminiOpts := []mcp.ClientOption{
|
|
mcp.WithProvider(mcp.ProviderGemini),
|
|
mcp.WithModel(DefaultGeminiModel),
|
|
mcp.WithBaseURL(DefaultGeminiBaseURL),
|
|
}
|
|
|
|
allOpts := append(geminiOpts, opts...)
|
|
baseClient := mcp.NewClient(allOpts...).(*mcp.Client)
|
|
|
|
geminiClient := &GeminiClient{
|
|
Client: baseClient,
|
|
}
|
|
|
|
baseClient.Hooks = geminiClient
|
|
return geminiClient
|
|
}
|
|
|
|
func (c *GeminiClient) SetAPIKey(apiKey string, customURL string, customModel string) {
|
|
c.APIKey = apiKey
|
|
|
|
if len(apiKey) > 8 {
|
|
c.Log.Infof("🔧 [MCP] Gemini API Key: %s...%s", apiKey[:4], apiKey[len(apiKey)-4:])
|
|
}
|
|
if customURL != "" {
|
|
c.BaseURL = customURL
|
|
c.Log.Infof("🔧 [MCP] Gemini using custom BaseURL: %s", customURL)
|
|
} else {
|
|
c.Log.Infof("🔧 [MCP] Gemini using default BaseURL: %s", c.BaseURL)
|
|
}
|
|
if customModel != "" {
|
|
c.Model = customModel
|
|
c.Log.Infof("🔧 [MCP] Gemini using custom Model: %s", customModel)
|
|
} else {
|
|
c.Log.Infof("🔧 [MCP] Gemini using default Model: %s", c.Model)
|
|
}
|
|
}
|
|
|
|
// Gemini OpenAI-compatible API uses standard Bearer auth
|
|
func (c *GeminiClient) SetAuthHeader(reqHeaders http.Header) {
|
|
c.Client.SetAuthHeader(reqHeaders)
|
|
}
|