Struct rust_bert::pipelines::conversation::Conversation [−][src]
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<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<(), RustBertError>[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]
Returns the last response generated by the system.
Returns
Option<&str>representation of the last response generated by the system.
Example
use rust_bert::pipelines::conversation::Conversation; let mut conversation = Conversation::new("Hi There"); let non_value = conversation.get_last_response();
pub fn load_from_history<ST, SI, STR, SIN>(&mut self, texts: ST, ids: SI) where
ST: AsRef<[STR]>,
SI: AsRef<[SIN]>,
STR: AsRef<str>,
SIN: AsRef<[i64]>, [src]
ST: AsRef<[STR]>,
SI: AsRef<[SIN]>,
STR: AsRef<str>,
SIN: AsRef<[i64]>,
Initializes a conversation form a prior state. It is assumed that a conversation always start from a user interaction.
Arguments
- texts: sequence of strings, alternating between past user inputs and past generated responses.
- ids: sequence of sequence of ids, alternating between past user inputs and past generated responses.
These can be generated via a
ConversationModel'sencode_prompts.
Example:
use rust_bert::pipelines::conversation::{ConversationManager, ConversationModel}; use rust_bert::pipelines::generation_utils::LanguageGenerator; let model = ConversationModel::new(Default::default())?; let mut conversation_manager = ConversationManager::new(); let history = [ "Going to the movies tonight - any suggestions?", "The Big Lebowski", "Is it an action movie?", ]; let encoded_history = model.encode_prompts(&history); let conversation_1_id = conversation_manager.create_empty(); let _ = conversation_manager .get(&conversation_1_id) .unwrap() .load_from_history(history, encoded_history);
Trait Implementations
impl Clone for Conversation[src]
fn clone(&self) -> Conversation[src]
pub 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,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T> Instrument for T[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>[src]
pub fn in_current_span(self) -> Instrumented<Self>[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub 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.
pub 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.
pub 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>,