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 invoke_with_config<'life0, 'async_trait>(
        &'life0 self,
        inputs: HashMap<String, Value>,
        config: Option<RunnableConfig>,
    ) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    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 stream_with_config<'life0, 'async_trait>(
        &'life0 self,
        inputs: HashMap<String, Value>,
        config: Option<RunnableConfig>,
    ) -> 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 invoke_with_config<'life0, 'async_trait>( &'life0 self, inputs: HashMap<String, Value>, config: Option<RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the Chain with a RunnableConfig.

This method propagates callbacks through the chain execution. The default implementation delegates to invoke() without config, so chains that don’t need callback support work automatically.

Chains that want to propagate callbacks (on_chain_start/end, on_llm_start/end) should override this method.

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 stream_with_config<'life0, 'async_trait>( &'life0 self, inputs: HashMap<String, Value>, config: Option<RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stream execute the Chain with a RunnableConfig.

The default implementation delegates to stream() without config.

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§