Files
nofx/mcp/kimi_client.go
T
tinkle-community e5703ffab6 feat: add Grok, OpenAI, Claude, Gemini, Kimi AI providers
- Add new MCP clients for Grok (xAI), OpenAI, Claude, Gemini, Kimi
- Update auto_trader, backtest, and strategy to support all providers
- Add provider icons and fix SVG gradient conflicts
- Add API application links and hints in model config modal
- Show model version in AI model list cards
- Add Chinese/English translations for provider hints
- Remove deprecated traders component files
2025-12-11 15:16:59 +08:00

72 lines
1.8 KiB
Go

package mcp
import (
"net/http"
)
const (
ProviderKimi = "kimi"
DefaultKimiBaseURL = "https://api.moonshot.ai/v1" // Global endpoint (use api.moonshot.cn for China)
DefaultKimiModel = "moonshot-v1-auto"
)
type KimiClient struct {
*Client
}
// NewKimiClient creates Kimi (Moonshot) client (backward compatible)
func NewKimiClient() AIClient {
return NewKimiClientWithOptions()
}
// NewKimiClientWithOptions creates Kimi client (supports options pattern)
func NewKimiClientWithOptions(opts ...ClientOption) AIClient {
// 1. Create Kimi preset options
kimiOpts := []ClientOption{
WithProvider(ProviderKimi),
WithModel(DefaultKimiModel),
WithBaseURL(DefaultKimiBaseURL),
}
// 2. Merge user options (user options have higher priority)
allOpts := append(kimiOpts, opts...)
// 3. Create base client
baseClient := NewClient(allOpts...).(*Client)
// 4. Create Kimi client
kimiClient := &KimiClient{
Client: baseClient,
}
// 5. Set hooks to point to KimiClient (implement dynamic dispatch)
baseClient.hooks = kimiClient
return kimiClient
}
func (c *KimiClient) SetAPIKey(apiKey string, customURL string, customModel string) {
c.APIKey = apiKey
if len(apiKey) > 8 {
c.logger.Infof("🔧 [MCP] Kimi API Key: %s...%s", apiKey[:4], apiKey[len(apiKey)-4:])
}
if customURL != "" {
c.BaseURL = customURL
c.logger.Infof("🔧 [MCP] Kimi using custom BaseURL: %s", customURL)
} else {
c.logger.Infof("🔧 [MCP] Kimi using default BaseURL: %s", c.BaseURL)
}
if customModel != "" {
c.Model = customModel
c.logger.Infof("🔧 [MCP] Kimi using custom Model: %s", customModel)
} else {
c.logger.Infof("🔧 [MCP] Kimi using default Model: %s", c.Model)
}
}
// Kimi uses standard OpenAI-compatible API, so we just use the base client methods
func (c *KimiClient) setAuthHeader(reqHeaders http.Header) {
c.Client.setAuthHeader(reqHeaders)
}