← Alle projekter

open source

jev-dotnet

En afhængighedsfri .NET-klient til Jev

Et uofficielt .NET 8-SDK til TypeSafe AI's Jev - typede Choice-, Score- og Noul-spørgsmål ind, typede svar med kalibreret confidence ud - bygget på intet andet end System.Net.Http og System.Text.Json.

Den fulde case er skrevet på engelsk.

Why

A chat LLM hands you a paragraph you have to parse. Jev hands you a value with a shape and a confidence you can threshold on, so you can run it on everything and escalate only the uncertain cases. This makes that pattern feel native in C#.

Highlights

  • Typed Choice, Score and Noul questions, all answered in one request
  • Retry with exponential backoff and jitter on 429/529, honouring Retry-After
  • A typed exception hierarchy under JevException, so callers can tell auth, validation and overload apart
  • An injectable HttpMessageHandler seam for offline tests; 18 xUnit tests behind a 90% line-coverage gate, warnings as errors
  • The Java sibling is jev-java
README.md - jev-dotnet▼

Jev.Client (.NET)

A small, dependency-free .NET client for TypeSafe AI's Jev, a "System One" model that returns typed judgments instead of free text. You send a piece of state and a set of typed questions; you get back typed answers with calibrated confidence, which your code can act on directly.

This is my own unofficial SDK, not published or endorsed by TypeSafe. It's built against the public API at https://api.typesafe.ai.

Why

A chat LLM hands you a paragraph you have to parse and second-guess. Jev hands you a value with a shape: an enum choice, a number on a scale, or a yes/no probability, each with a confidence you can threshold on. The idea is to run Jev on everything and only escalate the low-confidence cases to a person or a bigger model.

Install

Not yet published to NuGet (planned), so dotnet add package Jev.Client will not find it. Reference the project from source instead:

git clone https://github.com/CMaintz/jev-dotnet.git
dotnet add <YourProject>.csproj reference jev-dotnet/src/Jev.Client/Jev.Client.csproj

or build a local package with dotnet pack src/Jev.Client -c Release -o ./nupkg and add ./nupkg as a package source.

Targets net8.0. No runtime dependencies (built on System.Net.Http and System.Text.Json).

Quick start

using Jev;

using var client = JevClient.FromEnvironment(); // reads TYPESAFE_API_KEY

var questions = new Dictionary<string, Question>
{
    ["team"] = new Choice(
        "Which team should handle this ticket",
        new Dictionary<string, string>
        {
            ["billing"] = "Payment or subscription issues",
            ["technical"] = "Bugs or integration problems",
            ["sales"] = "Pricing or account questions",
        }),
    ["anger"] = new Score(
        "How frustrated the customer appears",
        ["Calm, just stating facts", "Frustrated but civil", "Very angry"]),
    ["refund"] = new Noul("Does the customer ask for a refund?"),
};

var response = await client.SystemOneAsync(
    new { subject = "Charged twice!", body = "I want my money back." },
    questions);

var team = response["team"];
if (team.IsConfident(0.7))
{
    Route(team.ChoiceValue!);          // "billing"
}
else
{
    EscalateToHuman();                 // distribution was spread out
}

double anger = response["anger"].ScoreValue ?? 0;   // e.g. 1.8
bool wantsRefund = response["refund"].NoulValue > 0.5;

The three questions above are answered in a single request. Independent questions are evaluated in parallel, so batching them is close to free.

The three primitives

Type Ask when Answer fields
Choice one of a defined set ChoiceValue, Probabilities (per option), Confidence
Score a position on an ordered scale ScoreValue, ScoreProbabilities (per level), Legend, Confidence
Noul a yes/no condition NoulValue (0..1); no confidence

Choice criteria is a map of option to description (max 255 options). Score criteria is an ordered list of 2 to 10 level descriptions, low to high. The model cannot pick an option you did not give it, so include a no-match option when nothing may fit.

Confidence

Choice and Score answers carry a Confidence in [0, 1] derived from how peaked the probability distribution is. Answer.IsConfident(threshold) is a convenience for gating. A Noul has no confidence; gate it on the probability itself (near 0.5 means genuinely uncertain, not "medium yes"). A confidence threshold is not one number: use a stricter bar for consequential actions than for harmless ones, and tune it on your data.

Errors

All failures derive from JevException, which carries StatusCode and ResponseBody:

Exception HTTP Meaning
JevAuthException 401 missing or invalid API key
JevValidationException 422 the request was rejected as malformed
JevRateLimitException 429 rate limited; retries exhausted
JevOverloadedException 529 service overloaded; retries exhausted

429 and 529 are retried automatically with exponential backoff (honoring Retry-After when present); MaxRetries is configurable.

Configuration

using var client = new JevClient(new JevClientOptions
{
    ApiKey = "sk-...",                            // or leave null to read TYPESAFE_API_KEY
    Model = "jev-latest",                         // tracks the recommended model
    Timeout = TimeSpan.FromSeconds(30),
    MaxRetries = 3,
    BaseUrl = new Uri("https://api.typesafe.ai"),   // e.g. a proxy; its path prefix is kept
    Handler = customHandler,                      // inject an HttpMessageHandler to test offline
});

Keep the API key server-side. JevClient is thread-safe: create one and reuse it.

Roadmap

  • Publish Jev.Client to NuGet.
  • Multi-target net8.0 plus netstandard2.0 for broader reach.
  • Optional streaming of large batches; response caching for repeated states.
  • A live end-to-end sample against a real key.

License

MIT. See LICENSE.

command.exeesc

↑↓ vælg · Tab udfyld · Enter kør · Esc luk

doom.exe

WASD move · ←→ turn · Space fire · E use · Shift run · Esc menu · click to capture mouse · licences