Struct rust_bert::pipelines::conversation::ConversationManager
source · pub struct ConversationManager { /* private fields */ }
Expand description
Data structure allowing the management of conversations and main input to the dialogue model.
It contains a HashMap
of conversations with UUID
keys
Implementations§
source§impl ConversationManager
impl ConversationManager
sourcepub fn new() -> ConversationManager
pub fn new() -> ConversationManager
Build a new ConversationManager
Example
use rust_bert::pipelines::conversation::ConversationManager;
let conversation_manager = ConversationManager::new();
sourcepub fn get_active_conversations(
&mut self
) -> (Vec<&Uuid>, Vec<&mut Conversation>)
pub fn get_active_conversations( &mut self ) -> (Vec<&Uuid>, Vec<&mut Conversation>)
Returns a list of the active conversations (containing new inputs to be processed by the model)
Returns
(Vec<&Uuid>, Vec<&mut Conversation>)
Tuple of vectors with the activeUUID
andConversations
Example
use rust_bert::pipelines::conversation::{Conversation, ConversationManager};
let mut conversation_manager = ConversationManager::new();
let conversation = Conversation::new("Hi there!");
let empty_conversation = Conversation::new_empty();
let conversation_id = conversation_manager.add(conversation);
let empty_conversation_id = conversation_manager.add(empty_conversation);
let active_conversations = conversation_manager.get_active_conversations();
assert_eq!(active_conversations.0.len(), 1usize);
sourcepub fn get(&mut self, uuid: &Uuid) -> Option<&mut Conversation>
pub fn get(&mut self, uuid: &Uuid) -> Option<&mut Conversation>
Returns a mutable reference to the conversation wih the provided UUID
Arguments
uuid
-&Uuid
of the conversation to retrieve
Returns
Option<&mut Conversation>
Optional mutable reference to the conversation matching the UUID provided
Example
use rust_bert::pipelines::conversation::{Conversation, ConversationManager};
let mut conversation_manager = ConversationManager::new();
let conversation = Conversation::new("Hi there!");
let conversation_id = conversation_manager.add(conversation);
let conversation_ref = conversation_manager.get(&conversation_id);
sourcepub fn get_all(&mut self) -> HashMap<&Uuid, &Conversation>
pub fn get_all(&mut self) -> HashMap<&Uuid, &Conversation>
Returns a HashMap containing references to all conversations stored in the manager
Example
use rust_bert::pipelines::conversation::{Conversation, ConversationManager};
let mut conversation_manager = ConversationManager::new();
let conversation = Conversation::new("Hi there!");
let conversation_id = conversation_manager.add(conversation);
let all_conversations = conversation_manager.get_all();
sourcepub fn create(&mut self, text: &str) -> Uuid
pub fn create(&mut self, text: &str) -> Uuid
Creates a conversation and add it to the conversation manager
Arguments
text
-&str
string slice with an original user input
Returns
Uuid
for the conversation created
Example
use rust_bert::pipelines::conversation::{Conversation, ConversationManager};
let mut conversation_manager = ConversationManager::new();
let conversation_id = conversation_manager.create("Hi there!");
sourcepub fn create_empty(&mut self) -> Uuid
pub fn create_empty(&mut self) -> Uuid
Creates an empty conversation and add it to the conversation manager
Returns
Uuid
for the conversation created
Example
use rust_bert::pipelines::conversation::{Conversation, ConversationManager};
let mut conversation_manager = ConversationManager::new();
let conversation_id = conversation_manager.create_empty();
sourcepub fn add(&mut self, conversation: Conversation) -> Uuid
pub fn add(&mut self, conversation: Conversation) -> Uuid
Adds an existing conversation to the conversation manager
Arguments
conversation
-Conversation
to be added to the conversation manager
Returns
Uuid
for the conversation created
Example
use rust_bert::pipelines::conversation::{Conversation, ConversationManager};
let mut conversation_manager = ConversationManager::new();
let conversation = Conversation::new("Hi there!");
let conversation_id = conversation_manager.add(conversation);
sourcepub fn remove(&mut self, uuid: &Uuid) -> Option<Conversation>
pub fn remove(&mut self, uuid: &Uuid) -> Option<Conversation>
Deregister a conversation from the conversation manager
Arguments
uuid
-&Uuid
of the conversation to deregister from the conversation manager
Returns
Option<Conversation>
de-registered conversation
Example
use rust_bert::pipelines::conversation::{Conversation, ConversationManager};
let mut conversation_manager = ConversationManager::new();
let conversation_id = conversation_manager.create("Hi there!");
conversation_manager.remove(&conversation_id);
sourcepub fn clear(&mut self) -> HashMap<Uuid, Conversation>
pub fn clear(&mut self) -> HashMap<Uuid, Conversation>
Clear all conversations from the conversation manager, and returns the conversations and their former UUID.
Returns
HashMap<Uuid, Conversation>
de-registered conversations
Example
use rust_bert::pipelines::conversation::{Conversation, ConversationManager};
let mut conversation_manager = ConversationManager::new();
let conversation_id = conversation_manager.create("Hi there!");
let conversations = conversation_manager.clear();