pub trait Executor: Sized {
type PerInvocationOptions: Options;
type PerExecutorOptions: Options;
type Output: Output;
type Error: ExecutorError + Debug + Error + From<StepError>;
type Token: Clone;
type StepTokenizer<'a>: Tokenizer<Self::Token>
where Self: 'a;
type TextSplitter<'a>: TextSplitter<Self::Token>
where Self: 'a;
// Required methods
fn new_with_options(
executor_options: Option<Self::PerExecutorOptions>,
invocation_options: Option<Self::PerInvocationOptions>
) -> Result<Self, ExecutorCreationError>;
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
step: &'life1 Step<Self>,
parameters: &'life2 Parameters
) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn tokens_used(
&self,
step: &Step<Self>,
parameters: &Parameters
) -> Result<TokenCount, PromptTokensError>;
fn max_tokens_allowed(&self, step: &Step<Self>) -> i32;
fn get_tokenizer(
&self,
step: &Step<Self>
) -> Result<Self::StepTokenizer<'_>, TokenizerError>;
fn get_text_splitter(
&self,
step: &Step<Self>
) -> Result<Self::TextSplitter<'_>, Self::Error>;
// Provided methods
fn new() -> Result<Self, ExecutorCreationError> { ... }
fn new_with_default() -> Self { ... }
}Expand description
The Executor trait represents an executor that performs a single step in a chain. It takes a
step, executes it, and returns the output.
Required Associated Types§
sourcetype PerInvocationOptions: Options
type PerInvocationOptions: Options
The per-invocation options type used by this executor. These are the options you can send to each step.
sourcetype PerExecutorOptions: Options
type PerExecutorOptions: Options
The per-executor options type used by this executor. These are the options you can send to the executor and can’t be set per step.
sourcetype Error: ExecutorError + Debug + Error + From<StepError>
type Error: ExecutorError + Debug + Error + From<StepError>
The error type produced by this executor.
type StepTokenizer<'a>: Tokenizer<Self::Token> where Self: 'a
type TextSplitter<'a>: TextSplitter<Self::Token> where Self: 'a
Required Methods§
sourcefn new_with_options(
executor_options: Option<Self::PerExecutorOptions>,
invocation_options: Option<Self::PerInvocationOptions>
) -> Result<Self, ExecutorCreationError>
fn new_with_options( executor_options: Option<Self::PerExecutorOptions>, invocation_options: Option<Self::PerInvocationOptions> ) -> Result<Self, ExecutorCreationError>
Create a new executor with the given executor options and invocation options. If you don’t need to set any options, you can use the new method instead.
Parameters
executor_options: The options to set for the executor.invocation_options: The default options to set for each invocation.
sourcefn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
step: &'life1 Step<Self>,
parameters: &'life2 Parameters
) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, step: &'life1 Step<Self>, parameters: &'life2 Parameters ) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,
Executes the given input and returns the resulting output.
Parameters
input: The input value to execute, that is the output of the step.
Returns
The output produced by the executor.
sourcefn tokens_used(
&self,
step: &Step<Self>,
parameters: &Parameters
) -> Result<TokenCount, PromptTokensError>
fn tokens_used( &self, step: &Step<Self>, parameters: &Parameters ) -> Result<TokenCount, PromptTokensError>
Calculates the number of tokens used by the step given a set of parameters.
The step and the parameters together are used to form full prompt, which is then tokenized and the token count is returned.
Parameters
step: The step to calculate token usage for.parameters: The parameters to plug into the step.
Returns
A Result containing the token count, or an error if there was a problem.
sourcefn max_tokens_allowed(&self, step: &Step<Self>) -> i32
fn max_tokens_allowed(&self, step: &Step<Self>) -> i32
Returns the maximum number of input tokens allowed by the model used in step.
Parameters
step: The step to get token allowance for.
Returns
The max token count for the step
sourcefn get_tokenizer(
&self,
step: &Step<Self>
) -> Result<Self::StepTokenizer<'_>, TokenizerError>
fn get_tokenizer( &self, step: &Step<Self> ) -> Result<Self::StepTokenizer<'_>, TokenizerError>
Creates a tokenizer, depending on the model used by step.
Parameters
step: The step to get an associated tokenizer for.
Returns
A Result containing a tokenizer, or an error if there was a problem.
sourcefn get_text_splitter(
&self,
step: &Step<Self>
) -> Result<Self::TextSplitter<'_>, Self::Error>
fn get_text_splitter( &self, step: &Step<Self> ) -> Result<Self::TextSplitter<'_>, Self::Error>
Creates a text splitter, depending on the model used by ‘step’
Parameters
stepThe step to get an associated text splitter for.
Returns
A Result containing a text splitter, or an error if there was a problem.