pub struct StuffDocumentsChain { /* private fields */ }Expand description
StuffDocumentsChain
Stuffs all documents into a single prompt for LLM processing. Suitable when the total document content fits within the LLM context window.
Implementations§
Source§impl StuffDocumentsChain
impl StuffDocumentsChain
Sourcepub fn new<L>(llm: L) -> Self
pub fn new<L>(llm: L) -> Self
Create a new StuffDocumentsChain with the given LLM.
Sourcepub fn with_prompt_template(self, template: impl Into<String>) -> Self
pub fn with_prompt_template(self, template: impl Into<String>) -> Self
Set the prompt template.
Sourcepub fn with_document_variable(self, name: impl Into<String>) -> Self
pub fn with_document_variable(self, name: impl Into<String>) -> Self
Set the document variable name used in the prompt.
Sourcepub fn with_input_key(self, key: impl Into<String>) -> Self
pub fn with_input_key(self, key: impl Into<String>) -> Self
Set the input key.
Sourcepub fn with_output_key(self, key: impl Into<String>) -> Self
pub fn with_output_key(self, key: impl Into<String>) -> Self
Set the output key.
Sourcepub fn with_verbose(self, verbose: bool) -> Self
pub fn with_verbose(self, verbose: bool) -> Self
Set verbose mode.
Sourcepub fn with_max_doc_length(self, max: usize) -> Self
pub fn with_max_doc_length(self, max: usize) -> Self
Set the maximum character count per document (documents are truncated if exceeded).
Sourcepub fn format_documents(&self, documents: &[Document]) -> String
pub fn format_documents(&self, documents: &[Document]) -> String
Format document list into context text.
Sourcepub fn build_prompt(&self, context: &str, input: &str) -> String
pub fn build_prompt(&self, context: &str, input: &str) -> String
Build prompt.
Sourcepub async fn invoke_with_documents(
&self,
documents: Vec<Document>,
input: &str,
) -> Result<String, ChainError>
pub async fn invoke_with_documents( &self, documents: Vec<Document>, input: &str, ) -> Result<String, ChainError>
Invoke with documents and input directly.
Trait Implementations§
Source§impl BaseChain for StuffDocumentsChain
impl BaseChain for StuffDocumentsChain
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,
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 execution for StuffDocumentsChain — token by token output.
Stuffs all documents into a single prompt, then streams the LLM response token by token.
Source§fn input_keys(&self) -> Vec<&str>
fn input_keys(&self) -> Vec<&str>
Get input keys.
Source§fn output_keys(&self) -> Vec<&str>
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,
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. Read more
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,
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. Read more
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,
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. Read more
Source§fn validate_inputs(
&self,
inputs: &HashMap<String, Value>,
) -> Result<(), ChainError>
fn validate_inputs( &self, inputs: &HashMap<String, Value>, ) -> Result<(), ChainError>
Validate inputs.
Auto Trait Implementations§
impl !RefUnwindSafe for StuffDocumentsChain
impl !UnwindSafe for StuffDocumentsChain
impl Freeze for StuffDocumentsChain
impl Send for StuffDocumentsChain
impl Sync for StuffDocumentsChain
impl Unpin for StuffDocumentsChain
impl UnsafeUnpin for StuffDocumentsChain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more