pub struct LengthBasedExampleSelector { /* private fields */ }Expand description
Selects examples in order until they would no longer fit in max_length, counting
the length of the input too. Useful to keep a prompt within the context window.
Length is measured in words by default (see with_length_fn).
ⓘ
let selector = LengthBasedExampleSelector::new(
template_fstring!("Input: {input}\nOutput: {output}", "input", "output"),
vec![prompt_args! {"input" => "happy", "output" => "sad"}],
)?
.with_max_length(25);Implementations§
Source§impl LengthBasedExampleSelector
impl LengthBasedExampleSelector
Sourcepub const DEFAULT_MAX_LENGTH: usize = 2048
pub const DEFAULT_MAX_LENGTH: usize = 2048
Default max_length, in words.
Sourcepub fn new(
example_prompt: PromptTemplate,
examples: Vec<PromptArgs>,
) -> Result<Self, PromptError>
pub fn new( example_prompt: PromptTemplate, examples: Vec<PromptArgs>, ) -> Result<Self, PromptError>
A selector over examples, formatted with example_prompt to measure them.
Fails if an example is missing a variable of example_prompt.
Sourcepub fn with_max_length(self, max_length: usize) -> Self
pub fn with_max_length(self, max_length: usize) -> Self
The most the selected examples plus the input may add up to.
Trait Implementations§
Source§impl Debug for LengthBasedExampleSelector
impl Debug for LengthBasedExampleSelector
Source§impl ExampleSelector for LengthBasedExampleSelector
impl ExampleSelector for LengthBasedExampleSelector
Source§fn add_example<'life0, 'async_trait>(
&'life0 self,
example: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn add_example<'life0, 'async_trait>(
&'life0 self,
example: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Adds an example to the pool the selector chooses from.
Source§fn select_examples<'life0, 'life1, 'async_trait>(
&'life0 self,
input_variables: &'life1 PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<Vec<PromptArgs>, PromptError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn select_examples<'life0, 'life1, 'async_trait>(
&'life0 self,
input_variables: &'life1 PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<Vec<PromptArgs>, PromptError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
The examples to use for
input_variables (the prompt’s inputs), in the order
they should appear.Auto Trait Implementations§
impl !Freeze for LengthBasedExampleSelector
impl !RefUnwindSafe for LengthBasedExampleSelector
impl !UnwindSafe for LengthBasedExampleSelector
impl Send for LengthBasedExampleSelector
impl Sync for LengthBasedExampleSelector
impl Unpin for LengthBasedExampleSelector
impl UnsafeUnpin for LengthBasedExampleSelector
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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