Skip to main content

BaseChain

Trait BaseChain 

Source
pub trait BaseChain: Send + Sync {
    // Required methods
    fn input_keys(&self) -> Vec<&str>;
    fn output_keys(&self) -> Vec<&str>;
    fn invoke<'life0, 'async_trait>(
        &'life0 self,
        inputs: HashMap<String, Value>,
    ) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn stream<'life0, 'async_trait>(
        &'life0 self,
        inputs: HashMap<String, Value>,
    ) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn validate_inputs(
        &self,
        inputs: &HashMap<String, Value>,
    ) -> Result<(), ChainError> { ... }
    fn name(&self) -> &str { ... }
}
Expand description

Base Chain trait.

Chain is LangChain’s core abstraction, representing a sequence of operations.

Required Methods§

Source

fn input_keys(&self) -> Vec<&str>

Get input keys.

Source

fn output_keys(&self) -> Vec<&str>

Get output keys.

Source

fn invoke<'life0, 'async_trait>( &'life0 self, inputs: HashMap<String, Value>, ) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the Chain.

§Arguments
  • inputs - Input parameter dictionary
§Returns

Output result dictionary

Provided Methods§

Source

fn stream<'life0, 'async_trait>( &'life0 self, inputs: HashMap<String, Value>, ) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stream execute the Chain – token by token output.

Default implementation wraps the invoke result as a single-element stream. Chains that support LLM streaming (LLMChain / ConversationChain) should override this method, calling BaseChatModel::stream_chat internally.

§Arguments
  • inputs - Input parameter dictionary
§Returns

Token stream

Source

fn validate_inputs( &self, inputs: &HashMap<String, Value>, ) -> Result<(), ChainError>

Validate inputs.

Source

fn name(&self) -> &str

Get Chain name.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§