pub struct WasmSession { /* private fields */ }Expand description
Interactive Akinator-style HS classification session.
§Typical flow
const session = new WasmSession(); // English
// const session = WasmSession.new_ja(); // Japanese
const q1 = session.start();
// q1 = { step: "Identifier", prompt: "...", type: "text", choices: null, ... }
const r1 = session.answer(JSON.stringify({ Text: "64-19-7" }));
// r1 = { type: "NeedMoreInfo", next_question: { step: "IsMixture", ... } }
// … repeat until r.type === "Ready" …
const prediction = session.classify();
// { hs_code: "291511", confidence: 0.95, ... }Implementations§
Source§impl WasmSession
impl WasmSession
Sourcepub fn new() -> WasmSession
pub fn new() -> WasmSession
Create a new session with English prompts.
Sourcepub fn new_ja() -> WasmSession
pub fn new_ja() -> WasmSession
Create a new session with Japanese prompts.
Sourcepub fn start(&mut self) -> JsValue
pub fn start(&mut self) -> JsValue
Start the session and return the first Question as a JS object.
§JS return shape
{
"step": "Identifier",
"prompt": "Please enter a CAS number, IUPAC name, SMILES, or InChIKey",
"type": "text",
"choices": null,
"number_range": null
}Sourcepub fn answer(&mut self, answer_json: &str) -> Result<JsValue, JsValue>
pub fn answer(&mut self, answer_json: &str) -> Result<JsValue, JsValue>
Submit an answer and advance the session.
answer_json must be the JSON representation of an Answer variant:
JSON.stringify({ Text: "1310-73-2" })— free-text answerJSON.stringify({ YesNo: true })— yes/no answerJSON.stringify({ Choice: 0 })— single-choice indexJSON.stringify({ MultiChoice: [0, 2] })— multi-choice indicesJSON.stringify({ Number: 30.5 })— numeric answer
§JS return shape
{ "type": "NeedMoreInfo", "next_question": { "step": "...", ... } }
{ "type": "Ready" }
{ "type": "RequiresLlm" }Trait Implementations§
Source§impl From<WasmSession> for JsValue
impl From<WasmSession> for JsValue
Source§fn from(value: WasmSession) -> Self
fn from(value: WasmSession) -> Self
Converts to this type from the input type.
Source§impl FromWasmAbi for WasmSession
impl FromWasmAbi for WasmSession
Source§impl IntoWasmAbi for WasmSession
impl IntoWasmAbi for WasmSession
Source§impl LongRefFromWasmAbi for WasmSession
impl LongRefFromWasmAbi for WasmSession
Source§type Abi = WasmPtr<WasmRefCell<WasmSession>>
type Abi = WasmPtr<WasmRefCell<WasmSession>>
Same as
RefFromWasmAbi::AbiSource§type Anchor = RcRef<WasmSession>
type Anchor = RcRef<WasmSession>
Same as
RefFromWasmAbi::AnchorSource§unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
Same as
RefFromWasmAbi::ref_from_abiSource§impl OptionFromWasmAbi for WasmSession
impl OptionFromWasmAbi for WasmSession
Source§impl OptionIntoWasmAbi for WasmSession
impl OptionIntoWasmAbi for WasmSession
Source§impl RefFromWasmAbi for WasmSession
impl RefFromWasmAbi for WasmSession
Source§type Abi = WasmPtr<WasmRefCell<WasmSession>>
type Abi = WasmPtr<WasmRefCell<WasmSession>>
The Wasm ABI type references to
Self are recovered from.Source§type Anchor = RcRef<WasmSession>
type Anchor = RcRef<WasmSession>
The type that holds the reference to
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for WasmSession
impl RefMutFromWasmAbi for WasmSession
Source§type Abi = WasmPtr<WasmRefCell<WasmSession>>
type Abi = WasmPtr<WasmRefCell<WasmSession>>
Same as
RefFromWasmAbi::AbiSource§type Anchor = RcRefMut<WasmSession>
type Anchor = RcRefMut<WasmSession>
Same as
RefFromWasmAbi::AnchorSource§unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
Same as
RefFromWasmAbi::ref_from_abiSource§impl TryFromJsValue for WasmSession
impl TryFromJsValue for WasmSession
Source§impl VectorFromWasmAbi for WasmSession
impl VectorFromWasmAbi for WasmSession
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[WasmSession]>
Source§impl VectorIntoWasmAbi for WasmSession
impl VectorIntoWasmAbi for WasmSession
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[WasmSession]>) -> Self::Abi
Source§impl WasmDescribeVector for WasmSession
impl WasmDescribeVector for WasmSession
impl SupportsConstructor for WasmSession
impl SupportsInstanceProperty for WasmSession
impl SupportsStaticProperty for WasmSession
Auto Trait Implementations§
impl Freeze for WasmSession
impl RefUnwindSafe for WasmSession
impl Send for WasmSession
impl Sync for WasmSession
impl Unpin for WasmSession
impl UnsafeUnpin for WasmSession
impl UnwindSafe for WasmSession
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
Mutably borrows from an owned value. Read more
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
Same as
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
Same as
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.