Skip to content

Commit

Permalink
remove old ui
Browse files Browse the repository at this point in the history
  • Loading branch information
kvey committed Feb 16, 2024
1 parent 9ba57d5 commit a44928a
Show file tree
Hide file tree
Showing 107 changed files with 2,041 additions and 8,153 deletions.
2,696 changes: 105 additions & 2,591 deletions toolchain/Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions toolchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[workspace]
members = [
"chidori-core",
"chidori-ui/src-tauri",
"chidori",
"chidori-prompt-format", "chidori-im-hashmap", "chidori-static-analysis",
"chidori-prompt-format",
"chidori-im-hashmap",
"chidori-static-analysis",
]
resolver = "2"

Expand Down
1 change: 1 addition & 0 deletions toolchain/chidori-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ rkyv.workspace = true
reqwest.workspace = true
bytes.workspace = true

regex = "1.10.3"
ariadne = "0.3.0"
chumsky = "0.9.3"
im = "15.1.0"
Expand Down
3 changes: 3 additions & 0 deletions toolchain/chidori-core/examples/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello from an example!");
}
100 changes: 100 additions & 0 deletions toolchain/chidori-core/src/bin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#[macro_use]
extern crate clap;
extern crate env_logger;
#[macro_use]
extern crate log;

use clap::{App, Arg};
use regex::Regex;
use std::fs;
use std::{
path::Path,
time::{Duration, Instant},
};

fn main() {
env_logger::init();
let app = App::new("chidori")
.version(crate_version!())
.author(crate_authors!())
.about("Runs an notebook directory.")
.arg(
Arg::with_name("folder")
.help("Folder to scan")
.required(true),
);
let matches = app.get_matches();

let folder = Path::new(matches.value_of("folder").unwrap());
if folder.exists() && folder.is_dir() {
println!("Parsing folder of python code: {folder:?}");
let t1 = Instant::now();
let parsed_files = parse_folder(folder).unwrap();
let t2 = Instant::now();
} else {
println!("{folder:?} is not a folder.");
}
}

fn parse_folder(path: &Path) -> std::io::Result<Vec<ParsedFile>> {
let mut res = vec![];
for entry in path.read_dir()? {
let entry = entry?;
let metadata = entry.metadata()?;

let path = entry.path();
if metadata.is_dir() {
res.extend(parse_folder(&path)?);
}

if metadata.is_file() && path.extension().and_then(|s| s.to_str()) == Some("md") {
let parsed_file = parse_markdown_file(&path);
match &parsed_file.result {
Ok(_) => {}
Err(y) => error!("Error in file {:?} {:?}", path, y),
}

res.push(parsed_file);
}
}
Ok(res)
}

fn extract_code_blocks(file_path: &str) -> Vec<String> {
let content = fs::read_to_string(file_path).expect("Something went wrong reading the file");

let re = Regex::new(r"```.*?\n(.*?)```").unwrap();
re.captures_iter(&content)
.filter_map(|cap| cap.get(1))
.map(|m| m.as_str().trim().to_string())
.collect()
}

fn parse_markdown_file(filename: &Path) -> ParsedFile {
info!("Parsing file {:?}", filename);
match std::fs::read_to_string(filename) {
Err(e) => ParsedFile {
// filename: Box::new(filename.to_path_buf()),
// code: "".to_owned(),
num_lines: 0,
result: Err(e.to_string()),
},
Ok(source) => {
let num_lines = source.lines().count();
let result = extract_code_blocks(&source);
ParsedFile {
// filename: Box::new(filename.to_path_buf()),
// code: source.to_string(),
num_lines,
result,
}
}
}
}

struct ParsedFile {
// filename: Box<PathBuf>,
// code: String,
num_lines: usize,
result: Vec<String>,
}
67 changes: 56 additions & 11 deletions toolchain/chidori-core/src/cells/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ use crate::library::std::ai::llm::{
TemplateMessage,
};
use chidori_prompt_format::templating::templates::ChatModelRoles;
use chidori_static_analysis::language::python::parse::Report;
use chidori_static_analysis::language::Report;
use std::env;
use tokio::runtime;

pub fn code_cell(cell: &CodeCell) -> OperationNode {
match cell.language {
SupportedLanguage::Python => {
SupportedLanguage::PyO3 => {
// TODO: all callable functions should be exposed as their own OperationNodes
// these can be depended on throughout the graph as their own cells.
let paths =
Expand Down Expand Up @@ -66,7 +66,7 @@ pub fn code_cell(cell: &CodeCell) -> OperationNode {
output_signature,
Box::new(move |x| {
// TODO: this needs to handle stdout and errors
crate::library::std::code::runtime_rustpython::source_code_run_python(
crate::library::std::code::runtime_pyo3::source_code_run_python(
&cell.source_code,
&x,
&cell.function_invocation,
Expand All @@ -81,14 +81,59 @@ pub fn code_cell(cell: &CodeCell) -> OperationNode {
OutputSignature::new(),
Box::new(|x| x),
),
SupportedLanguage::Deno => OperationNode::new(
InputSignature::new(),
OutputSignature::new(),
Box::new(|x| {
unimplemented!();
//crate::library::std::code::runtime_deno::source_code_run_deno(cell.source_code)
}),
),
SupportedLanguage::Deno => {
let paths =
chidori_static_analysis::language::javascript::parse::extract_dependencies_js(
&cell.source_code,
);
let report = chidori_static_analysis::language::javascript::parse::build_report(&paths);

let mut input_signature = InputSignature::new();
for (key, value) in &report.cell_depended_values {
input_signature.globals.insert(
key.clone(),
InputItemConfiguation {
ty: Some(InputType::String),
default: None,
},
);
}

let mut output_signature = OutputSignature::new();
for (key, value) in &report.cell_exposed_values {
output_signature.globals.insert(
key.clone(),
OutputItemConfiguation {
ty: Some(InputType::String),
},
);
}

for (key, value) in &report.triggerable_functions {
output_signature.functions.insert(
key.clone(),
OutputItemConfiguation {
ty: Some(InputType::Function),
},
);
}

let cell = cell.clone();
OperationNode::new(
input_signature,
output_signature,
Box::new(move |x| {
// TODO: this needs to handle stdout and errors
crate::library::std::code::runtime_deno::source_code_run_deno(
&cell.source_code,
&x,
&cell.function_invocation,
)
.unwrap()
.0
}),
)
}
}
}

Expand Down
Loading

0 comments on commit a44928a

Please sign in to comment.