feat: Add support for VertexAI compatible service (#375)

feat: consolidate Vertex AI compatibility with API key support in Gemini
This commit is contained in:
Aero
2025-12-02 08:14:22 +08:00
committed by GitHub
parent 08a1d2edf9
commit 0ebb654019
9 changed files with 633 additions and 77 deletions

View File

@@ -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)