Integrate AI providers, improve scoring, add 3D visualization and cache#9
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR expands the Angel Filter app with additional AI/search providers, improved prompt/scoring logic, new UI visualizations (3D + radar), and an in-memory query cache with history endpoints to speed up repeated queries.
Changes:
- Adds Plotly-based visualizations and richer result rendering (score bars, provider breakdown, history UI).
- Improves client-side safety/robustness (safe URL linking, NaN guards, winner detection by index).
- Integrates cache/history UX hooks to support instant repeat queries.
Comments suppressed due to low confidence (1)
static/index.html:252
axisHtmlinterpolatesvdirectly intoinnerHTMLwithout escaping. Ifaxis_scoresever contains a non-numeric value, this becomes an XSS vector (server data is still untrusted at the browser boundary).
const axisHtml = Object.entries(axes).map(([k, v]) =>
`<div class="axis-chip">${esc(k.replace("_", " "))}: <span>${v}</span></div>`
).join("");
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <title>Angel Filter</title> | ||
| <script src="/static/plotly.min.js"></script> |
Comment on lines
153
to
+155
| let _maxScore = 1; | ||
| // Store current query results for history replay | ||
| let _lastQueries = []; |
Comment on lines
202
to
206
| function autoRotate() { | ||
| const el = document.getElementById("plot-3d"); | ||
| if (!el._layout) return; | ||
| if (!el._layout || !window.Plotly) return; | ||
| let angle = 0; | ||
| const steps = 80; |
| if (!url) return ""; | ||
| const safe = /^https?:\/\//i.test(url); | ||
| if (!safe) return ""; | ||
| return `<div class="best-snippet"><a href="${esc(url)}" target="_blank" rel="noopener noreferrer">${esc(url)}</a></div>`; |
|
|
||
| // --- Query history ---------------------------------------------------- | ||
| // --- Query history --- | ||
| // Fix #1 — use data-query attribute + delegated click listener, no inline onclick injection |
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.
Summary
Providers: Added OpenAI, Gemini, Ollama, WatsonX, and Brave Search providers. Removed DuckDuckGo (unreliable scraping) and Mock from the server build. Each provider is enabled automatically when its API key is present in
.env.Prompt engineering: Built a shared prompt builder (
prompt.py) that injects parsed constraints ($15, 4 stars, etc.) directly into AI prompts. Removeddistance_milesfrom AI prompts since models fabricate it without location context.Scoring improvements: Rebalanced weights (50% similarity / 35% axis / 15% consensus), multi-intent axis scoring so "cheap AND nearby" scores both P1 and P2, hard constraint filtering before scoring, consensus bonus capped at 2 providers, and sponsored penalty raised to 0.20.
UI: 3D scoring space (Plotly), radar chart for top 3 comparison, score bars on every result card, provider breakdown panel, and query history dropdown.
Cache: 3-hour in-memory query cache with
/historyand/cache/clearendpoints. Same query returns instantly without hitting AI providers.Bug fixes: Resolved all merge conflict markers in
index.html, fixed Copilot-flagged issues — XSS in history dropdown (switched todata-query+addEventListener),javascript:URL injection (safeLink()), winner detection by index not title,Plotly.Plots.resizeDOM element fix, NaN score bar guard.Docs: README fully rewritten with Mac and Windows setup guides, API key table, and
.env.example.Test plan
python3.12 -m pytest tests/ -v— all 23 tests should pass./start.shand check/healthshows expected providersFind me the top 3 lunch spots under $15, within 1 mile, rated at least 4 stars/historyendpoint returns cached queries