-
Notifications
You must be signed in to change notification settings - Fork 1
Evaluating text and using results
After you have a return object, pass the text to EvaluateAsync<T>(). The generic type T is the class JevDotNet will create and fill. If you have not made a call yet, follow Getting started first.
string apiKey = Environment.GetEnvironmentVariable("JEV_API_KEY")
?? throw new InvalidOperationException("Set JEV_API_KEY first.");
JevClient client = new(apiKey);
JevResponse<SupportAssessment> response =
await client.EvaluateAsync<SupportAssessment>(message);
SupportAssessment result = response.Result;Here SupportAssessment and message are defined in Getting started. Each attributed property becomes a separate question about the same input text. A successful call returns a new result object; it does not modify the input text or an existing instance.
The optional second argument is a CancellationToken:
using CancellationTokenSource timeout = new(TimeSpan.FromSeconds(30));
JevResponse<SupportAssessment> response =
await client.EvaluateAsync<SupportAssessment>(message, timeout.Token);Choose a timeout appropriate to your application. The example assumes the client, message, and SupportAssessment from the first walkthrough.
JevResponse<T> contains:
| Member | Meaning |
|---|---|
Result |
Your populated return object. |
InputTokenCount |
Input tokens reported by the API. |
OutputTokenCount |
Output tokens reported by the API. |
For the simple properties in the first walkthrough:
Category? category = response.Result.Category;
double? severity = response.Result.Severity;
bool? isBroken = response.Result.IsBroken;
long inputTokens = response.InputTokenCount;
long outputTokens = response.OutputTokenCount;Use nullable properties when a result object may also exist before evaluation. After a successful evaluation JevDotNet sets every attributed property, provided the API supplied valid answers. Unattributed properties retain their constructor or initializer values.
The simple shapes above discard supporting fields. Change a property to its detailed type when your application needs confidence, the distribution over options or levels, or the raw Noul probability:
public sealed class DetailedSupportAssessment
{
[JevChoiceQuestion<Category>("What is the primary category?")]
public JevChoice<Category>? Category { get; set; }
[JevScoreQuestion<Severity>("How severe is the reported issue?")]
public JevScore<Severity>? Severity { get; set; }
[JevNoulQuestion("Is the product broken or unavailable?")]
public JevNoul? IsBroken { get; set; }
}Then evaluate that class and inspect the fields you need:
JevResponse<DetailedSupportAssessment> detailedResponse =
await client.EvaluateAsync<DetailedSupportAssessment>(message);
Category? selected = detailedResponse.Result.Category?.Choice;
double? categoryConfidence = detailedResponse.Result.Category?.Confidence;
double? technicalProbability =
detailedResponse.Result.Category?.Probabilities[Category.Technical];
double? numericSeverity = detailedResponse.Result.Severity?.Score;
double? blockingProbability =
detailedResponse.Result.Severity?.Probabilities[Severity.Blocking];
double? brokenProbability = detailedResponse.Result.IsBroken?.Probability;
bool? aboveSeventyPercent = detailedResponse.Result.IsBroken?.IsAtLeast(0.7);These snippets use the enums and client from Getting started. A Choice's Confidence summarizes how concentrated its option probabilities are; a Score's Confidence does the same for its level probabilities. Noul has only the yes-probability, without a separate confidence field. See the Choice, Score, and Noul pages for each record's full behavior.
The string constructor uses the default model jev-latest and endpoint https://api.typesafe.ai/v1/systemone. For a different model, endpoint, or caller-owned HttpClient, use JevClientOptions:
HttpClient httpClient = new();
JevClient client = new(new JevClientOptions
{
ApiKey = apiKey,
Model = "jev-latest",
Endpoint = new Uri("https://api.typesafe.ai/v1/systemone"),
HttpClientFactory = () => httpClient
});Keep and dispose the supplied HttpClient according to your application's lifetime. In a long-lived application, reuse it rather than creating one per request. Supply the API key from a secret source.
- Invalid return-object shapes throw before the HTTP request. The exception names the property and links to the relevant wiki guide.
- A non-success API response raises
HttpRequestExceptionwith the HTTP status. Check the API key, model, and endpoint. - A missing or incompatible answer raises
JsonExceptionwith the question ID or response field. Compare the shape in the linked type guide.
See Troubleshooting return objects for specific fixes.