bot: kolejkowany interfejs zapytań AI + recenzja wyników librariana #2
Reference in New Issue
Block a user
Delete Branch "ai-query-interface"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Dwie powiązane funkcje.
1) Interfejs zapytań AI (przez warstwę komunikacji)
communication_subroutinedostajeAI_QUERY_Q, wewnętrznysubmit_ai_query()i authed endpointPOST /ai_query({prompt, channel_id, request_type?, username?}). Prompt jest kolejkowany i obsługiwany asynchronicznie przez nowytasks.loopw always-loaded cogu AI (Events), który wołahandle_response— czyli leci aktywnym backendem (przełącznik$gadaj_teraz, GPT/Claude) — i wysyła odpowiedź na wskazany kanał (dzieli na porcje ≤1900).request_type="NONE"(domyślne) = czysty strzał: bez persony, bez pisania do pamięci. Worker startuje przed guardem OpenAI, więc działa też na Claude-only;cog_unloadgo anuluje.2) Recenzja AI wyników librariana
Nowa komenda
$wyszukaj_z_recenzjadziała jak$wyszukaj_linki_do_dokumentow, ale ustawiaai_review=TruenaQueryControl— flaga przeżywa drogę tam-i-z-powrotem (match po UUID). Gdy wyniki wracają,check_data_qwysyła surową listę jak dotąd, a potem — jeśli flaga — przekazuje tę samą listę (już w kolejności trafności Crossref) + hasło do kolejki AI po przeważenie i recenzję źródeł, na ten sam kanał.QueryControldostajeai_review(domyślnie False, więc ścieżka orphan i wszyscy istniejący wołający bez zmian).Potwierdzone (i w docs): lista DOI trafiająca do AI jest presortowana trafnością Crossref — pipeline tylko filtruje (wyrzuca bez tytułu) i dzieli (w bazie / nie), nigdy nie re-sortuje; zależność: insertion-ordered dict (Py 3.7+).
Weryfikacja
/ai_query(401/200/400/otwarte),submit_ai_query+ kształt kolejkowanego dicta, flagaQueryControl— klient Flask +tests/integration/test_ai_query_endpoint.py(5 testów). Kompilacja całości czysta. Worker i ścieżkacheck_data_qnie odpalane na żywo (wymagają działającego bota) — sprawdzone kompilacją i przeglądem.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>