Skip to content

SCRUM-39:Adding setup for Groq API call#516

Open
smaharjan-web wants to merge 1 commit into
boom-astro:mainfrom
smaharjan-web:groq-api-backend-setup
Open

SCRUM-39:Adding setup for Groq API call#516
smaharjan-web wants to merge 1 commit into
boom-astro:mainfrom
smaharjan-web:groq-api-backend-setup

Conversation

@smaharjan-web

@smaharjan-web smaharjan-web commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Move Groq LLM filter generation server-side

Summary

Babamul's natural-language → alert-filter feature previously called the Groq API directly from the browser, with the API key baked into the frontend bundle — exposing it to every visitor. This PR moves that call behind an authenticated backend endpoint, builds the LLM prompt server-side, and adds encrypted per-user key storage with a shared server fallback key.

What changed

  • New authenticated endpoints (/babamul scope):

  • POST /babamul/llm/filter — generates a validated filter tree from a NL query for a given survey (ZTF/LSST)

  • PUT /babamul/profile/groq-key — save a user's own Groq key

  • DELETE /babamul/profile/groq-key — remove it

  • Key handling: user keys are encrypted (AES-256-GCM, reusing existing crypto helpers) and stored on the user document; a server default key (BOOM_BABAMUL__GROQ_API_KEY) is used
    as fallback. Per-user key takes precedence.

  • Prompt moved server-side: the system prompt (ported from the old llmFilterAgent.ts) and model are now controlled by the backend.

  • Data model: added groq_api_key_encrypted to the user (backward-compatible via #[serde(default)], no migration needed) and exposed has_groq_api_key on the public profile.

  • Config: BOOM_BABAMUL__GROQ_API_KEY and BOOM_BABAMUL__GROQ_MODEL (defaults to llama-3.3-70b-versatile), documented in config.yaml and .env.example.

  • Docs & tests: endpoints registered in the OpenAPI (BabamulApiDoc) spec; test fixtures updated.

    Security notes

  • API key no longer shipped to the browser

  • User keys stored encrypted at rest, never returned in plaintext

  • Input limits (query/key length), markdown-fence stripping, and filter shape validation

  • Provider error bodies are not echoed back to clients (avoids leaking key fragments)

@smaharjan-web smaharjan-web changed the title adding setup for Groq API call with user API key input option plus de… SCRUM-39:Adding setup for Groq API call Jul 1, 2026
@smaharjan-web
smaharjan-web marked this pull request as ready for review July 1, 2026 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant