Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pdl-live-react/src-tauri/src/pdl/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,19 @@ pub struct ModelBlock {
#[serde(skip_serializing_if = "Option::is_none")]
pub platform: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<Vec<MessageBlock>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "modelResponse")]
pub model_response: Option<String>,
#[serde(rename = "pdl__usage")]
#[serde(skip_serializing_if = "Option::is_none")]
pub pdl_usage: Option<PdlUsage>,

/// The result of evaluating the `input` field (if given)
#[serde(rename = "pdl__model_input", skip_serializing_if = "Option::is_none")]
pub pdl_model_input: Option<Vec<MessageBlock>>,

/// The actual input given to the model (whether via `input` or from the incoming messages)
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<Vec<MessageBlock>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down
29 changes: 23 additions & 6 deletions pdl-live-react/src-tauri/src/pdl/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,12 +827,14 @@ impl<'a> Interpreter<'a> {
eprintln!("Model tools {:?} {:?}", metadata.description, tools);
}

let mut trace = block.clone();

// The input messages to the model is either:
// a) block.input, if given
// b) the current state's accumulated messages
let input_messages = match &block.input {
Some(input) => {
// TODO ignoring result, trace
// TODO ignoring result and trace
let (_result, messages, _trace) = self.run_quiet(&*input, state).await?;
messages
}
Expand Down Expand Up @@ -917,13 +919,28 @@ impl<'a> Interpreter<'a> {
}
}

let mut trace = block.clone();
// TODO, does this belong in run_advanced(), and does
// trace.context belong in Metadata rather than ModelBlock
trace.context = Some(
state
.messages
.iter()
.map(|m| MessageBlock {
role: self.from_ollama_role(&m.role),
content: Box::new(PdlBlock::String(m.content.clone())),
name: None,
tool_call_id: None,
defsite: None,
})
.collect(),
);
// TODO, what is the difference between context and pdl_model_input fields?
trace.pdl_model_input = Some(
input_messages
.into_iter()
.iter()
.map(|m| MessageBlock {
role: self.from_ollama_role(m.role),
content: Box::new(PdlBlock::String(m.content)),
role: self.from_ollama_role(&m.role),
content: Box::new(PdlBlock::String(m.content.clone())),
name: None,
tool_call_id: None,
defsite: None,
Expand Down Expand Up @@ -1090,7 +1107,7 @@ impl<'a> Interpreter<'a> {
}
}

fn from_ollama_role(&self, role: MessageRole) -> Role {
fn from_ollama_role(&self, role: &MessageRole) -> Role {
match role {
MessageRole::User => Role::User,
MessageRole::Assistant => Role::Assistant,
Expand Down