SystemOneCodec

@ApiStatus.Experimental
object SystemOneCodec

Reads and writes the System One wire format, the JSON protocol for asking a decision model several typed questions about one piece of state in a single request.

A request is {"state", "model", "questions"}. Questions are keyed q1 to qN in spec order, replacing application question names in the JSON sent to the model endpoint. The input and question instructions are still sent. A proposition goes out as a noul question, a choice as a choice question with its options as criteria, and a rating as a score question with its level descriptions as an ordered criteria list.

A response is {"model", "answers", "usage"}. The envelope is read strictly: anything that is not one JSON object with a non-empty answers object, a repeated member, or trailing content throws SystemOneFormatException and fails the whole request. Each answer is then read on its own, so one bad answer fails only its question. Members this codec doesn't know are ignored, so a newer model can add fields. The evidence rules for each answer type are in SystemOneAnswers.

Properties

Link copied to clipboard

The path that answers a question set.

Link copied to clipboard
const val MODELS_PATH: String

The path that lists the models an endpoint serves.

Functions

Link copied to clipboard
fun decode(body: ByteArray, spec: DecisionSpec, serviceName: String, provenance: Function<String?, ModelProvenance>): DecisionResponse

Reads a response body into a decision response for the spec that was asked.

Link copied to clipboard

Writes the request body for one decision request with no model in it, for a host that names the model outside the System One request.

fun encode(model: String, request: DecisionRequest): ByteArray

Writes the request body for one decision request.

Link copied to clipboard

Reads the model names from a model listing. It reads the System One shape, {"models": [{"name", ...}]}, and the OpenAI shape that Ollama serves, {"data": [{"id", ...}]}.