feat: Implement GoogleProvider for Google Generative AI integration

- Added GoogleProvider class to handle chat completions with Google Gemini API.
- Implemented client initialization and response handling for streaming and non-streaming responses.
- Created utility functions for tool conversion, response parsing, and content extraction.
- Removed legacy tool conversion utilities from the tools module.
- Enhanced logging for better traceability of API interactions and error handling.
This commit is contained in:
2025-03-27 11:11:56 +00:00
parent 678f395649
commit 6b390a35f8
10 changed files with 979 additions and 567 deletions

View File

@@ -0,0 +1,27 @@
# 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-generativeai) 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