-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathqa_chain.rs
34 lines (30 loc) · 905 Bytes
/
qa_chain.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use langchain_rust::{
chain::{Chain, StuffDocumentBuilder},
llm::openai::OpenAI,
prompt_args,
schemas::Document,
};
#[tokio::main]
async fn main() {
let llm = OpenAI::default();
let chain = StuffDocumentBuilder::new()
.llm(llm)
// .prompt() you can add a custom prompt if you want
.build()
.unwrap();
let input = prompt_args! {
"input_documents"=>vec![
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"
};
let output = chain.invoke(input).await.unwrap();
println!("{}", output);
}