TypeSafeDecisionModel

class TypeSafeDecisionModel(client: HttpClient, apiKey: String, model: String = DEFAULT_MODEL, headers: Map<String, String> = emptyMap(), baseUrl: String = "https://api.typesafe.ai", timeout: Duration? = 1.minutes) : DecisionModel

A DecisionModel that calls Jev, the decision model of TypeSafe AI, through its System One API. Jev does not write text: it picks an option, answers yes or no, or rates on a scale, in a fraction of the time and the price of a chat model. It is built on Ktor, so it runs on every Kotlin target.

val client = HttpClient()
val jev = TypeSafeDecisionModel(client, apiKey = System.getenv("TYPESAFE_API_KEY"))

val answer = jev.choose(email.body, "Which team should handle this email?", mapOf("refund" to null, "technical" to null))

HttpClient() uses the Ktor engine among your dependencies. The client is yours: share one between models, and close it when your app is done with it. A call may take one minute, whatever limits the client and its engine have. Change the limit with timeout.

The API answers 429 or 529 when it has too much to do. This class does not try again by itself: install the HttpRequestRetry plugin of Ktor in client to retry those with a pause.

All questions of one request are answered together, so several questions about the same state cost one call. Question.YesNo is what TypeSafe calls a Noul.

Parameters

client

the Ktor client that sends the requests.

apiKey

the TypeSafe API key.

model

the id of the model. jev-latest moves to each new release; give a version such as jev-1.13.0 when you have set confidence limits for it.

headers

more headers for every request.

baseUrl

where the API lives. Change it to go through a proxy or a gateway.

timeout

how long one call may take. It replaces the limits of client and of its engine for the requests of this model. null leaves those limits in place.

Throws

Constructors

Link copied to clipboard
constructor(client: HttpClient, apiKey: String, model: String = DEFAULT_MODEL, headers: Map<String, String> = emptyMap(), baseUrl: String = "https://api.typesafe.ai", timeout: Duration? = 1.minutes)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun decide(request: DecisionRequest): DecisionResponse

Sends the questions of request to the System One API and returns Jev's answers.