bot: queued AI query interface + librarian AI review of results
Two connected features.
1) AI query interface (via the comm layer). communication_subroutine gains an
AI_QUERY_Q, a submit_ai_query() in-process entry point, and an authed
POST /ai_query endpoint ({prompt, channel_id, request_type?, username?}). The
prompt is queued and answered asynchronously by a new tasks.loop worker in the
always-loaded AI cog (Events), which calls handle_response - so it runs on
whichever backend $gadaj_teraz currently selects (GPT or Claude) - and posts the
answer to the requested channel, chunked to Discord's limit. request_type "NONE"
(default) is a clean one-shot: no persona system prompt, no memory write. The
worker starts before the OpenAI guard in cog_load, so it also runs on a
Claude-only box; cog_unload cancels it.
2) Librarian AI review. New command $wyszukaj_z_recenzja mirrors
$wyszukaj_linki_do_dokumentow but sets ai_review=True on the QueryControl, which
rides the round-trip and is matched back by UUID. When the hits return,
check_data_q sends the raw list as before, then - if flagged - hands the same
list (already in Crossref-relevance order) plus the search phrase to the AI
queue for a weighted re-rank and per-source review, delivered to the same
channel. QueryControl gains an ai_review flag (default False, so the orphan path
and all existing callers are unaffected).
Confirmed separately (and noted in the docs): the DOI list the AI receives is
pre-sorted by Crossref relevance - the librarian pipeline only filters (drops
title-less items) and splits (in-db / not-in-db), never re-sorts, and relies on
insertion-ordered dicts (Py 3.7+).
Verified: /ai_query auth (401/200/400/open), submit_ai_query and the queued
dict shape, and the QueryControl flag - via a Flask test client and
tests/integration/test_ai_query_endpoint.py (5 tests, all pass; integration
suite 11 passed, the 3 failures are the pre-existing /clear_pr_pls musician
tests fixed on a separate branch). Full first-party compile clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit was merged in pull request #2.
This commit is contained in:
@@ -20,6 +20,7 @@ The three talk to each other over HTTP on the Proxmox LAN. Direction of calls:
|
||||
bot --(/query)--------------------------------> librarian
|
||||
musician --(/prepped_tracks)--------------------> bot
|
||||
librarian --(/conjurer results)-----------------> bot
|
||||
* --(/ai_query)-----------------------------> bot (see 1c-ter)
|
||||
```
|
||||
|
||||
Everything is configured through `CONJURER_*` environment variables (see the
|
||||
@@ -117,6 +118,23 @@ generation (`imaginuje sobie:`) and personal assistants stay on OpenAI whatever
|
||||
the switch says (Anthropic has no equivalent) and degrade quietly if OpenAI is
|
||||
not configured, so a Claude-only box still boots.
|
||||
|
||||
### 1c-ter. AI query interface + librarian AI review
|
||||
|
||||
The bot exposes a queued AI interface on its comm layer: `POST /ai_query` with
|
||||
`{"prompt": ..., "channel_id": <discord channel id>, "request_type"?: "NONE"}`
|
||||
(same `X-Conjurer-Api-Key` auth as the other endpoints). The prompt is queued and
|
||||
answered asynchronously by whatever backend `$gadaj_teraz` currently selects
|
||||
(GPT or Claude), and the answer is posted to `channel_id`. `request_type: "NONE"`
|
||||
(the default) keeps it a clean one-shot that doesn't touch the bar's
|
||||
conversation memory.
|
||||
|
||||
The first consumer of this is the librarian command **`$wyszukaj_z_recenzja`**:
|
||||
it works like `$wyszukaj_linki_do_dokumentow`, but when the DOI hits come back
|
||||
the list (already sorted by Crossref relevance) plus the search phrase are handed
|
||||
to the AI for a weighted-relevance re-rank and a short source review, delivered
|
||||
to the same channel right after the raw results. No extra config — it uses the
|
||||
active AI backend.
|
||||
|
||||
### 1d. Configure and launch
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user