pub struct Session {
pub state: Value,
pub questions: Vec<Entry>,
pub model: Option<String>,
pub bars: Vec<(String, f64)>,
}Expand description
Everything the next :ask will send.
Fields§
§state: ValueThe text or JSON the model reasons about.
questions: Vec<Entry>Named questions, in insertion order.
model: Option<String>Per-session model override; None means the client default.
bars: Vec<(String, f64)>Each question’s decision bar, by name: a noul’s threshold, or the confidence a choice or a score has to reach before it is acted on. It lives on the page and never goes on the wire — it is what the caller does with the answer, not part of the question.
Implementations§
Source§impl Session
impl Session
pub fn new() -> Self
Sourcepub fn bar(&self, name: &str) -> Option<f64>
pub fn bar(&self, name: &str) -> Option<f64>
The bar written for a question, if the page gives it one.
Sourcepub fn set_bar(&mut self, name: &str, bar: f64)
pub fn set_bar(&mut self, name: &str, bar: f64)
Write down a question’s bar, replacing the one it had.
Sourcepub fn threshold_of(&self, name: &str, fallback: f64) -> f64
pub fn threshold_of(&self, name: &str, fallback: f64) -> f64
The threshold a noul is read at: its own @threshold when the page has one, fallback — the
session-wide :threshold or --threshold — when it does not. The question’s own bar wins
because it is the more specific of the two: someone wrote it down for this question.
pub fn state_is_empty(&self) -> bool
Sourcepub fn state_preview(&self) -> String
pub fn state_preview(&self) -> String
One-line preview of the state for the side panel.
Sourcepub fn turns(&self) -> Option<Vec<Turn>>
pub fn turns(&self) -> Option<Vec<Turn>>
The state read as a conversation, or None when it is something else.
Sourcepub fn add_turn(&mut self, turn: Turn) -> Result<Vec<Turn>, String>
pub fn add_turn(&mut self, turn: Turn) -> Result<Vec<Turn>, String>
Append a turn to the state.
An empty state starts a thread and a thread grows by one. A state that is plain text becomes the first turn, because that is how a session usually begins — one message, then the reply to it. Any other JSON is refused rather than reshaped: whatever it is, it is not a conversation, and guessing at one would lose it.
Sourcepub fn drop_turn(&mut self) -> Option<Turn>
pub fn drop_turn(&mut self) -> Option<Turn>
Take the last turn back. The last one of all leaves the state empty again.
Sourcepub fn insert(&mut self, name: String, question: Question) -> bool
pub fn insert(&mut self, name: String, question: Question) -> bool
Add a question, or replace one of the same name in place.
pub fn remove(&mut self, name: &str) -> bool
pub fn to_questions(&self) -> Questions
Sourcepub fn request_json(&self, model: &str) -> String
pub fn request_json(&self, model: &str) -> String
The exact JSON body the SDK will POST to /v1/systemone.
Serialized through a struct (not a Value) so field and question order survive, which is
the whole point of showing it.
Sourcepub fn request_json_compact(&self, model: &str) -> String
pub fn request_json_compact(&self, model: &str) -> String
The same body Session::request_json shows, with the whitespace taken out: what a cache
key hashes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
impl UnwindSafe for Session
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more