Skip to content

Harden gemini_brain: env keys, retry/backoff, tests & CI#4

Draft
Claude wants to merge 2 commits into
mainfrom
claude/bi
Draft

Harden gemini_brain: env keys, retry/backoff, tests & CI#4
Claude wants to merge 2 commits into
mainfrom
claude/bi

Conversation

@Claude
Copy link
Copy Markdown

@Claude Claude AI commented Feb 13, 2026

Removes hardcoded API keys, adds exponential backoff for rate limits, and establishes test infrastructure with CI.

Security

  • Environment variables for secrets: All API keys now read from GOOGLE_API_KEY and PEXELS_API_KEY environment variables
  • Files updated: gemini_brain.py, imagen_brain.py, scan_weapons.py, veo_brain.py, veo_proof.py, pexels_brain.py
  • Configuration: Added .env.example template with required keys

Reliability

  • Exponential backoff: gemini_brain.get_viral_script() retries 429 rate-limit errors with increasing delays (5s → 10s → 20s)
  • Configurable: retries and backoff_factor parameters allow tuning
# Before: hardcoded key, no retry logic
API_KEY = "AIzaSy..."
response = model.generate_content(prompt)

# After: env-based key, automatic retry on rate limits
api_key = os.environ.get("GOOGLE_API_KEY")
for attempt in range(retries):
    try:
        return model.generate_content(prompt).text
    except Exception as e:
        if "429" in str(e):
            time.sleep((backoff_factor ** attempt) * 5)

Testing

  • Mocked unit tests: tests/test_gemini_brain.py and tests/test_backoff.py validate API key handling and retry behavior
  • CI workflow: .github/workflows/python-tests.yml runs pytest on push/PR
  • Dev dependencies: requirements-dev.txt added with pytest

Build artifacts

  • Updated .gitignore: Excludes generated media files (temp_*.mp3, VISUAL_*.png, etc.) and standard Python artifacts

- Replace hard-coded API keys with environment variables (GOOGLE_API_KEY, PEXELS_API_KEY)
- Add exponential backoff for 429 rate-limits in gemini_brain.py
- Add unit tests with mocking (tests/test_gemini_brain.py, tests/test_backoff.py)
- Add GitHub Actions CI workflow (.github/workflows/python-tests.yml)
- Add .env.example and requirements-dev.txt
- Update .gitignore to exclude temp files and build artifacts

Co-authored-by: atherion005-byte <239668684+atherion005-byte@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Add bi Harden gemini_brain: env keys, retry/backoff, tests & CI Feb 13, 2026
@Claude Claude AI requested a review from atherion005-byte February 13, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants