Spaces:
Running
Running
import os | |
import json | |
from dotenv import load_dotenv | |
import firebase_admin | |
from firebase_admin import credentials, firestore | |
import openai | |
def initialize(): | |
load_dotenv() | |
openai.api_key = os.environ.get('OPENAI_API_KEY') | |
if not openai.api_key: | |
raise ValueError("OpenAI API ключ не найден в переменных окружения.") | |
try: | |
firebase_admin.get_app() | |
except ValueError: | |
firebase_key = os.environ.get('FIREBASE_KEY') | |
if firebase_key: | |
key_dict = json.loads(firebase_key) | |
cred = credentials.Certificate(key_dict) | |
firebase_admin.initialize_app(cred) | |
else: | |
raise ValueError("Firebase ключ не найден в переменных окружения.") | |
db = firestore.client() | |
return db |