use std::collections::HashMap;
use crate::spec::SamplingParams;
#[derive(Clone, Debug)]
pub enum Op {
System(String),
User(String),
Assistant(String),
Gen {
name: String,
params: SamplingParams,
},
Select {
name: String,
choices: Vec<String>,
params: SamplingParams,
},
Fork { branches: Vec<Program> },
}
#[derive(Clone, Debug, Default)]
pub struct Program {
pub ops: Vec<Op>,
}
impl Program {
pub fn new() -> Self {
Program { ops: Vec::new() }
}
pub fn system(&mut self, text: impl Into<String>) -> &mut Self {
self.ops.push(Op::System(text.into()));
self
}
pub fn user(&mut self, text: impl Into<String>) -> &mut Self {
self.ops.push(Op::User(text.into()));
self
}
pub fn assistant(&mut self, text: impl Into<String>) -> &mut Self {
self.ops.push(Op::Assistant(text.into()));
self
}
pub fn gen(&mut self, name: impl Into<String>, params: SamplingParams) -> &mut Self {
self.ops.push(Op::Gen {
name: name.into(),
params,
});
self
}
pub fn select(
&mut self,
name: impl Into<String>,
choices: Vec<String>,
params: SamplingParams,
) -> &mut Self {
self.ops.push(Op::Select {
name: name.into(),
choices,
params,
});
self
}
pub fn fork(&mut self, branches: Vec<Program>) -> &mut Self {
self.ops.push(Op::Fork { branches });
self
}
}
#[derive(Clone, Debug, Default)]
pub struct StreamResult {
pub vars: HashMap<String, String>,
pub transcript: String,
}
impl StreamResult {
pub fn get(&self, name: &str) -> Option<&String> {
self.vars.get(name)
}
}