mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 04:10:51 +08:00
feat: Add support for VertexAI compatible service (#375)
feat: consolidate Vertex AI compatibility with API key support in Gemini
This commit is contained in:
@@ -29,7 +29,7 @@ func NewAPIKeyClientProvider() APIKeyClientProvider {
|
||||
type apiKeyClientProvider struct{}
|
||||
|
||||
func (p *apiKeyClientProvider) Load(ctx context.Context, cfg *config.Config) (*APIKeyClientResult, error) {
|
||||
geminiCount, claudeCount, codexCount, openAICompat := watcher.BuildAPIKeyClients(cfg)
|
||||
geminiCount, vertexCompatCount, claudeCount, codexCount, openAICompat := watcher.BuildAPIKeyClients(cfg)
|
||||
if ctx != nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -38,9 +38,10 @@ func (p *apiKeyClientProvider) Load(ctx context.Context, cfg *config.Config) (*A
|
||||
}
|
||||
}
|
||||
return &APIKeyClientResult{
|
||||
GeminiKeyCount: geminiCount,
|
||||
ClaudeKeyCount: claudeCount,
|
||||
CodexKeyCount: codexCount,
|
||||
OpenAICompatCount: openAICompat,
|
||||
GeminiKeyCount: geminiCount,
|
||||
VertexCompatKeyCount: vertexCompatCount,
|
||||
ClaudeKeyCount: claudeCount,
|
||||
CodexKeyCount: codexCount,
|
||||
OpenAICompatCount: openAICompat,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ func openAICompatInfoFromAuth(a *coreauth.Auth) (providerKey string, compatName
|
||||
if len(a.Attributes) > 0 {
|
||||
providerKey = strings.TrimSpace(a.Attributes["provider_key"])
|
||||
compatName = strings.TrimSpace(a.Attributes["compat_name"])
|
||||
if providerKey != "" || compatName != "" {
|
||||
if compatName != "" {
|
||||
if providerKey == "" {
|
||||
providerKey = compatName
|
||||
}
|
||||
@@ -362,6 +362,8 @@ func (s *Service) ensureExecutorsForAuth(a *coreauth.Auth) {
|
||||
s.coreManager.RegisterExecutor(executor.NewGeminiExecutor(s.cfg))
|
||||
case "vertex":
|
||||
s.coreManager.RegisterExecutor(executor.NewGeminiVertexExecutor(s.cfg))
|
||||
case "vertex-compat":
|
||||
s.coreManager.RegisterExecutor(executor.NewGeminiVertexCompatExecutor(s.cfg))
|
||||
case "gemini-cli":
|
||||
s.coreManager.RegisterExecutor(executor.NewGeminiCLIExecutor(s.cfg))
|
||||
case "aistudio":
|
||||
@@ -498,7 +500,7 @@ func (s *Service) Run(ctx context.Context) error {
|
||||
}()
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
fmt.Println("API server started successfully")
|
||||
fmt.Printf("API server started successfully on: %d\n", s.cfg.Port)
|
||||
|
||||
if s.hooks.OnAfterStart != nil {
|
||||
s.hooks.OnAfterStart(s)
|
||||
@@ -680,6 +682,35 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) {
|
||||
// Vertex AI Gemini supports the same model identifiers as Gemini.
|
||||
models = registry.GetGeminiVertexModels()
|
||||
models = applyExcludedModels(models, excluded)
|
||||
case "vertex-compat":
|
||||
// Handle Vertex AI compatibility providers with custom model definitions
|
||||
if s.cfg != nil && len(s.cfg.VertexCompatAPIKey) > 0 {
|
||||
// Create models for all Vertex compatibility providers
|
||||
allModels := make([]*ModelInfo, 0)
|
||||
for i := range s.cfg.VertexCompatAPIKey {
|
||||
compat := &s.cfg.VertexCompatAPIKey[i]
|
||||
for j := range compat.Models {
|
||||
m := compat.Models[j]
|
||||
// Use alias as model ID, fallback to name if alias is empty
|
||||
modelID := m.Alias
|
||||
if modelID == "" {
|
||||
modelID = m.Name
|
||||
}
|
||||
if modelID != "" {
|
||||
allModels = append(allModels, &ModelInfo{
|
||||
ID: modelID,
|
||||
Object: "model",
|
||||
Created: time.Now().Unix(),
|
||||
OwnedBy: "vertex-compat",
|
||||
Type: "vertex-compat",
|
||||
DisplayName: m.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
models = allModels
|
||||
}
|
||||
|
||||
case "gemini-cli":
|
||||
models = registry.GetGeminiCLIModels()
|
||||
models = applyExcludedModels(models, excluded)
|
||||
|
||||
@@ -49,19 +49,21 @@ type APIKeyClientProvider interface {
|
||||
Load(ctx context.Context, cfg *config.Config) (*APIKeyClientResult, error)
|
||||
}
|
||||
|
||||
// APIKeyClientResult contains API key based clients along with type counts.
|
||||
// It provides metadata about the number of clients loaded for each provider type.
|
||||
// APIKeyClientResult is returned by APIKeyClientProvider.Load()
|
||||
type APIKeyClientResult struct {
|
||||
// GeminiKeyCount is the number of Gemini API key clients loaded.
|
||||
// GeminiKeyCount is the number of Gemini API keys loaded
|
||||
GeminiKeyCount int
|
||||
|
||||
// ClaudeKeyCount is the number of Claude API key clients loaded.
|
||||
// VertexCompatKeyCount is the number of Vertex-compatible API keys loaded
|
||||
VertexCompatKeyCount int
|
||||
|
||||
// ClaudeKeyCount is the number of Claude API keys loaded
|
||||
ClaudeKeyCount int
|
||||
|
||||
// CodexKeyCount is the number of Codex API key clients loaded.
|
||||
// CodexKeyCount is the number of Codex API keys loaded
|
||||
CodexKeyCount int
|
||||
|
||||
// OpenAICompatCount is the number of OpenAI-compatible API key clients loaded.
|
||||
// OpenAICompatCount is the number of OpenAI compatibility API keys loaded
|
||||
OpenAICompatCount int
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user