Spaces:
Sleeping
Sleeping
| """ | |
| Configuration management for the Gemini AI Agent. | |
| Handles environment variables and application settings. | |
| """ | |
| import os | |
| from typing import Optional | |
| from dataclasses import dataclass | |
| class Config: | |
| """ | |
| Configuration class for the Gemini AI Agent. | |
| """ | |
| # API Configuration | |
| gemini_api_key: str | |
| model_name: str = "gemini-1.5-flash" | |
| max_tokens: int = 2048 | |
| temperature: float = 0.7 | |
| # Application Configuration | |
| max_history_length: int = 10 | |
| timeout_seconds: int = 30 | |
| def __init__(self): | |
| """ | |
| Initialize configuration from environment variables. | |
| """ | |
| self.gemini_api_key = self._get_api_key() | |
| def _get_api_key(self) -> str: | |
| """ | |
| Get the Gemini API key from environment variables. | |
| Returns: | |
| str: The API key | |
| Raises: | |
| ValueError: If API key is not found | |
| """ | |
| api_key = os.getenv('GEMINI_API_KEY') | |
| if not api_key: | |
| raise ValueError( | |
| "GEMINI_API_KEY environment variable is required. " | |
| "Please set it with your Google AI Studio API key." | |
| ) | |
| return api_key | |
| def validate(self) -> bool: | |
| """ | |
| Validate the configuration. | |
| Returns: | |
| bool: True if configuration is valid | |
| """ | |
| return bool(self.gemini_api_key and self.model_name) |