intelligence/jev

A type-safe implementation of evaluating questions using the Jev mode from typesafe.ai.

Types

pub type Client(t) {
  Client(
    origin: origin.Origin,
    token: String,
    model: String,
    fetch: fn(request.Request(BitArray)) -> fn(
      fn(Result(response.Response(BitArray), effect.FetchError)) -> t,
    ) -> t,
  )
}

Constructors

pub type Evaluation(t) {
  Evaluation(model: String, answer: t, usage: Usage)
}

Constructors

  • Evaluation(model: String, answer: t, usage: Usage)
pub type Failure {
  Unauthenticated(message: String)
  BadRequest(message: String)
  TooManyTokens
  InvalidRequest(problems: List(Problem))
  RateLimited(retry_after: option.Option(Int))
  Overloaded(retry_after: option.Option(Int))
  UnexpectedResponse(status: Int, body: BitArray)
  UnableToDecode(reason: json.DecodeError)
  UnableToFetch(reason: effect.FetchError)
}

Constructors

  • Unauthenticated(message: String)
  • BadRequest(message: String)
  • TooManyTokens
  • InvalidRequest(problems: List(Problem))
  • RateLimited(retry_after: option.Option(Int))
  • Overloaded(retry_after: option.Option(Int))
  • UnexpectedResponse(status: Int, body: BitArray)
  • UnableToDecode(reason: json.DecodeError)
  • UnableToFetch(reason: effect.FetchError)
pub type Model {
  Model(name: String, description: String, release_date: String)
}

Constructors

  • Model(name: String, description: String, release_date: String)
pub type Problem {
  Problem(location: List(String), message: String)
}

Constructors

  • Problem(location: List(String), message: String)
pub type Question {
  Noul(
    instructions: json.Json,
    true_criteria: option.Option(json.Json),
    false_criteria: option.Option(json.Json),
  )
  Choice(
    instructions: json.Json,
    options: List(#(String, json.Json)),
  )
  Score(instructions: json.Json, levels: List(json.Json))
}

Constructors

pub type Usage {
  Usage(input_tokens: Int, output_tokens: Int)
}

Constructors

  • Usage(input_tokens: Int, output_tokens: Int)

Values

pub fn and(
  question: #(Question, decode.Decoder(a), a),
  then: fn(a) -> #(List(#(String, Question)), decode.Decoder(t)),
) -> #(List(#(String, Question)), decode.Decoder(t))

Add a question to a bundle. The callback runs both to collect questions (using a placeholder answer) and to decode answers. Keep the remaining questions independent of earlier answers; all are sent in one request.

pub fn choice(
  instructions: String,
  options: List(#(String, #(a, json.Json))),
  zero: a,
) -> #(
  Question,
  decode.Decoder(#(a, dict.Dict(a, Float), Float)),
  #(a, dict.Dict(b, c), Float),
)
pub fn evaluate(
  client: Client(t),
  state: String,
  bundle: #(List(#(String, Question)), decode.Decoder(a)),
) -> fn(fn(Result(Evaluation(a), Failure)) -> t) -> t

Evaluate all questions against the same state with POST /v1/systemone. The bundle determines the type of Evaluation.answer.

pub fn list_models(
  client: Client(t),
) -> fn(fn(Result(List(Model), Failure)) -> t) -> t

Discover available models with GET /v1/models using the same fetch effect.

pub fn noul(
  instructions: String,
  true: option.Option(String),
  false: option.Option(String),
) -> #(Question, decode.Decoder(Float), Float)

Ask the model is something is true or false returning a float between 0 and 1

pub fn option(
  label: String,
  value: a,
  rubric: String,
) -> #(String, #(a, json.Json))

Associate an API label with an application value and a description.

pub fn return(
  x: t,
) -> #(List(#(String, Question)), decode.Decoder(t))

Finish a bundle with the value to return as Evaluation.answer.

pub fn score(
  instructions: String,
  levels: List(String),
) -> #(
  Question,
  decode.Decoder(
    #(
      Float,
      dict.Dict(String, String),
      dict.Dict(String, Float),
      Float,
    ),
  ),
  #(Float, dict.Dict(a, b), dict.Dict(c, d), Float),
)

Returns #(score, legend, probabilities, confidence). Supply 2–10 levels ordered lowest to highest. Legend and probability keys are index strings.

✨ Search Document