forked from sobelio/llm-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchain-from-json.rs
27 lines (24 loc) · 938 Bytes
/
chain-from-json.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
use llm_chain::chains::sequential::Chain;
use llm_chain::serialization::StorableEntity;
use llm_chain::step::Step;
use llm_chain::traits::Executor as ExecutorTrait;
use llm_chain::{parameters, prompt};
use llm_chain_openai::chatgpt::Executor;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let chatgpt = Executor::new()?;
let mut path = std::env::temp_dir();
path.push("chain-from-yaml.yaml");
let path = path.to_str().unwrap();
let chain_to_write: Chain = Step::for_prompt_template(prompt!(
"You are a bot for making personalized greetings",
"Make a personalized greet for Joe"
))
.to_chain();
chain_to_write.write_file_sync(path)?;
println!("Wrote chain to {}", path);
let chain = Chain::read_file_sync(path).unwrap();
let res = chain.run(parameters!(), &chatgpt).await.unwrap();
println!("{}", res);
Ok(())
}