07_inspect_history/
07-inspect-history.rs

1/*
2Script to inspect the history of an LM.
3
4Run with:
5```
6cargo run --example 07-inspect-history
7```
8*/
9
10use 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::default();
32    configure(lm, ChatAdapter);
33
34    let example = example! {
35        "question": "input" => "What is the capital of France?",
36    };
37
38    let qa_rater = QARater::builder().build();
39    let prediction = qa_rater.forward(example.clone()).await.unwrap();
40    println!("Prediction: {prediction:?}");
41
42    let history = get_lm().inspect_history(1).await;
43    println!("History: {history:?}");
44}