Skip to content

✨ feat: Add the Classification Port - #561

Draft
danny-avila wants to merge 2 commits into
mainfrom
feat/classification-port
Draft

danny-avila wants to merge 2 commits into
mainfrom
feat/classification-port

Conversation

@danny-avila

Copy link
Copy Markdown
Collaborator

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

src/classification/
  types.ts        questions, answers, Classifier, ClassificationError, dialect + provider settings
  dialect.ts      boolean <-> noul; string criterion -> {true} pair; reads boolean/choice/score answers
  transport.ts    one deadline per call, bounded retries (429/5xx/network, retry-after <= 10 s), onAnswered hook
  http.ts         createHttpClassifier / parseEnvelope (requestKey / responseKey for hosts that nest)
  presets.ts      typesafe, openrouter, cloudflare, http; createClassifier(settings, apiKey, { fetch })
  questions.ts    booleanQuestion, choiceQuestion, scoreQuestion
  index.ts        exports (also re-exported from src/index.ts)
  classification.test.ts   7 tests, fake fetch

Differences from #16180: score questions 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; no librechat-data-provider or @librechat/data-schemas import (an onAnswered(label, ms) hook replaces the logger).

Checks run

  • npx jest src/classification — 7 passed
  • npx tsc --noEmit -p tsconfig.json — clean
  • node scripts/sort-imports.ts src/classification/*.ts — applied

Draft: publishing is a version bump; #16180 rebases onto the import afterwards, and codegraph's suppliers/classify/port.mjs becomes an import.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant