Structs representing a successful TypeSafe API response.
A Response contains:
model— the model that performed the evaluationanswers— every answer keyed exactly as its question was suppliednouls,choices, andscores— typed convenience maps for each answer kindusage— token counts for the requestrequest_id— the TypeSafe request ID, when the API sent one
When questions are keyed by atoms, atom keys are restored after decoding JSON, so dot access is ergonomic and does not create atoms from API-controlled data:
response.answers.is_urgent.noul
response.choices.department.choice
response.scores.frustration.score
Summary
Functions
Parses a raw API response map (as decoded JSON) into a Response struct.
Parses a raw API response and restores keys from the supplied question map or struct.
Types
@type answer() :: ExTypesafe.Response.NoulAnswer.t() | ExTypesafe.Response.ChoiceAnswer.t() | ExTypesafe.Response.ScoreAnswer.t() | ExTypesafe.Response.UnknownAnswer.t()
A question key preserved from the caller's request.
@type t() :: %ExTypesafe.Response{ answers: %{optional(answer_key()) => answer()}, choices: %{optional(answer_key()) => ExTypesafe.Response.ChoiceAnswer.t()}, model: String.t() | nil, nouls: %{optional(answer_key()) => ExTypesafe.Response.NoulAnswer.t()}, request_id: String.t() | nil, scores: %{optional(answer_key()) => ExTypesafe.Response.ScoreAnswer.t()}, usage: ExTypesafe.Response.Usage.t() | nil }
Functions
Parses a raw API response map (as decoded JSON) into a Response struct.
Since no original question map is available, answer keys remain the string IDs returned by the
API. Use from_map/2 when atom keys should be restored.
Parses a raw API response and restores keys from the supplied question map or struct.
Struct containers are normalized without their __struct__ field and omit nil fields. Atom
question keys are reused rather than created from strings. String question keys remain strings.
The caller is responsible for ensuring that no atom and string key serialize to the same API key;
ExTypesafe.Client.evaluate/4 validates that invariant before making a request.