feat(gemini): normalize base URL to strip API version suffixes

Automatically remove trailing slashes and version paths (e.g., /v1beta) from GEMINI_BASE_URL
Update GeminiAnalyzer to use the normalized URL and add type hints
Add test coverage for Gemini client configuration
This commit is contained in:
2026-04-02 10:25:18 +08:00
parent 7003dfa0df
commit d6218d6bad
6 changed files with 104 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
import re
from typing import Self
from dotenv import load_dotenv
@@ -30,3 +31,10 @@ class Settings:
def require_api_key(self) -> None:
if not self.api_key:
raise ValueError("Missing GEMINI_API_KEY (or GOOGLE_API_KEY) in the environment.")
def normalized_base_url(self) -> str | None:
if not self.base_url:
return None
base_url = self.base_url.strip().rstrip("/")
return re.sub(r"/v\d+(?:alpha|beta)?$", "", base_url, flags=re.IGNORECASE)