Skip to content

Commit f114c1e

Browse files
committed
fix: make Gemini service resilient to missing API key in CI/CD
1 parent 2325476 commit f114c1e

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
pip install pytest httpx
2626
2727
- name: Run Backend Tests
28+
env:
29+
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
2830
run: |
2931
cd backend
3032
pytest tests/ --disable-warnings

backend/services/gemini_service.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111
class GeminiService:
1212
def __init__(self):
13-
self.client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
13+
api_key = os.getenv("GEMINI_API_KEY")
14+
if not api_key:
15+
print("WARNING: GEMINI_API_KEY not found in environment. AI services will be unavailable.")
16+
self.client = None
17+
else:
18+
self.client = genai.Client(api_key=api_key)
1419
self.model_name = "gemini-2.0-flash"
1520

1621
async def generate_text(self, prompt: str) -> str:

0 commit comments

Comments
 (0)