Repository navigation
feat: one typed detect interface for the detectors package (#126) - #204
Conversation
Add tests/golden.py (assert_golden, UPDATE_GOLDEN=1 to rewrite, readable unified diff, floats rounded to 6 places) and record predict, predict_prompt and predict_prompt_batch in "tokens" and "spans" format on a stub model with the local tokenizer, plus a multi-group context and spans typed by a stub typer. Recorded as-is: "tokens" output ends with the trailing [SEP], and the multi-group path flags a token at prob >= 0.5 while the single-group path uses argmax. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Record predict, predict_prompt and predict_prompt_batch in "tokens" and "spans" format through a fake LLMClient: the judge with defaults, zero_shot, include_reasoning, each include_taxonomy form (True, list, flat dict, nested dict), verify, and native mode with and without include_reasoning. Also record today's behaviour in the cases the epic changes (llm_defect_*): a reply without hallucination_list, an unparseable reply, an item that is not found in the answer, and spans without confidence. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…130) Record "tokens", "spans" and "detailed" output of predict, predict_prompt and predict_prompt_batch through a fake fact checker, a triplet matched only by the single-word fallback (confidence 0.7), and the merge defect where a merged span's text is shorter than its offsets (rag_merge_overlap_text_shorter_than_offsets_*, for the fix PR to update). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ior (#131) Record the class make_detector returns for "transformer", "llm" and "rag_fact_checker" and the error for an unknown method; assert and record that HallucinationDetector.predict, predict_prompt and predict_prompt_batch return what the detector alone returns (transformer, LLM, RAG); and pin the CacheManager file after set/delete calls, the _hash strings, and the judge, native and verify keys LLMDetector writes for fixed prompts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…-todays-detector-api test: record golden fixtures for today's detector API (#127)
…ixtures-for-todays-detector-api Revert "test: record golden fixtures for today's detector API (#127)"
Add tests/golden.py (assert_golden, UPDATE_GOLDEN=1 to rewrite, readable unified diff, floats rounded to 6 places) and record predict, predict_prompt and predict_prompt_batch in "tokens" and "spans" format on a stub model with the local tokenizer, plus a multi-group context and spans typed by a stub typer. Recorded as-is: "tokens" output ends with the trailing [SEP], and the multi-group path flags a token at prob >= 0.5 while the single-group path uses argmax. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Record predict, predict_prompt and predict_prompt_batch in "tokens" and "spans" format through a fake LLMClient: the judge with defaults, zero_shot, include_reasoning, each include_taxonomy form (True, list, flat dict, nested dict), verify, and native mode with and without include_reasoning. Also record today's behaviour in the cases the epic changes (llm_defect_*): a reply without hallucination_list, an unparseable reply, an item that is not found in the answer, and spans without confidence. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…130) Record "tokens", "spans" and "detailed" output of predict, predict_prompt and predict_prompt_batch through a fake fact checker, a triplet matched only by the single-word fallback (confidence 0.7), and the merge defect where a merged span's text is shorter than its offsets (rag_merge_overlap_text_shorter_than_offsets_*, for the fix PR to update). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ior (#131) Record the class make_detector returns for "transformer", "llm" and "rag_fact_checker" and the error for an unknown method; assert and record that HallucinationDetector.predict, predict_prompt and predict_prompt_batch return what the detector alone returns (transformer, LLM, RAG); and pin the CacheManager file after set/delete calls, the _hash strings, and the judge, native and verify keys LLMDetector writes for fixed prompts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…convention-in-contributingmd' into 140-implement-a-detector-against-detect-and-check-it-with-a-contract-suite
…or-every-deprecated-name' into 140-implement-a-detector-against-detect-and-check-it-with-a-contract-suite
…rors' into 140-implement-a-detector-against-detect-and-check-it-with-a-contract-suite
test: record golden fixtures for today's detector API (#127)
…g-convention-in-contributingmd (docs): add the error handling and logging convention to CONTRIBUTING.md (#133)
…-for-every-deprecated-name See one consistent warning for every deprecated name (#134)
…-typed-results-and-errors
…read-typed-results-and-errors Build detect requests and read typed result warning (#137)
…etect-and-check-it-with-a-contract-suite
…st-detect-and-check-it-with-a-contract-suite Implement a detector against detect and check it with a contract suite (#140)
feat: run many requests with detect_batch and adetect_batch (#175)
…angelog's deprecation notes (#181)
…ted and head the 0.3.0 roadmap section Next (#179)
docs: changelog, roadmap and contributor guide for the typed detector interface (#179)
Conflicts: CHANGELOG.md keeps both entries; llm.py and rag_fact_checker.py keep the typed length check of this branch. The fact checker batch tests from main mock the single-call method the batch path now uses, and the short-backend-result test is dropped because the batch path makes one call per pair.
chore: merge main into stateless_core
|
Thanks for pulling the epic together. The per-ticket PRs made this much easier to follow, and the core design holds up well: typed requests and results, constructors that take loaded objects, stable error codes, and the contract suite. For this review I focused on the new typed core: What I checked and found right:
There are two items I'd like fixed before merge, then a list of smaller ones. Must fix1. One failing request can still abort the whole
|
…o the model's language
…and keep span offsets in the answer A fact checker that raises now gives UpstreamError, so detect_batch reports that request as failed and returns the others. A result that is no dict, or whose hallucinated triplets are not lists of strings, raises UpstreamError(invalid_model_output). Case-insensitive matches are located in the answer itself, so offsets stay right after characters whose lowercase form is longer. With a custom fact checker, usage.model_id is the checker's model or None.
… request error, ignore invalid Retry-After, close only an owned client
…ading and locking - An answer that does not fit in max_length raises InvalidInputError (input_too_long) for its own request; in detect_batch the other requests are still scored. - NaN scores and spans or token scores that fail validation raise UpstreamError (invalid_model_output). - EncoderDetector and TaxonomyTyper can be pickled and deep-copied after use. - A TaxonomyTyper takes the scoring lock of its tokenizer, shared with detectors built on it. - detect_batch works with a tokenizer that has no pad token (one forward pass per request). - from_pretrained reports a missing or unreadable local model folder as ConfigurationError. - TaxonomyTyper.from_pretrained takes max_length. - The typer test stub returns tensors on the device of its input.
…udge replies OpenAIClient and BedrockClient raise typed errors for every provider failure, so one failed request no longer aborts detect_batch. A reply without content raises empty_response. OpenAI 429s carry retry_after from the header. A confidence outside [0, 1] is clamped, and the judge parser strips code fences with the helper the generative parser uses.
…into 204-review-fixes
fix: isolate request failures in detect_batch and complete the load_detector registry
|
Thanks for the review, this was very useful. Everything in it is addressed in #205, which is merged into Must fix
Should fix and smaller items: all done as you suggested, with these details:
Where the result differs from your notes
Two things I left alone: context-length errors from OpenAI stay A re-review would be welcome whenever you have time. |
The integration branch of epic #126: one typed interface for the detectors package. Every ticket of the epic was merged into
stateless_corethrough its own pull request; this one brings the branch intomainfor a single review.What it adds
detect,adetect,detect_batchandadetect_batchon every detector. They take aSourcesInputor aPromptInputand return aDetectionwith spans, scores, optional tokens and detail,usageandwarnings. A batch returns oneBatchResultper request, so one failed request does not discard the others.EncoderDetector,LLMJudgeDetector,GenerativeDetector,RAGFactCheckerDetectorandVelaDetector(in process and over HTTP). They take loaded models or clients as arguments; construction reads no environment variable and writes no file.load_detector(model_id, ...)with a registry of the KR Labs model ids.InvalidInputError,ConfigurationError,UpstreamError) with stable codes, caller-controlled reply caching (ResponseCache,FileCache,InMemoryCache), and frozen pydantic request, result and config types.tests/detector_contract.py) that every detector passes.What happens to the existing API
TransformerDetector,LLMDetector,make_detector,CacheManager,TaxonomyTyper(model_path, ...)and thepredict*methods keep working as adapters over the new classes. Used from outside the package they warn withLettuceDetectDeprecationWarning.HallucinationDetectoris not deprecated and does not warn.Some behaviour changes through the existing API.
CHANGELOG.mdlists each one under "Changed" with what happened before and what happens now. The ones most likely to affect callers:UpstreamErrorinstead of returning no spans;LLMDetectorwrites a cache file only whencache_fileis passed;confidencenow carryconfidence: 1.0;LLMDetectorareConfigurationError, which is not aValueError.Where to look
The per-ticket pull requests have the detail and the readings taken where the tickets left room: #184 to #191 (golden fixtures, the error and logging convention, the deprecation helper, types, the contract suite, the cache, the encoder), #193 and #194 (Vela), #195 (fixes from #192), #196 (fact checker), #197 (LLM judge), #198 (generative), #199 (
LLMDetectoradapter), #200 (load_detector), #201 (batch, and thepredictoverride bridge), #202 (changelog, thepredict*warnings).Points that deserve a reviewer's attention:
predictoverride bridge inbase.py(feat: run many requests with detect_batch and adetect_batch (#175) #201) were open decisions in the epic and were taken on this branch.TransformerDetector.predict_prompt_batchkeeps its own padded path instead of callingdetect_batch(feat: run many requests with detect_batch and adetect_batch (#175) #201 explains why).BaseDetector.max_concurrencydefaults to 1, soVelaDetectorbatches run one request at a time.detect" is tested with stub models, not with a real model.LLMDetectorandRAGFactCheckerDetectorhas no replacement on the new interface.Testing
The test and lint workflows ran on every pull request into the branch. The suite has about 1,400 tests and needs no network and no API key.
Rights & sign-off (required)
distributed under the repository's MIT license
(see CONTRIBUTING).