pub trait Executor: Sized {
    type PerInvocationOptions: Options;
    type PerExecutorOptions: Options;
    type Output: Output;
    type Error: ExecutorError + Debug + Error;
    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,
        options: Option<&'life1 Self::PerInvocationOptions>,
        prompt: &'life2 Prompt,
        is_streaming: Option<bool>
    ) -> 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,
        options: Option<&Self::PerInvocationOptions>,
        prompt: &Prompt
    ) -> Result<TokenCount, PromptTokensError>;
    fn max_tokens_allowed(
        &self,
        options: Option<&Self::PerInvocationOptions>
    ) -> i32;
    fn answer_prefix(&self, prompt: &Prompt) -> Option<String>;
    fn get_tokenizer(
        &self,
        options: Option<&Self::PerInvocationOptions>
    ) -> Result<Self::StepTokenizer<'_>, TokenizerError>;
    fn get_text_splitter(
        &self,
        options: Option<&Self::PerInvocationOptions>
    ) -> Result<Self::TextSplitter<'_>, Self::Error>;

    // Provided method
    fn new() -> Result<Self, ExecutorCreationError> { ... }
}
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§

source

type PerInvocationOptions: Options

The per-invocation options type used by this executor. These are the options you can send to each step.

source

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.

source

type Output: Output

The output type produced by this executor.

source

type Error: ExecutorError + Debug + Error

The error type produced by this executor.

source

type Token: Clone

The token type used by this executor.

source

type StepTokenizer<'a>: Tokenizer<Self::Token> where Self: 'a

source

type TextSplitter<'a>: TextSplitter<Self::Token> where Self: 'a

Required Methods§

source

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.
source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, options: Option<&'life1 Self::PerInvocationOptions>, prompt: &'life2 Prompt, is_streaming: Option<bool> ) -> 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,

source

fn tokens_used( &self, options: Option<&Self::PerInvocationOptions>, prompt: &Prompt ) -> 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.

source

fn max_tokens_allowed( &self, options: Option<&Self::PerInvocationOptions> ) -> i32

Returns the maximum number of input tokens allowed by the model used.

Parameters
  • options: The per-invocation options that affect the token allowance.
Returns

The max token count for the step

source

fn answer_prefix(&self, prompt: &Prompt) -> Option<String>

Returns a possible answer prefix inserted by the model, during a certain prompt mode

Parameters
  • prompt: The prompt passed into step
Returns

A Option containing a String if prefix exists, or none if there is no prefix

source

fn get_tokenizer( &self, options: Option<&Self::PerInvocationOptions> ) -> 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.

source

fn get_text_splitter( &self, options: Option<&Self::PerInvocationOptions> ) -> Result<Self::TextSplitter<'_>, Self::Error>

Creates a text splitter, depending on the model used by ‘step’

Parameters
  • step The step to get an associated text splitter for.
Returns

A Result containing a text splitter, or an error if there was a problem.

Provided Methods§

Implementors§