Repository navigation
Search overview endpoint on the quick model (E6.3) - #704
Conversation
Extract _build_chat_model from create_community_assistant and make the summarizer's one-retry call a public invoke_with_retry, for the overview endpoint to reuse. No behavior change; tests/test_api and tests/test_agents/test_model_routing.py pass.
src/api/overview.py holds the request and response models, query normalization, the cache key, the bounded 24 h cache with one call in flight per key, the prompt, the parser and the citation filter, with no FastAPI import. Unit tests cover the pure parts (87 passing).
Route in create_community_router, beside /ask: 404 without a quick_model, quick tier routing and cost check, low effort and a small token budget, one retry, a request_log row with the tier and cost (overview added to the middleware's community suffixes), 502 when no sentence survives. Tests drive the real ASGI app with a scripted model (51 passing); the real-model test is skipped without ANTHROPIC_API_KEY.
communityOverview matcher and handleOverview, handled like feedback (no Turnstile). test-routing.js covers the route on every host, POST only, the forwarded body and Origin, and a Turnstile secret not being asked for. Tested: bun test-routing.js (192) and test-mounted-hosts.js (37) pass. The worker is deployed by hand.
…hangelog) Request, response, errors, cache and budget behavior. Docs-only; tests/test_frontend/test_embed_snippet_hygiene.py passes.
answer_from_reply raises OverviewUnanswered when the surviving summary has no dataset segment, so a refusal, an off-format reply or planted text is a 502 and uncached. Sentences with a link are dropped, a long first sentence is kept instead of leaving nothing, stray single brackets are removed, and build_messages returns list[BaseMessage] (ty clean). Unit tests added; tested.
The call outlives a cancelled request, so it books its own cost on a 499 row when the request that started it is gone. A failure that is not the provider's is a 500 logged with its traceback; classified provider failures stay 502. Route tests for refusals, off-format and planted replies, the cancelled-owner spend, and the 500; the concurrency tests wait on arrivals with a 5 s timeout instead of a fixed sleep. Tested.
…chat counter 100 an hour in production, 500 in development, key rl:overview:hour; the per-minute limiter still applies. Shares a helper with the resume-chain counter. README documents the budget and the Origin trust model. Tested with workers/osa-worker/test-routing.js.
|
Worker changes detected. After merging to Manual deployment (if needed): cd workers/osa-worker
wrangler deploy --env dev # for develop branch
wrangler deploy # for main branch |
|
Review round 1: outcome for each finding (fix commits
Verification: |
…ntrol on /overview (docs only)
…m overviews (tested)
…n_words (collects, not run: needs key)
|
Review round 2 outcomes (fix commits c142363, 55ecb05, fb14145, f159061 on this branch).
Tests: |
Summary
POST /{community_id}/overviewfor the Discover panel of board D2 (nemarOrg/website#518), plan E6.3.The caller sends a query, its filters and up to 10 search results; the community's quick model writes a summary of at most about 100 words as segments (
{text}or{dataset_id}), up to 3 picks,cited_ids,shown,cached,modelandgenerated_at.create_community_routerbeside/ask. 404 when the community has noquick_model(no new config key), 502 when no sentence survives._route_request(..., tier="quick"),_check_model_cost, then a new_build_chat_modelhelper thatcreate_community_assistantnow also uses (extracted from its inline provider block, behavior unchanged). The model runs atreasoning_effort="low"withmax_tokens=1500, retried once through the now-publicinvoke_with_retry(the summarizer's_invoke_summarizer, same classification).[[id]]markers and a JSON picks list; the server parses it, drops any sentence holding a marker or a bare id-shaped token (\b[a-z]{2}\d{6}\b) outside the given ids, and any pick of one. Result text goes to the prompt as JSON inside<data>tags with<and>escaped, and never widens the allowed ids./ask's is (tierquick, model, key source, tokens, cost) andoverviewis in_COMMUNITY_SUFFIXES, socheck_budgetcounts it. A cache hit or a joined call logs zero tokens and zero cost; a call that produced no answer is still paid for.ROUTE_PATTERNS.communityOverviewandhandleOverview(rate limit only, no Turnstile, like feedback), tested intest-routing.js. The worker is deployed by hand (wrangler deploy, seeworkers/osa-worker/README.md): a maintainer must deploy it before the website can call the endpoint through it..context/api-structure.mdsection 5,docs/search-overview.md,CHANGELOG.md.Also changed:
tests/test_api/test_security.pylists/overviewamong the routes allowed to useverify_api_key(it spends the caller's credential on a model, like/ask).Closes #702
Commands run
uv sync --extra devuv run pytest tests/test_api/test_search_overview.py tests/test_api/test_overview_unit.py -v: 51 + 87 passeduv run pytest tests/test_api tests/test_metrics -q(alsotests/test_agents): all passed after rebasing onto develop (2325 with test_agents)tests/test_tools/test_hed_suggest.py::test_real_program_suggests_a_schema_tag, a real-network HED schema test unrelated to this change (every other test intests/test_toolspasses)uv run pytest tests/test_integration/test_search_overview_llm.py -m llm -v: skipped, there is noANTHROPIC_API_KEYin this environment (the skipif reason says so). The prompt and the JSON/marker contract have therefore not been run against the real model yet; the post-merge dev check below does that.uv run ruff check . && uv run ruff format --check .: cleanbun workers/osa-worker/test-routing.js(192 passed),bun workers/osa-worker/test-mounted-hosts.js(37 passed),node --check workers/osa-worker/index.jscurl -s 'https://api-test.nemar.org/datasets?limit=6': the source oftests/fixtures/overview_results.json(the sixxx0999NNrows)https://api.osc.earth/osa-dev/healthto carry the merged version, POST twice tohttps://api.osc.earth/osa-dev/nemar/overviewwith Originhttps://test.nemar.organd a stagingxx0999NNresult set, check cited ids andcached: trueon the second call, read therequest_logrow withdocker exec osa-dev python3): after merge, output to be pasted in Search overview endpoint on the quick model #702Notes for review
request_logandcheck_budget); the only stand-in is aScriptedChatModel. Deletingoverviewfrom_COMMUNITY_SUFFIXESmakes five budget tests fail.cached: trueand logs no cost.