#[non_exhaustive]pub struct SystemOneResponse {
pub model: String,
pub answers: IndexMap<String, Answer>,
pub usage: Usage,
pub request_id: Option<String>,
}Expand description
The response to a System One request.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.model: StringThe model that answered; may differ from the alias that was requested.
answers: IndexMap<String, Answer>Answers keyed by question id.
usage: UsageToken usage for the request.
request_id: Option<String>The x-typesafe-request-id header, when the response was received over HTTP.
Serialized only when present, so stored responses keep it.
Implementations§
Source§impl SystemOneResponse
impl SystemOneResponse
Sourcepub fn new(model: impl Into<String>, usage: Usage) -> Self
pub fn new(model: impl Into<String>, usage: Usage) -> Self
An empty response from model, for fixtures and tests. Add answers with
SystemOneResponse::with_answer.
use typesafe_client::{NoulAnswer, NoulQuestion, Questions, SystemOneResponse, Usage};
let mut questions = Questions::new();
let urgent = questions.add("is_urgent", NoulQuestion::new("Does this convey urgency?"));
let response = SystemOneResponse::new("jev-latest", Usage::new(312, 48))
.with_answer(&urgent, NoulAnswer::new(0.92));
assert_eq!(response.answer(&urgent)?.noul, 0.92);Sourcepub fn with_answer(self, id: impl AsRef<str>, answer: impl Into<Answer>) -> Self
pub fn with_answer(self, id: impl AsRef<str>, answer: impl Into<Answer>) -> Self
Adds or replaces the answer for question id (an id string or a QuestionKey).
Sourcepub fn with_request_id(self, request_id: impl Into<String>) -> Self
pub fn with_request_id(self, request_id: impl Into<String>) -> Self
Sets the request id, as a transport would from the response headers.
Sourcepub fn answer<A: ReadAnswer>(
&self,
key: &QuestionKey<A>,
) -> Result<A::Output<'_>, AnswerError>
pub fn answer<A: ReadAnswer>( &self, key: &QuestionKey<A>, ) -> Result<A::Output<'_>, AnswerError>
Reads the answer for key with the type its question promises.
Noul answers are copied, Choice and Score answers are borrowed, and typed choices are parsed into their Rust type.
use typesafe_client::{NoulQuestion, Questions, SystemOneResponse};
let mut questions = Questions::new();
let urgent = questions.add("is_urgent", NoulQuestion::new("Does this convey urgency?"));
let response: SystemOneResponse = serde_json::from_str(
r#"{"model":"jev-latest","answers":{"is_urgent":{"type":"noul","noul":0.92}},
"usage":{"input_tokens":312,"output_tokens":48}}"#,
)?;
assert_eq!(response.answer(&urgent)?.noul, 0.92);Sourcepub fn verify(&self, questions: &Questions) -> Result<(), AnswerError>
pub fn verify(&self, questions: &Questions) -> Result<(), AnswerError>
Checks that every question has an answer of its kind, naming only options and levels the question has. Transports run this before returning a response, so reading an answer can then only fail when a key belongs to a different request.
Trait Implementations§
Source§impl Clone for SystemOneResponse
impl Clone for SystemOneResponse
Source§fn clone(&self) -> SystemOneResponse
fn clone(&self) -> SystemOneResponse
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more