SCRUM-39:Adding setup for Groq API call#516
Open
smaharjan-web wants to merge 1 commit into
Open
Conversation
smaharjan-web
marked this pull request as ready for review
July 1, 2026 03:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)