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§
Sourcefn input_keys(&self) -> Vec<&str>
fn input_keys(&self) -> Vec<&str>
Get input keys.
Sourcefn output_keys(&self) -> Vec<&str>
fn output_keys(&self) -> Vec<&str>
Get output keys.
Provided Methods§
Sourcefn 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<'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
Sourcefn validate_inputs(
&self,
inputs: &HashMap<String, Value>,
) -> Result<(), ChainError>
fn validate_inputs( &self, inputs: &HashMap<String, Value>, ) -> Result<(), ChainError>
Validate inputs.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".