Skip to content

Commit 424e33f

Browse files
committed
fix: rust interpreter was not handling pdl__context for re-runs of traces
This only covers the run_model code path, but it's a start. Signed-off-by: Nick Mitchell <[email protected]>
1 parent 3e313a6 commit 424e33f

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

pdl-live-react/src-tauri/src/pdl/interpreter.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,22 @@ impl<'a> Interpreter<'a> {
931931
// The input messages to the model is either:
932932
// a) block.input, if given
933933
// b) the current state's accumulated messages
934+
if let Some(c) = &block.context {
935+
state.scope.insert(
936+
"pdl_context".to_string(),
937+
PdlResult::List(
938+
c.iter()
939+
.map(|m| {
940+
PdlResult::Block(PdlBlock::Advanced(Block {
941+
metadata: None,
942+
body: Body::Message(m.clone()),
943+
}))
944+
})
945+
.collect(),
946+
),
947+
);
948+
}
949+
934950
let input_messages = match &block.input {
935951
Some(input) => {
936952
// TODO ignoring result and trace
@@ -1027,7 +1043,23 @@ impl<'a> Interpreter<'a> {
10271043
true,
10281044
)?;
10291045
trace.data = from_str(to_string(&result)?.as_str())?;
1030-
Ok((result, vec![], Data(trace)))
1046+
let messages = match &trace.data {
1047+
Value::Object(m) => match m.get("pdl__result") {
1048+
Some(Value::Array(a)) => a
1049+
.iter()
1050+
.filter_map(|m| match m {
1051+
Value::Object(d) => match d.get("content") {
1052+
Some(Value::String(s)) => Some(ChatMessage::user(s.clone())),
1053+
_ => None,
1054+
},
1055+
_ => None,
1056+
})
1057+
.collect(),
1058+
_ => vec![],
1059+
},
1060+
_ => vec![],
1061+
};
1062+
Ok((result, messages, Data(trace)))
10311063
}
10321064
}
10331065

0 commit comments

Comments
 (0)