-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
91 lines (71 loc) · 3.01 KB
/
config.py
File metadata and controls
91 lines (71 loc) · 3.01 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""Configuration module for Avra backend."""
import logging
import os
from dotenv import load_dotenv
from kerykeion.utilities import setup_logging # noqa: F401 # Ensures logging configuration for kerykeion
# Load environment variables from .env file if present
load_dotenv()
# Configure logging
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
# Suppress verbose logs from third-party libraries
logging.getLogger('httpx').setLevel(logging.INFO)
logging.getLogger('httpcore').setLevel(logging.INFO)
logging.getLogger('root').setLevel(logging.INFO)
logger = logging.getLogger(__name__)
# Environment variables
GEMINI_API_KEY = os.getenv('GEMINI_API_KEY') # Add Gemini API Key
PROJECT_ID = os.getenv('PROJECT_ID')
LOCATION = os.getenv('LOCATION')
FIRESTORE_DATABASE_ID = os.getenv('FIRESTORE_DATABASE_ID')
WEATHERKIT_TEAM_ID = os.getenv('WEATHERKIT_TEAM_ID', 'F957AP9B34')
WEATHERKIT_KEY_ID = os.getenv('WEATHERKIT_KEY_ID', '4PDNV2USTN')
WEATHERKIT_SERVICE_ID = os.getenv('WEATHERKIT_SERVICE_ID', 'com.rafasiqueira.avra.weatherkit-client')
WEATHERKIT_KEY_PATH = os.getenv('WEATHERKIT_KEY_PATH')
GCS_AUDIO_BUCKET = os.getenv('GCS_AUDIO_BUCKET')
# App configuration
APP_TITLE = "Avra API"
APP_VERSION = "1.0.0"
# CORS configuration
CORS_ORIGINS = ["*"] # In production, specify your Flutter app's domain
CORS_CREDENTIALS = True
CORS_METHODS = ["*"]
CORS_HEADERS = ["*"]
def get_logger(name: str) -> logging.Logger:
"""Get a logger instance with the specified name."""
return logging.getLogger(name)
def get_gemini_client():
"""Initialise the Google Gemini client if the API key is configured."""
try:
if GEMINI_API_KEY:
# Patch SDK before use to fix timeout bug
from genai_patch import apply_patch
apply_patch()
from google import genai
from google.genai import types
logger.info("Applying custom timeout of 60s to Gemini Client via patch")
return genai.Client(
api_key=GEMINI_API_KEY,
http_options=types.HttpOptions(timeout=60000)
)
else:
if not PROJECT_ID or not LOCATION:
logger.error("GEMINI_API_KEY not found, and PROJECT_ID/LOCATION not set for Vertex AI")
return None
logger.info(f"Using Vertex AI via google-genai SDK with project={PROJECT_ID}, location={LOCATION}")
# Patch SDK before use to fix timeout bug
from genai_patch import apply_patch
apply_patch()
from google import genai
from google.genai import types
return genai.Client(
vertexai=True,
project=PROJECT_ID,
location=LOCATION,
http_options=types.HttpOptions(timeout=60000)
)
except Exception as exc: # pragma: no cover - defensive logging
logger.error(f"Failed to initialise Gemini client: {exc}")
return None