pub struct Session {
pub state: Value,
pub questions: Vec<Entry>,
pub model: Option<String>,
}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.
Implementations§
Source§impl Session
impl Session
pub fn new() -> Self
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