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::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}