Skip to content

Add AI search in plain language - #1

Merged
AD-coderr merged 1 commit into
mainfrom
ai-search
Nov 15, 2026
Merged

AD-coderr merged 1 commit into
mainfrom
ai-search

Conversation

@AD-coderr

Copy link
Copy Markdown
Owner

What this adds

An Ask AI bar on the Assets page. Type a question such as "which laptops in Berlin are free?" and the table narrows to the matching devices, with the interpreted filters shown as chips.

How it works

  1. POST /ai/search sends the question to an OpenAI-compatible chat API, together with the asset types, brands, locations and departments that exist in the database.
  2. The model replies with a small JSON filter (status, type, brand, model, location, current holder, department, free text).
  3. The reply is validated with Pydantic, and the API builds the SQLAlchemy query itself.

The model never writes SQL and has no database access, so a manipulated question can at worst produce a wrong filter. Unknown keys are dropped; invalid values return 502.

Configuration

Off by default; the app behaves exactly as before without it. Enable with ASSETFLOW_LLM_BASE_URL, ASSETFLOW_LLM_MODEL and (for hosted providers) ASSETFLOW_LLM_API_KEY. See the new README section and .env.example. No new dependency: the client uses the standard library.

Testing

  • New backend/tests/test_ai_search.py (model mocked): filters, current holder, LIKE wildcards treated literally, prose-wrapped replies, unusable replies, provider failure, input validation.
  • UI checked in a browser against sample data (light, dark, mobile, AI on and off).
  • Not yet run: the backend test suite, which this PR's CI run is the first execution of, and a real model end to end.

Generated by Claude Code

Ask a question such as "which laptops in Berlin are free?" on the Assets
page and the table narrows to the matching devices.

- POST /ai/search sends the question to an OpenAI-compatible chat API,
  which replies with a JSON filter (status, type, brand, model, location,
  current holder, department, free text)
- The reply is validated with Pydantic and the API builds the SQLAlchemy
  query itself; the model never writes SQL or touches the database
- GET /ai/status tells the web UI whether AI search is configured
- Off by default: enabled through ASSETFLOW_LLM_BASE_URL, ASSETFLOW_LLM_MODEL
  and ASSETFLOW_LLM_API_KEY; no new dependency (standard library client)
- Web UI: "Ask AI" bar with the interpreted filters shown as chips
- Tests with a mocked model, README section and .env.example

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017eYATpzPeBWrAevdHnoopb
@AD-coderr
AD-coderr merged commit 97cd7d2 into main Nov 15, 2026
1 check passed
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