Struct 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

Source

pub fn new() -> ConversationManager

Build a new ConversationManager

§Example
use rust_bert::pipelines::conversation::ConversationManager;

let conversation_manager = ConversationManager::new();
Source

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 active UUID and Conversations
§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);
Source

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);
Source

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();
Source

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!");
Source

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();
Source

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);
Source

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);
Source

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();

Trait Implementations§

Source§

impl Debug for ConversationManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConversationManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T