pub struct RefineDocumentsChain<M: BaseChatModel> { /* private fields */ }Expand description
RefineDocumentsChain
Iteratively refines the answer document by document. Generates an initial answer from the first document, then refines with each subsequent document.
Implementations§
Source§impl<M: BaseChatModel> RefineDocumentsChain<M>
impl<M: BaseChatModel> RefineDocumentsChain<M>
pub fn new(llm: M) -> Self
pub fn with_initial_prompt(self, template: impl Into<String>) -> Self
pub fn with_refine_prompt(self, template: impl Into<String>) -> Self
pub fn with_document_variable(self, name: impl Into<String>) -> Self
pub fn with_input_key(self, key: impl Into<String>) -> Self
pub fn with_output_key(self, key: impl Into<String>) -> Self
pub fn with_name(self, name: impl Into<String>) -> Self
pub fn with_verbose(self, verbose: bool) -> Self
pub fn build_initial_prompt(&self, context: &str, input: &str) -> String
pub fn build_refine_prompt( &self, context: &str, input: &str, existing_answer: &str, ) -> String
Trait Implementations§
Source§impl<M: BaseChatModel + Send + Sync + 'static> BaseChain for RefineDocumentsChain<M>
impl<M: BaseChatModel + Send + Sync + 'static> BaseChain for RefineDocumentsChain<M>
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 RefineDocumentsChain.
Runs the initial + all intermediate refine steps via invoke (since
their output feeds the next step), then streams the final refine step
token by token via stream_chat.
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<M> Freeze for RefineDocumentsChain<M>where
M: Freeze,
impl<M> RefUnwindSafe for RefineDocumentsChain<M>where
M: RefUnwindSafe,
impl<M> Send for RefineDocumentsChain<M>
impl<M> Sync for RefineDocumentsChain<M>
impl<M> Unpin for RefineDocumentsChain<M>where
M: Unpin,
impl<M> UnsafeUnpin for RefineDocumentsChain<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for RefineDocumentsChain<M>where
M: UnwindSafe,
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