07_inspect_history/
07-inspect-history.rs1use anyhow::Result;
11use bon::Builder;
12use dspy_rs::{
13 ChatAdapter, Example, LM, Module, Predict, Prediction, Predictor, configure, example, get_lm,
14 sign,
15};
16
17#[derive(Builder)]
18pub struct QARater {
19 #[builder(default = Predict::new(sign! { (question: String) -> answer: String }))]
20 pub answerer: Predict,
21}
22
23impl Module for QARater {
24 async fn forward(&self, inputs: Example) -> Result<Prediction> {
25 return self.answerer.forward(inputs.clone()).await;
26 }
27}
28
29#[tokio::main]
30async fn main() {
31 let lm = LM::builder()
32 .model("openai:gpt-4o-mini".to_string())
33 .build()
34 .await
35 .unwrap();
36 configure(lm, ChatAdapter);
37
38 let example = example! {
39 "question": "input" => "What is the capital of France?",
40 };
41
42 let qa_rater = QARater::builder().build();
43 let prediction = qa_rater.forward(example.clone()).await.unwrap();
44 println!("Prediction: {prediction:?}");
45
46 let history = get_lm().inspect_history(1).await;
47 println!("History: {history:?}");
48}