✨ feat: Add the Classification Port - #561
Draft
danny-avila wants to merge 2 commits into
Draft
danny-avila wants to merge 2 commits into
danny-avila wants to merge 2 commits into
Conversation
A typed question in, a calibrated answer out: `src/classification/` carries the port that
LibreChat PR #16180 introduced under `packages/api` and that codegraph mirrors in ESM, so the
product, the graph and any other consumer share one implementation of the contract a System One
host (TypeSafe's Jev, directly or through a gateway) answers.
- types: boolean / choice / score questions, answers with a probability or a calibrated
confidence and distribution, `Classifier`, `ClassificationError` with typed failures,
`ClassificationDialect`, `ClassificationProviderSettings`
- dialect: boolean ↔ `noul`; a string yes-criterion becomes the `{true}` pair a System One host wants
- transport: one deadline for the whole call, bounded retries on 429/5xx/network honouring
retry-after, an `onAnswered` hook instead of a logger dependency
- http: the host over HTTP, with request/response wrapping for hosts that nest the envelope
- presets: typesafe, openrouter, cloudflare, http; `createClassifier(settings, apiKey)`
- questions: `booleanQuestion`, `choiceQuestion`, `scoreQuestion`
- seven jest tests with a fake fetch; `tsc --noEmit` clean
No LibreChat type is imported: the SDK holds the port, consumers hold their configuration.
…assifier A host whose bearer expires (the ClickHouse inference gateway mints an hourly Okta token) can be given a function instead of a key. The transport calls it before each request and once more with refresh: true after a 401, then retries that request; a 403 is a scope refusal and is not retried. The `clickhouse` preset points at the gateway's System One route.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
src/classification/: the classification port — typed questions (boolean, choice, score) about a piece of content, answered by a classifier with a probability per answer — as an SDK module, so LibreChat (packages/api, PR LibreChat-AI/LibreChat#16180), codegraph and any other consumer import one implementation instead of carrying copies.Why
PR #16180 put the port in
packages/api; codegraph mirrored it in plain ESM to run on a dev box; both now answer through TypeSafe's Jev. The SDK is where the shared contract belongs: consumers keep their configuration (librechat.yaml, an env file), the SDK keeps the wire dialect, the transport and the presets.Shape
Differences from #16180:
scorequestions and answers (TypeSafe supports them; codegraph's issue severity uses them); boolean criteria accept a string for the yes side and normalise to the{true, false}pair; nolibrechat-data-provideror@librechat/data-schemasimport (anonAnswered(label, ms)hook replaces the logger).Checks run
npx jest src/classification— 7 passednpx tsc --noEmit -p tsconfig.json— cleannode scripts/sort-imports.ts src/classification/*.ts— appliedDraft: publishing is a version bump; #16180 rebases onto the import afterwards, and codegraph's
suppliers/classify/port.mjsbecomes an import.