Struct langchain_rust::chain::StuffDocument
source · pub struct StuffDocument { /* private fields */ }
Implementations§
source§impl StuffDocument
impl StuffDocument
pub fn new(llm_chain: LLMChain) -> Self
pub fn qa_prompt_builder<'a>(&self) -> StuffQAPromptBuilder<'a>
sourcepub fn load_stuff_qa<L: LLM + 'static>(llm: L) -> Self
pub fn load_stuff_qa<L: LLM + 'static>(llm: L) -> Self
load_stuff_qa return an instance of StuffDocument with a prompt desiged for question ansering
§Example
ⓘ
let llm = OpenAI::default();
let chain = StuffDocument::load_stuff_qa(llm);
let input = chain
.qa_prompt_builder()
.documents(&[
Document::new(format!(
"\nQuestion: {}\nAnswer: {}\n",
"Which is the favorite text editor of luis", "Nvim"
)),
Document::new(format!(
"\nQuestion: {}\nAnswer: {}\n",
"How old is Luis", "24"
)),
])
.question("How old is luis and whats his favorite text editor")
.build();
let ouput = chain.invoke(input).await.unwrap();
println!("{}", ouput);
sourcepub fn load_stuff_qa_with_options<L: LLM + 'static>(
llm: L,
opt: ChainCallOptions
) -> Self
pub fn load_stuff_qa_with_options<L: LLM + 'static>( llm: L, opt: ChainCallOptions ) -> Self
load_stuff_qa_with_options return an instance of StuffDocument with a prompt desiged for question ansering
§Example
ⓘ
let llm = OpenAI::default();
let chain = StuffDocument::load_stuff_qa_with_options(llm,ChainCallOptions::default());
let input = chain
.qa_prompt_builder()
.documents(&[
Document::new(format!(
"\nQuestion: {}\nAnswer: {}\n",
"Which is the favorite text editor of luis", "Nvim"
)),
Document::new(format!(
"\nQuestion: {}\nAnswer: {}\n",
"How old is Luis", "24"
)),
])
.question("How old is luis and whats his favorite text editor")
.build();
let ouput = chain.invoke(input).await.unwrap();
println!("{}", ouput);
Trait Implementations§
source§impl Chain for StuffDocument
impl Chain for StuffDocument
source§fn call<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs
) -> Pin<Box<dyn Future<Output = Result<GenerateResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn call<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs
) -> Pin<Box<dyn Future<Output = Result<GenerateResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Call the
Chain
and receive as output the result of the generation process along with
additional information like token consumption. The input is a set of variables passed
as a PromptArgs
hashmap. Read moresource§fn stream<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamData, ChainError>> + Send>>, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamData, ChainError>> + Send>>, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream the
Chain
and get an asynchronous stream of chain generations.
The input is a set of variables passed as a PromptArgs
hashmap.
If the chain have memroy, the tream method will not be able to automaticaly
set the memroy, bocause it will not know if the how to extract the output message
out of the stram Read morefn get_input_keys(&self) -> Vec<String>
source§fn invoke<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs
) -> Pin<Box<dyn Future<Output = Result<String, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs
) -> Pin<Box<dyn Future<Output = Result<String, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Invoke the
Chain
and receive just the generation result as a String.
The input is a set of variables passed as a PromptArgs
hashmap. Read moresource§fn execute<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
input_variables: PromptArgs
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute the
Chain
and return the result of the generation process
along with additional information like token consumption formatted as a HashMap
.
The input is a set of variables passed as a PromptArgs
hashmap.
The key for the generated output is specified by the get_output_keys
method (default key is output
). Read morefn get_output_keys(&self) -> Vec<String>
Auto Trait Implementations§
impl Freeze for StuffDocument
impl !RefUnwindSafe for StuffDocument
impl Send for StuffDocument
impl Sync for StuffDocument
impl Unpin for StuffDocument
impl !UnwindSafe for StuffDocument
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