import google.generativeai as genai from typing import List, Dict import os class GeminiChat: def __init__(self): api_key = os.getenv("GOOGLE_AI_STUDIO_KEY") if not api_key: raise ValueError("GOOGLE_AI_STUDIO_KEY environment variable not set") genai.configure(api_key=api_key) self.model = genai.GenerativeModel('gemini-pro') async def chat(self, messages: List[Dict[str, str]], temperature: float = 0.7) -> str: """Generate a chat response using Gemini API.""" try: chat = self.model.start_chat(history=messages) response = chat.send_message( messages[-1]["content"], generation_config={"temperature": temperature} ) return response.text except Exception as e: print(f"Error in Gemini chat: {e}") return ""