Skip to content

Commit c157bfd

Browse files
committed
initial tests
Signed-off-by: Nick Mitchell <[email protected]>
1 parent 0b85e58 commit c157bfd

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// use ::std::cell::LazyCell;
22
use ::std::collections::HashMap;
3-
use ::std::env::current_dir;
3+
// use ::std::env::current_dir;
44
use ::std::error::Error;
55
use ::std::fs::File;
6-
use ::std::path::PathBuf;
6+
// use ::std::path::PathBuf;
77

88
use minijinja::value::ValueKind;
99
use minijinja::Environment;
@@ -30,8 +30,8 @@ type Interpretation = Result<(Context, PdlBlock), Box<dyn Error>>;
3030
struct Interpreter<'a> {
3131
// batch: u32,
3232
// role: Role,
33-
cwd: Box<PathBuf>,
34-
id_stack: Vec<String>,
33+
// cwd: Box<PathBuf>,
34+
// id_stack: Vec<String>,
3535
jinja_env: Environment<'a>,
3636
rt: Runtime,
3737
scope: Vec<Scope>,
@@ -43,8 +43,8 @@ impl<'a> Interpreter<'a> {
4343
Self {
4444
// batch: 0,
4545
// role: Role::User,
46-
cwd: Box::new(current_dir().unwrap_or(PathBuf::from("/"))),
47-
id_stack: vec![],
46+
// cwd: Box::new(current_dir().unwrap_or(PathBuf::from("/"))),
47+
// id_stack: vec![],
4848
jinja_env: Environment::new(),
4949
rt: Runtime::new().unwrap(),
5050
scope: vec![Scope::new()],
@@ -119,7 +119,7 @@ impl<'a> Interpreter<'a> {
119119
0.0
120120
};
121121

122-
let tools = if let Some(Value::Array(tools)) = parameters.get(&"tools".to_string()) {
122+
let tools = if let Some(Value::Array(_tools)) = parameters.get(&"tools".to_string()) {
123123
// TODO
124124
//tools.into_iter().map(|tool| function!()).collect()
125125
vec![]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#[cfg(test)]
2+
mod tests {
3+
// use super::*;
4+
use ::std::error::Error;
5+
6+
use crate::pdl::{
7+
ast::{
8+
PdlBlock,
9+
/*PdlCallBlock,*/
10+
PdlModelBlock, /*PdlRepeatBlock, PdlTextBlock, PdlUsage, Role,*/
11+
},
12+
interpreter::run,
13+
};
14+
15+
use ollama_rs::generation::chat::MessageRole;
16+
17+
const DEFAULT_MODEL: &'static str = "ollama/granite3.2:2b";
18+
19+
#[test]
20+
fn string() -> Result<(), Box<dyn Error>> {
21+
let (messages, _) = run(&PdlBlock::String("hello".into()), false)?;
22+
assert_eq!(messages.len(), 1);
23+
assert_eq!(messages[0].role, MessageRole::User);
24+
assert_eq!(messages[0].content, "hello");
25+
Ok(())
26+
}
27+
28+
#[test]
29+
fn single_model() -> Result<(), Box<dyn Error>> {
30+
let (messages, _) = run(
31+
&PdlBlock::Model(PdlModelBlock {
32+
def: None,
33+
description: None,
34+
model_response: None,
35+
parameters: None,
36+
pdl_result: None,
37+
pdl_usage: None,
38+
model: DEFAULT_MODEL.into(),
39+
input: Some(Box::new(PdlBlock::String("hello".into()))),
40+
}),
41+
false,
42+
)?;
43+
assert_eq!(messages.len(), 1);
44+
assert_eq!(messages[0].role, MessageRole::Assistant);
45+
assert!(messages[0].content.contains("Hello!"));
46+
Ok(())
47+
}
48+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod ast;
22
pub mod extract;
33
pub mod interpreter;
4+
mod interpreter_tests;
45
pub mod pip;
56
pub mod pull;
67
pub mod requirements;

0 commit comments

Comments
 (0)