Spaces:
Sleeping
Sleeping
| import os | |
| from typing import Tuple | |
| from dotenv import load_dotenv | |
| from openai import OpenAI | |
| from utils.db_utils import DatabaseUtils | |
| def check_credentials() -> Tuple[bool, str]: | |
| """Check if required credentials are set and valid | |
| Returns: | |
| Tuple[bool, str]: (is_valid, message) | |
| - is_valid: True if all credentials are valid | |
| - message: Error message if credentials are invalid | |
| """ | |
| # Load environment variables | |
| load_dotenv() | |
| atlas_uri = os.getenv("ATLAS_URI") | |
| openai_key = os.getenv("OPENAI_API_KEY") | |
| if not atlas_uri: | |
| return False, """Please set up your MongoDB Atlas credentials: | |
| 1. Go to Settings tab | |
| 2. Add ATLAS_URI as a Repository Secret | |
| 3. Paste your MongoDB connection string (should start with 'mongodb+srv://')""" | |
| if not openai_key: | |
| return False, """Please set up your OpenAI API key: | |
| 1. Go to Settings tab | |
| 2. Add OPENAI_API_KEY as a Repository Secret | |
| 3. Paste your OpenAI API key""" | |
| return True, "" | |
| def init_clients(): | |
| """Initialize OpenAI and MongoDB clients | |
| Returns: | |
| Tuple[OpenAI, DatabaseUtils]: OpenAI client and DatabaseUtils instance | |
| or (None, None) if initialization fails | |
| """ | |
| try: | |
| openai_client = OpenAI() | |
| db_utils = DatabaseUtils() | |
| return openai_client, db_utils | |
| except Exception as e: | |
| return None, None | |