pub struct ConversationModel { /* private fields */ }
Expand description
§Conversation model
Processes a ConversationManager and generate system responses for active conversations.
Implementations§
Source§impl ConversationModel
impl ConversationModel
Sourcepub fn new(
conversation_config: ConversationConfig,
) -> Result<ConversationModel, RustBertError>
pub fn new( conversation_config: ConversationConfig, ) -> Result<ConversationModel, RustBertError>
Build a new ConversationModel
§Arguments
conversation_config
-ConversationConfig
object containing the resource references (model, vocabulary, configuration), conversation options and device placement (CPU/GPU)
§Example
use rust_bert::pipelines::conversation::ConversationModel;
let conversation_model = ConversationModel::new(Default::default())?;
Sourcepub fn new_with_tokenizer(
conversation_config: ConversationConfig,
tokenizer: TokenizerOption,
) -> Result<ConversationModel, RustBertError>
pub fn new_with_tokenizer( conversation_config: ConversationConfig, tokenizer: TokenizerOption, ) -> Result<ConversationModel, RustBertError>
Build a new ConversationModel
with a provided tokenizer.
§Arguments
conversation_config
-ConversationConfig
object containing the resource references (model, vocabulary, configuration), conversation options and device placement (CPU/GPU)tokenizer
-TokenizerOption
tokenizer to use for conversation
§Example
use rust_bert::pipelines::common::{ModelType, TokenizerOption};
use rust_bert::pipelines::conversation::ConversationModel;
let tokenizer = TokenizerOption::from_file(
ModelType::GPT2,
"path/to/vocab.json",
Some("path/to/merges.txt"),
false,
None,
None,
)?;
let conversation_model = ConversationModel::new_with_tokenizer(Default::default(), tokenizer)?;
Sourcepub fn generate_responses<'a>(
&self,
conversation_manager: &'a mut ConversationManager,
) -> Result<HashMap<&'a Uuid, &'a str>, RustBertError>
pub fn generate_responses<'a>( &self, conversation_manager: &'a mut ConversationManager, ) -> Result<HashMap<&'a Uuid, &'a str>, RustBertError>
Perform a multi-turn conversation based on user input
§Arguments
conversation_manager
-&mut ConversationManager
Conversation manager keeping track of active conversations
§Returns
HashMap<&Uuid, &str>
Responses from the model for each active conversation, referenced by Uuid
§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();
conversation_manager.create("Hello, how are you?");
let output = model.generate_responses(&mut conversation_manager);
Sourcepub fn encode_prompts(&self, texts: &[&str]) -> Vec<Vec<i64>>
pub fn encode_prompts(&self, texts: &[&str]) -> Vec<Vec<i64>>
Encodes prompts into Vectors of indices to be processed by the model. This method may be used to initialize the history of a conversation with a prior state.
§Example:
use rust_bert::pipelines::conversation::{ConversationManager, ConversationModel};
use rust_bert::pipelines::generation_utils::LanguageGenerator;
let model = ConversationModel::new(Default::default())?;
let history = [
"Going to the movies tonight - any suggestions?",
"The Big Lebowski",
"Is it an action movie?",
];
let encoded_history = model.encode_prompts(&history);
Auto Trait Implementations§
impl !Freeze for ConversationModel
impl !RefUnwindSafe for ConversationModel
impl Send for ConversationModel
impl !Sync for ConversationModel
impl Unpin for ConversationModel
impl !UnwindSafe for ConversationModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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