pub trait Executor {
type Step: Step;
type Output: Output;
type Error: ExecutorError + Debug + Error + From<<Self::Step as Step>::Error>;
type Token;
// Required methods
fn execute<'life0, 'async_trait>(
&'life0 self,
input: <<Self as Executor>::Step as Step>::Output
) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn tokens_used(
&self,
step: &Self::Step,
parameters: &Parameters
) -> Result<TokenCount, PromptTokensError>;
fn tokenize_str(
&self,
step: &Self::Step,
doc: &str
) -> Result<Vec<Self::Token>, PromptTokensError>;
fn to_string(
&self,
step: &Self::Step,
tokens: &[Self::Token]
) -> Result<String, PromptTokensError>;
}
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§
Required Methods§
sourcefn execute<'life0, 'async_trait>(
&'life0 self,
input: <<Self as Executor>::Step as Step>::Output
) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>( &'life0 self, input: <<Self as Executor>::Step as Step>::Output ) -> Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: '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: &Self::Step,
parameters: &Parameters
) -> Result<TokenCount, PromptTokensError>
fn tokens_used( &self, step: &Self::Step, 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 tokenize_str(
&self,
step: &Self::Step,
doc: &str
) -> Result<Vec<Self::Token>, PromptTokensError>
fn tokenize_str( &self, step: &Self::Step, doc: &str ) -> Result<Vec<Self::Token>, PromptTokensError>
Tokenizes a string based on the step.
Parameters
step
: The step used for tokenization.doc
: The string to tokenize.
Returns
A Result
containing a vector of tokens, or an error if there was a problem.
sourcefn to_string(
&self,
step: &Self::Step,
tokens: &[Self::Token]
) -> Result<String, PromptTokensError>
fn to_string( &self, step: &Self::Step, tokens: &[Self::Token] ) -> Result<String, PromptTokensError>
Converts a slice of tokens into a string based on the step.
Parameters
step
: The step used for conversion.tokens
: The slice of tokens to convert.
Returns
A Result
containing a string, or an error if there was a problem.