Struct rust_bert::pipelines::conversation::Conversation[][src]

pub struct Conversation {
    pub past_user_inputs: Vec<String>,
    pub generated_responses: Vec<String>,
    pub new_user_input: Option<String>,
    pub history: Vec<Vec<i64>>,
}

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 - String with 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 - &str with 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 - &str with 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

  • bool flag 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]

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's encode_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]

impl Debug for Conversation[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,