Skip to content

Commit e9b02f6

Browse files
committed
fix: populate trace context field in rust interpreter
Signed-off-by: Nick Mitchell <[email protected]>
1 parent 1bf9482 commit e9b02f6

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,19 @@ pub struct ModelBlock {
285285
#[serde(skip_serializing_if = "Option::is_none")]
286286
pub platform: Option<String>,
287287
#[serde(skip_serializing_if = "Option::is_none")]
288-
pub context: Option<Vec<MessageBlock>>,
289-
#[serde(skip_serializing_if = "Option::is_none")]
290288
#[serde(rename = "modelResponse")]
291289
pub model_response: Option<String>,
292290
#[serde(rename = "pdl__usage")]
293291
#[serde(skip_serializing_if = "Option::is_none")]
294292
pub pdl_usage: Option<PdlUsage>,
293+
294+
/// The result of evaluating the `input` field (if given)
295295
#[serde(rename = "pdl__model_input", skip_serializing_if = "Option::is_none")]
296296
pub pdl_model_input: Option<Vec<MessageBlock>>,
297+
298+
/// The actual input given to the model (whether via `input` or from the incoming messages)
299+
#[serde(skip_serializing_if = "Option::is_none")]
300+
pub context: Option<Vec<MessageBlock>>,
297301
}
298302

299303
#[derive(Serialize, Deserialize, Debug, Clone)]

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -827,12 +827,14 @@ impl<'a> Interpreter<'a> {
827827
eprintln!("Model tools {:?} {:?}", metadata.description, tools);
828828
}
829829

830+
let mut trace = block.clone();
831+
830832
// The input messages to the model is either:
831833
// a) block.input, if given
832834
// b) the current state's accumulated messages
833835
let input_messages = match &block.input {
834836
Some(input) => {
835-
// TODO ignoring result, trace
837+
// TODO ignoring result and trace
836838
let (_result, messages, _trace) = self.run_quiet(&*input, state).await?;
837839
messages
838840
}
@@ -917,13 +919,28 @@ impl<'a> Interpreter<'a> {
917919
}
918920
}
919921

920-
let mut trace = block.clone();
922+
// TODO, does this belong in run_advanced(), and does
923+
// trace.context belong in Metadata rather than ModelBlock
924+
trace.context = Some(
925+
state
926+
.messages
927+
.iter()
928+
.map(|m| MessageBlock {
929+
role: self.from_ollama_role(&m.role),
930+
content: Box::new(PdlBlock::String(m.content.clone())),
931+
name: None,
932+
tool_call_id: None,
933+
defsite: None,
934+
})
935+
.collect(),
936+
);
937+
// TODO, what is the difference between context and pdl_model_input fields?
921938
trace.pdl_model_input = Some(
922939
input_messages
923-
.into_iter()
940+
.iter()
924941
.map(|m| MessageBlock {
925-
role: self.from_ollama_role(m.role),
926-
content: Box::new(PdlBlock::String(m.content)),
942+
role: self.from_ollama_role(&m.role),
943+
content: Box::new(PdlBlock::String(m.content.clone())),
927944
name: None,
928945
tool_call_id: None,
929946
defsite: None,
@@ -1090,7 +1107,7 @@ impl<'a> Interpreter<'a> {
10901107
}
10911108
}
10921109

1093-
fn from_ollama_role(&self, role: MessageRole) -> Role {
1110+
fn from_ollama_role(&self, role: &MessageRole) -> Role {
10941111
match role {
10951112
MessageRole::User => Role::User,
10961113
MessageRole::Assistant => Role::Assistant,

0 commit comments

Comments
 (0)