__init__.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. """Google Vertex AI provider profile: Gemini via Google Cloud's OpenAI-compatible endpoint.
  2. Auth is OAuth2 (service-account JSON or ADC), not a static key: ``agent/vertex_adapter.py``
  3. mints ``(token, base_url)`` and the token is passed as ``api_key``. ``auth_type="vertex"``
  4. keeps it out of the api_key provider path so a credentials-file path is never mistaken for a key.
  5. """
  6. from typing import Any
  7. from providers import register_provider
  8. from providers.base import ProviderProfile
  9. class VertexProfile(ProviderProfile):
  10. """Vertex AI — reuse Gemini's thinking_config translation for extra_body."""
  11. def build_extra_body(self, *, session_id: str | None = None, **context: Any) -> dict[str, Any]:
  12. """Emit ``extra_body.google.thinking_config`` like the ``gemini`` provider's OpenAI-compat subpath."""
  13. from agent.transports.chat_completions import _build_gemini_thinking_config, _snake_case_gemini_thinking_config
  14. raw = _build_gemini_thinking_config(context.get("model") or "", context.get("reasoning_config"))
  15. thinking_config = _snake_case_gemini_thinking_config(raw) if raw else None
  16. return {"extra_body": {"google": {"thinking_config": thinking_config}}} if thinking_config else {}
  17. vertex = VertexProfile(
  18. name="vertex", aliases=("google-vertex", "vertex-ai", "gcp-vertex", "vertexai"), api_mode="chat_completions",
  19. env_vars=(), # OAuth2 via service account / ADC — not a static key env var
  20. base_url="https://aiplatform.googleapis.com", # real base_url computed at runtime
  21. auth_type="vertex", default_aux_model="google/gemini-3.6-flash",
  22. supports_model_listing=False, # no /models route on the OpenAI-compat endpoint; setup ships a curated list
  23. )
  24. register_provider(vertex)