pub struct LlmUserSimulator { /* private fields */ }Expand description
A simulator that drives a user LLM with a persona + template. Each
respond call builds a CompletionRequest whose system prompt is
the rendered prompt_template (with {persona} and {task}
substituted) and whose user message is the serialized conversation
so far.
The simulator looks for a terminal sentinel — by default <end> —
in the LLM’s response to decide whether to return
UserAction::EndConversation. The sentinel is matched
case-insensitively and stripped from the surrounding text.
Implementations§
Source§impl LlmUserSimulator
impl LlmUserSimulator
Sourcepub fn default_template() -> &'static str
pub fn default_template() -> &'static str
A reasonable default template — users with opinionated simulators should supply their own.
pub fn new( llm: Arc<dyn Llm>, persona: impl Into<String>, prompt_template: impl Into<String>, ) -> Self
pub fn with_end_sentinel(self, sentinel: impl Into<String>) -> Self
pub fn with_name(self, name: impl Into<String>) -> Self
Trait Implementations§
Source§impl UserSimulator for LlmUserSimulator
impl UserSimulator for LlmUserSimulator
fn name(&self) -> &str
Source§fn initial_message<'life0, 'life1, 'async_trait>(
&'life0 self,
task: &'life1 Task,
) -> Pin<Box<dyn Future<Output = Result<String, UserError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn initial_message<'life0, 'life1, 'async_trait>(
&'life0 self,
task: &'life1 Task,
) -> Pin<Box<dyn Future<Output = Result<String, UserError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Produce the first user message from the task. Called once at the
start of a conversation loop.
Source§fn respond<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
conversation: ConversationView<'life1>,
task: &'life2 Task,
) -> Pin<Box<dyn Future<Output = Result<UserAction, UserError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn respond<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
conversation: ConversationView<'life1>,
task: &'life2 Task,
) -> Pin<Box<dyn Future<Output = Result<UserAction, UserError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Respond to the current conversation. Return
UserAction::Say with the next user message, or
UserAction::EndConversation to terminate the loop.Auto Trait Implementations§
impl Freeze for LlmUserSimulator
impl !RefUnwindSafe for LlmUserSimulator
impl Send for LlmUserSimulator
impl Sync for LlmUserSimulator
impl Unpin for LlmUserSimulator
impl UnsafeUnpin for LlmUserSimulator
impl !UnwindSafe for LlmUserSimulator
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