mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
8e294a5eed
- 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.8 KiB
Go
74 lines
1.8 KiB
Go
package provider
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"nofx/mcp"
|
|
)
|
|
|
|
const (
|
|
DefaultOpenAIBaseURL = "https://api.openai.com/v1"
|
|
DefaultOpenAIModel = "gpt-5.4"
|
|
)
|
|
|
|
func init() {
|
|
mcp.RegisterProvider(mcp.ProviderOpenAI, func(opts ...mcp.ClientOption) mcp.AIClient {
|
|
return NewOpenAIClientWithOptions(opts...)
|
|
})
|
|
}
|
|
|
|
type OpenAIClient struct {
|
|
*mcp.Client
|
|
}
|
|
|
|
func (c *OpenAIClient) BaseClient() *mcp.Client { return c.Client }
|
|
|
|
// NewOpenAIClient creates OpenAI client (backward compatible)
|
|
func NewOpenAIClient() mcp.AIClient {
|
|
return NewOpenAIClientWithOptions()
|
|
}
|
|
|
|
// NewOpenAIClientWithOptions creates OpenAI client (supports options pattern)
|
|
func NewOpenAIClientWithOptions(opts ...mcp.ClientOption) mcp.AIClient {
|
|
openaiOpts := []mcp.ClientOption{
|
|
mcp.WithProvider(mcp.ProviderOpenAI),
|
|
mcp.WithModel(DefaultOpenAIModel),
|
|
mcp.WithBaseURL(DefaultOpenAIBaseURL),
|
|
}
|
|
|
|
allOpts := append(openaiOpts, opts...)
|
|
baseClient := mcp.NewClient(allOpts...).(*mcp.Client)
|
|
|
|
openaiClient := &OpenAIClient{
|
|
Client: baseClient,
|
|
}
|
|
|
|
baseClient.Hooks = openaiClient
|
|
return openaiClient
|
|
}
|
|
|
|
func (c *OpenAIClient) SetAPIKey(apiKey string, customURL string, customModel string) {
|
|
c.APIKey = apiKey
|
|
|
|
if len(apiKey) > 8 {
|
|
c.Log.Infof("🔧 [MCP] OpenAI API Key: %s...%s", apiKey[:4], apiKey[len(apiKey)-4:])
|
|
}
|
|
if customURL != "" {
|
|
c.BaseURL = customURL
|
|
c.Log.Infof("🔧 [MCP] OpenAI using custom BaseURL: %s", customURL)
|
|
} else {
|
|
c.Log.Infof("🔧 [MCP] OpenAI using default BaseURL: %s", c.BaseURL)
|
|
}
|
|
if customModel != "" {
|
|
c.Model = customModel
|
|
c.Log.Infof("🔧 [MCP] OpenAI using custom Model: %s", customModel)
|
|
} else {
|
|
c.Log.Infof("🔧 [MCP] OpenAI using default Model: %s", c.Model)
|
|
}
|
|
}
|
|
|
|
// OpenAI uses standard Bearer auth
|
|
func (c *OpenAIClient) SetAuthHeader(reqHeaders http.Header) {
|
|
c.Client.SetAuthHeader(reqHeaders)
|
|
}
|