[−][src]Struct rust_bert::pipelines::conversation::Conversation
Data structure keeping track of a conversation in the system. It contains past user inputs and generated answers, a history of the tokens generated and a placeholder for new user inputs to be processed by the system if submitted for prediction
Fields
past_user_inputs: Vec<String>Past user inputs that have already been processed
generated_responses: Vec<String>Past system generated responses
new_user_input: Option<String>New user input that needs to be processed
history: Vec<i64>History of the tokens passed as an input and generated so far used as context for next turn generation
Implementations
impl Conversation[src]
pub fn new(text: &str) -> Conversation[src]
Build a new Conversation with an initial user input
Arguments
text-Stringwith the initial user input to start a conversation
Example
use rust_bert::pipelines::conversation::Conversation; let conversation = Conversation::new("Hi there!");
pub fn new_empty() -> Conversation[src]
Build a new Conversation placeholder without user input
Example
use rust_bert::pipelines::conversation::Conversation; let conversation = Conversation::new_empty();
pub fn add_user_input(&mut self, text: &str) -> Result<(), &'static str>[src]
Adds a new user input to the conversation. This method returns an error if an unprocessed user input already exists
Arguments
text-&strwith the additional user input to continue a conversation
Example
use rust_bert::pipelines::conversation::Conversation; let mut conversation = Conversation::new_empty(); conversation.add_user_input("Hi there!");
pub fn add_user_input_with_overwrite(&mut self, text: &str) -> Option<String>[src]
Adds a new user input to the conversation. If an unprocessed user input already exists, its contents are overwritten by the new value provided.
Arguments
text-&strwith the additional user input to continue a conversation
Returns
Option<String>containing overwritten string if applicable
Example
use rust_bert::pipelines::conversation::Conversation; let mut conversation = Conversation::new_empty(); conversation.add_user_input("This input will not be used"); let unused_string = conversation.add_user_input_with_overwrite("Hi there!");
pub fn contains_new_input(&self) -> bool[src]
Returns true if the conversation contains new user inputs to process
Returns
boolflag indicating if the conversation contains new inputs to process
Example
use rust_bert::pipelines::conversation::Conversation; let mut conversation = Conversation::new_empty(); let false_value = conversation.contains_new_input(); conversation.add_user_input("This input will not be used"); let true_value = conversation.contains_new_input();
pub fn mark_processed(&mut self)[src]
Marks the conversation as processed and moves the user input that was up for processing to the past user inputs.
Example
use rust_bert::pipelines::conversation::Conversation; let mut conversation = Conversation::new_empty(); let false_value = conversation.contains_new_input(); conversation.add_user_input("This input will not be used"); let true_value = conversation.contains_new_input(); conversation.mark_processed(); let false_value = conversation.contains_new_input(); assert_eq!(conversation.past_user_inputs.len(), 1usize);
pub fn get_last_input(&self) -> Option<&str>[src]
Returns the last user input provided (including non-processed inputs).
Returns
Option<&str>representation of the last user input provided
Example
use rust_bert::pipelines::conversation::Conversation; let mut conversation = Conversation::new_empty(); let none_value = conversation.get_last_input(); conversation.add_user_input("This input will not be used"); let last_provided_input = conversation.get_last_input(); assert_eq!(last_provided_input, Some("This input will not be used"));
pub fn get_last_response(&self) -> Option<&str>[src]
Trait Implementations
impl Clone for Conversation[src]
fn clone(&self) -> Conversation[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Debug for Conversation[src]
Auto Trait Implementations
impl RefUnwindSafe for Conversation
impl Send for Conversation
impl Sync for Conversation
impl Unpin for Conversation
impl UnwindSafe for Conversation
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,