Files
mcpapp/src/providers/google_provider/client.py

28 lines
1.0 KiB
Python

# src/providers/google_provider/client.py
import logging
from typing import Any
from google import genai
logger = logging.getLogger(__name__)
def initialize_client(api_key: str, base_url: str | None = None) -> Any:
"""Initializes and returns the Google Generative AI client module."""
logger.info("Initializing Google Generative AI client")
if genai is None:
logger.error("Google Generative AI SDK (google-genai) is not installed.")
raise ImportError("Google Generative AI SDK is required for GoogleProvider. Please install google-generativeai.")
try:
# Configure the client
genai.configure(api_key=api_key)
if base_url:
logger.warning(f"base_url '{base_url}' provided but not typically used by Google client configuration.")
# Return the configured module itself, as it's used directly
return genai
except Exception as e:
logger.error(f"Failed to configure Google Generative AI client: {e}", exc_info=True)
raise