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
11 changes: 11 additions & 0 deletions pdl-live-react/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pdl-live-react/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ tokio = { version = "1.44.1", features = ["io-std"] }
indexmap = { version = "2.9.0", features = ["serde"] }
rustpython-stdlib = { version = "0.4.0", features = ["zlib"] }
schemars = "0.8.22"
fs4 = "0.13.1"

[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-cli = "2"
Expand Down
35 changes: 27 additions & 8 deletions pdl-live-react/src-tauri/src/pdl/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,43 @@ fn extract_values_iter(program: &PdlBlock, field: &str, values: &mut Vec<String>
.array
.iter()
.for_each(|p| extract_values_iter(p, field, values)),
PdlBlock::Text(b) => b
.text
.iter()
.for_each(|p| extract_values_iter(p, field, values)),
PdlBlock::LastOf(b) => b
.last_of
.iter()
.for_each(|p| extract_values_iter(p, field, values)),
PdlBlock::Text(b) => {
b.text
.iter()
.for_each(|p| extract_values_iter(p, field, values));
if let Some(defs) = &b.defs {
defs.values()
.for_each(|p| extract_values_iter(p, field, values));
}
}
PdlBlock::LastOf(b) => {
b.last_of
.iter()
.for_each(|p| extract_values_iter(p, field, values));
if let Some(defs) = &b.defs {
defs.values()
.for_each(|p| extract_values_iter(p, field, values));
}
}
PdlBlock::If(b) => {
extract_values_iter(&b.then, field, values);
if let Some(else_) = &b.else_ {
extract_values_iter(else_, field, values);
}
if let Some(defs) = &b.defs {
defs.values()
.for_each(|p| extract_values_iter(p, field, values));
}
}
PdlBlock::Object(b) => b
.object
.values()
.for_each(|p| extract_values_iter(p, field, values)),

PdlBlock::Function(b) => {
extract_values_iter(&b.return_, field, values);
}

_ => {}
}
}
21 changes: 17 additions & 4 deletions pdl-live-react/src-tauri/src/pdl/pull.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use ::std::io::Error;

use duct::cmd;
use fs4::fs_std::FileExt;
use rayon::prelude::*;

use crate::pdl::ast::PdlBlock;
Expand Down Expand Up @@ -46,8 +47,20 @@ fn ollama_exists(model: &str) -> bool {

/// The Ollama implementation of a single model pull
fn ollama_pull_if_needed(model: &str) -> Result<(), Error> {
if !ollama_exists(model) {
cmd!("ollama", "pull", model).stdout_to_stderr().run()?;
}
Ok(())
let path = ::std::env::temp_dir().join(format!("pdl-ollama-pull-{model}"));
let f = ::std::fs::File::create(path)?;
f.lock_exclusive()?;

// don't ? the cmd! so that we can "finally" unlock the file
let res = if !ollama_exists(model) {
cmd!("ollama", "pull", model)
.stdout_to_stderr()
.run()
.and_then(|_| Ok(()))
} else {
Ok(())
};

FileExt::unlock(&f)?;
res
}