File size: 1,404 Bytes
46a6768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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