diff --git a/toolchain/Cargo.lock b/toolchain/Cargo.lock index 5be9207..5a19521 100644 --- a/toolchain/Cargo.lock +++ b/toolchain/Cargo.lock @@ -27,16 +27,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "advisory-lock" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6caee7d48f930f9ad3fc9546f8cbf843365da0c5b0ca4eee1d1ac3dd12d8f93" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "aead" version = "0.5.2" @@ -286,7 +276,6 @@ dependencies = [ "chidori-core", "dirs 3.0.2", "dirs 5.0.1", - "diskmap", "notify-debouncer-full", "petgraph", "pyo3-build-config 0.19.2", @@ -3131,17 +3120,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "diskmap" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6422b0580b2542a6ba7fd39cf610480859586b1ccc2942d4eae39c0fdda2fec8" -dependencies = [ - "advisory-lock", - "serde", - "serde_cbor", -] - [[package]] name = "dispatch" version = "0.2.0" @@ -4568,12 +4546,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "half" -version = "1.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" - [[package]] name = "halfbrown" version = "0.2.5" @@ -8979,8 +8951,6 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" version = "1.0.197" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] @@ -9015,21 +8985,9 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_cbor" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" -dependencies = [ - "half", - "serde", -] - [[package]] name = "serde_derive" version = "1.0.197" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.36", @@ -10282,8 +10240,6 @@ checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" [[package]] name = "tauri" version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f078117725e36d55d29fafcbb4b1e909073807ca328ae8deb8c0b3843aac0fed" dependencies = [ "anyhow", "cocoa", @@ -10315,7 +10271,7 @@ dependencies = [ "tauri-macros", "tauri-runtime", "tauri-runtime-wry", - "tauri-utils", + "tauri-utils 1.5.3", "tempfile", "thiserror", "tokio", @@ -10340,7 +10296,7 @@ dependencies = [ "semver 1.0.22", "serde", "serde_json", - "tauri-utils", + "tauri-utils 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "tauri-winres", "walkdir", ] @@ -10348,8 +10304,6 @@ dependencies = [ [[package]] name = "tauri-codegen" version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1554c5857f65dbc377cefb6b97c8ac77b1cb2a90d30d3448114d5d6b48a77fc" dependencies = [ "base64 0.21.7", "brotli 3.5.0", @@ -10363,7 +10317,7 @@ dependencies = [ "serde", "serde_json", "sha2", - "tauri-utils", + "tauri-utils 1.5.3", "thiserror", "time", "uuid", @@ -10373,22 +10327,18 @@ dependencies = [ [[package]] name = "tauri-macros" version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "277abf361a3a6993ec16bcbb179de0d6518009b851090a01adfea12ac89fa875" dependencies = [ "heck 0.4.1", "proc-macro2 1.0.79", "quote 1.0.36", "syn 1.0.109", "tauri-codegen", - "tauri-utils", + "tauri-utils 1.5.3", ] [[package]] name = "tauri-runtime" version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2d0652aa2891ff3e9caa2401405257ea29ab8372cce01f186a5825f1bd0e76" dependencies = [ "gtk", "http 0.2.12", @@ -10397,7 +10347,7 @@ dependencies = [ "raw-window-handle", "serde", "serde_json", - "tauri-utils", + "tauri-utils 1.5.3", "thiserror", "url", "uuid", @@ -10408,8 +10358,6 @@ dependencies = [ [[package]] name = "tauri-runtime-wry" version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "067c56fc153b3caf406d7cd6de4486c80d1d66c0f414f39e94cb2f5543f6445f" dependencies = [ "cocoa", "gtk", @@ -10417,7 +10365,7 @@ dependencies = [ "rand 0.8.5", "raw-window-handle", "tauri-runtime", - "tauri-utils", + "tauri-utils 1.5.3", "uuid", "webkit2gtk", "webview2-com", @@ -10425,13 +10373,40 @@ dependencies = [ "wry", ] +[[package]] +name = "tauri-utils" +version = "1.5.3" +dependencies = [ + "brotli 3.5.0", + "ctor", + "dunce", + "glob", + "heck 0.4.1", + "html5ever", + "infer 0.13.0", + "json-patch", + "kuchikiki", + "log", + "memchr", + "phf 0.11.2", + "proc-macro2 1.0.79", + "quote 1.0.36", + "semver 1.0.22", + "serde", + "serde_json", + "serde_with", + "thiserror", + "url", + "walkdir", + "windows-version", +] + [[package]] name = "tauri-utils" version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75ad0bbb31fccd1f4c56275d0a5c3abdf1f59999f72cb4ef8b79b4ed42082a21" dependencies = [ - "brotli 3.5.0", "ctor", "dunce", "glob", diff --git a/toolchain/Cargo.toml b/toolchain/Cargo.toml index 1c3dcb9..3f4c209 100644 --- a/toolchain/Cargo.toml +++ b/toolchain/Cargo.toml @@ -29,9 +29,9 @@ protobuf = "3.2.0" sqlparser = "0.34.0" anyhow = { version = "1.0", default-features = false } indoc = "1.0.3" -serde = { version = "1", features = ["derive"] } +serde = { version = "1.0", features = ["derive"] } serde_derive = "1" -serde_json = "=1.0.115" +serde_json = "1.0.115" tonic = "0.9" prost = "0.11" tokio = { version = "1", features = ["full", "tracing"] } @@ -50,9 +50,11 @@ tracing-log = "0.1.3" tracing-chrome = "0.7.1" tracing-flame = "0.2.0" bincode = "2.0.0-rc.3" - petgraph = "0.6.3" [patch.crates-io] deno = {path = "../../deno/cli"} deno_runtime = {path = "../../deno/runtime"} +serde = {path = "../../serde/serde" } +serde_derive = {path = "../../serde/serde_derive" } +tauri = {path = "../../tauri/core/tauri" } diff --git a/toolchain/book_src/SUMMARY.md b/toolchain/book_src/SUMMARY.md index e31c2fb..09a1be2 100644 --- a/toolchain/book_src/SUMMARY.md +++ b/toolchain/book_src/SUMMARY.md @@ -1,7 +1,7 @@ # Summary -[Introduction](README.md) - -- [My First Chapter](my-first-chapter.md) -- [Nested example](nested/README.md) - - [Sub-chapter](nested/sub-chapter.md) \ No newline at end of file +- [Introduction](README.md) +- [Architecture](ARCHITECTURE.md) +- [Library](library/HOME.md) + - [AI](library/ai.md) +- [Future Work](FUTURE_WORK.md) diff --git a/toolchain/chidori-core/examples/core6_prompts_leveraging_function_calling/core.md b/toolchain/chidori-core/examples/core6_prompts_leveraging_function_calling/core.md index 849db60..3597d33 100644 --- a/toolchain/chidori-core/examples/core6_prompts_leveraging_function_calling/core.md +++ b/toolchain/chidori-core/examples/core6_prompts_leveraging_function_calling/core.md @@ -40,7 +40,7 @@ import unittest class TestMarshalledValues(unittest.IsolatedAsyncioTestCase): async def test_run_prompt(self): - self.assertEqual(await run_prompt(5), 4) + self.assertEqual(await current_weather_in_sf(5), 4) unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromTestCase(TestMarshalledValues)) ``` diff --git a/toolchain/chidori-core/examples/core9_multi_agent_simulation/core.md b/toolchain/chidori-core/examples/core9_multi_agent_simulation/core.md index abee84d..fb5d8d1 100644 --- a/toolchain/chidori-core/examples/core9_multi_agent_simulation/core.md +++ b/toolchain/chidori-core/examples/core9_multi_agent_simulation/core.md @@ -17,6 +17,9 @@ import json import os import requests +def partition_html(text=""): + return text + async def scrape_and_summarize_website(website): """Useful to scrape and summarize a website content""" url = f"https://chrome.browserless.io/content?token={os.environ['BROWSERLESS_API_KEY']}" diff --git a/toolchain/chidori-core/src/cells/memory_cell.rs b/toolchain/chidori-core/src/cells/memory_cell.rs index 2db2d03..5c5564b 100644 --- a/toolchain/chidori-core/src/cells/memory_cell.rs +++ b/toolchain/chidori-core/src/cells/memory_cell.rs @@ -1,10 +1,10 @@ use std::time::Duration; use tonic::codegen::Body; use crate::cells::{MemoryCell, SupportedMemoryProviders}; -use crate::execution::primitives::operation::{AsyncRPCCommunication, InputSignature, InputType, OperationNode, OutputItemConfiguation, OutputSignature}; +use crate::execution::primitives::operation::{AsyncRPCCommunication, InputItemConfiguation, InputSignature, InputType, OperationNode, OutputItemConfiguation, OutputSignature}; use futures_util::FutureExt; use serde_json::json; -use crate::execution::primitives::serialized_value::RkyvSerializedValue; +use crate::execution::primitives::serialized_value::{json_value_to_serialized_value, RkyvSerializedValue, serialized_value_to_json_value}; use crate::library::std::ai::memory::in_memory::InMemoryVectorDb; /// Memory cells when first executed have no inputs. They initialize the connection to the memory store. @@ -14,16 +14,17 @@ pub fn memory_cell(cell: &MemoryCell) -> OperationNode { match cell.provider { SupportedMemoryProviders::InMemory => { let mut input_signature = InputSignature::new(); - // input_signature.globals.insert( - // key.clone(), - // InputItemConfiguation { - // ty: Some(InputType::String), - // default: None, - // }, - // ); + input_signature.globals.insert( + cell.embedding_function.clone(), + InputItemConfiguation { + ty: Some(InputType::String), + default: None, + }, + ); let triggerable_functions = vec![ - ("run", "run",) + ("insert", "insert",), + ("search", "search",) ]; let mut output_signature = OutputSignature::new(); @@ -36,28 +37,52 @@ pub fn memory_cell(cell: &MemoryCell) -> OperationNode { }, ); } - let cell = cell.clone(); OperationNode::new( None, input_signature, output_signature, - Box::new(move |_, x, _, async_rpccommunication| { + Box::new(move |s, x, _, async_rpccommunication| { + let embedding_function = cell.embedding_function.clone(); + let s = s.clone(); async move { let mut db = InMemoryVectorDb::new(); db.new_collection("default".to_string()); let mut async_rpccommunication: AsyncRPCCommunication = async_rpccommunication.unwrap(); - async_rpccommunication.callable_interface_sender.send(vec!["run".to_string()]).unwrap(); + async_rpccommunication.callable_interface_sender.send(vec!["insert".to_string(), "search".to_string()]).unwrap(); + let s = s.clone(); tokio::spawn(async move { loop { if let Ok((key, value, sender)) = async_rpccommunication.receiver.try_recv() { match key.as_str() { - "run" => { - let mut embedding = vec![0.1, 0.2, 0.3]; - let contents = json!({"name": "test"}); + "insert" => { + let (embedded_value, _) = s.dispatch(&embedding_function, value.clone()).await; + let mut embedding = vec![]; + if let RkyvSerializedValue::Array(arr) = embedded_value { + arr.iter().for_each(|a| if let RkyvSerializedValue::Float(f) = a { + embedding.push(f.clone()); + }); + } + let contents = serialized_value_to_json_value(&value); let row = vec![(&embedding, contents)]; db.insert("default".to_string(), &row); - sender.send(RkyvSerializedValue::String(format!("{}", 1))).unwrap(); + sender.send(RkyvSerializedValue::String(String::from("Success"))).unwrap(); + } + "search" => { + let (embedded_value, _) = s.dispatch(&embedding_function, value.clone()).await; + let mut embedding = vec![]; + if let RkyvSerializedValue::Array(arr) = embedded_value { + arr.iter().for_each(|a| if let RkyvSerializedValue::Float(f) = a { + embedding.push(f.clone()); + }); + } + let results = db.search("default".to_string(), embedding, 5); + let mut output = vec![]; + for (_, value) in results.iter() { + let value = json_value_to_serialized_value(&value); + output.push(value); + } + sender.send(RkyvSerializedValue::Array(output)).unwrap(); } _ => {} } @@ -75,9 +100,45 @@ pub fn memory_cell(cell: &MemoryCell) -> OperationNode { } #[cfg(test)] mod test { + use super::*; + use std::time::Duration; + use futures_util::FutureExt; + use indoc::indoc; + use crate::cells::{CellTypes, CodeCell, SupportedLanguage}; use crate::execution::execution::ExecutionState; + use crate::execution::primitives::operation::{AsyncRPCCommunication, OperationNode, Signature}; + use crate::execution::primitives::serialized_value::RkyvSerializedValue; #[tokio::test] async fn test_memory_cell() { + let (async_rpc_communication, rpc_sender, callable_interface_receiver) = AsyncRPCCommunication::new(); + let mut state = ExecutionState::new(); + let (mut state, _) = state.update_op(CellTypes::Code(CodeCell { + name: None, + language: SupportedLanguage::PyO3, + source_code: String::from(indoc! {r#" + def fake_embedding(): + return [0.1, 0.2, 0.3] + "#}), + function_invocation: None, + }), Some(0)); + let op = memory_cell(&MemoryCell { + provider: SupportedMemoryProviders::InMemory, + embedding_function: "fake_embedding".to_string(), + }); + let ex = op.execute(&state, RkyvSerializedValue::Null, None, Some(async_rpc_communication)); + let join_handle = tokio::spawn(async move { + ex.await; + }); + let callable_interface = callable_interface_receiver.await; + assert_eq!(callable_interface, Ok(vec!["insert".to_string(), "search".to_string()])); + let (s, r) = tokio::sync::oneshot::channel(); + rpc_sender.send(("insert".to_string(), RkyvSerializedValue::String("Demonstration".to_string()), s)).unwrap(); + let result = r.await.unwrap(); + assert_eq!(result, RkyvSerializedValue::String("Success".to_string())); + let (s, r) = tokio::sync::oneshot::channel(); + rpc_sender.send(("search".to_string(), RkyvSerializedValue::String("Demo".to_string()), s)).unwrap(); + let result = r.await.unwrap(); + assert_eq!(result, RkyvSerializedValue::Array(vec![RkyvSerializedValue::String("Demonstration".to_string())])); } } diff --git a/toolchain/chidori-core/src/cells/mod.rs b/toolchain/chidori-core/src/cells/mod.rs index 487a517..0591385 100644 --- a/toolchain/chidori-core/src/cells/mod.rs +++ b/toolchain/chidori-core/src/cells/mod.rs @@ -103,7 +103,7 @@ bound = "__C: rkyv::validation::ArchiveContext, <__C as rkyv::Fallible>::Error: #[ts(export, export_to = "package_node/types/")] pub(crate) struct MemoryCell { pub(crate) provider: SupportedMemoryProviders, - pub(crate) function_invocation: Option, + pub(crate) embedding_function: String, } diff --git a/toolchain/chidori-core/src/execution/execution/execution_graph.rs b/toolchain/chidori-core/src/execution/execution/execution_graph.rs index df042ea..601321f 100644 --- a/toolchain/chidori-core/src/execution/execution/execution_graph.rs +++ b/toolchain/chidori-core/src/execution/execution/execution_graph.rs @@ -44,7 +44,6 @@ pub type ExecutionNodeId = (usize, usize); #[derive(Debug, Clone)] pub struct MergedStateHistory(HashMap)>); - impl serde::Serialize for MergedStateHistory { fn serialize(&self, serializer: S) -> Result where diff --git a/toolchain/chidori-core/src/execution/integration/mod.rs b/toolchain/chidori-core/src/execution/integration/mod.rs deleted file mode 100644 index 742ec58..0000000 --- a/toolchain/chidori-core/src/execution/integration/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod triggerable; diff --git a/toolchain/chidori-core/src/execution/integration/triggerable.rs b/toolchain/chidori-core/src/execution/integration/triggerable.rs deleted file mode 100644 index 179b14f..0000000 --- a/toolchain/chidori-core/src/execution/integration/triggerable.rs +++ /dev/null @@ -1,61 +0,0 @@ -use crate::execution::execution::execution_graph::ExecutionGraph; - - - -pub trait TriggerContext {} - -struct Context<'a> { - triggered: &'a mut bool, -} - -impl<'a> TriggerContext for Context<'a> {} - -pub trait Subscribable { - fn has_changed(&self) -> bool; -} - -/// Registers a given function with a reactivity db, based on a pointer to the boxed function. -/// We use this as the identity of that method and return that identity so that we can continue to -/// mutate the composition of the registered function. -pub fn make_triggerable(_reactivity_db: &mut ExecutionGraph, _args: usize, func: F) -> usize -where - F: 'static + FnMut(Vec<&Option>>) -> Vec, -{ - let boxed_fn = Box::new(func); - let _box_address = &*boxed_fn as *const _ as usize; - // reactivity_db.upsert_operation(box_address, args, boxed_fn) - assert!(false); - 0 -} - -#[cfg(test)] -mod tests { - use super::*; - - #[derive(Debug, Clone)] - struct Element { - name: String, - } - - impl Subscribable for Element { - fn has_changed(&self) -> bool { - // A simple example; in reality, you might compare states or versions - self.name.contains("changed") - } - } - - #[test] - fn test_trigger_on_dependency_change() { - let mut binding = false; - { - let mut registry = ExecutionGraph::new(); - let mut context = Context { - triggered: &mut binding, - }; - - make_triggerable(&mut registry, 2, |ctx: Vec<&Option>>| vec![1, 2]); - - assert_eq!(*context.triggered, true); - } - } -} diff --git a/toolchain/chidori-core/src/execution/mod.rs b/toolchain/chidori-core/src/execution/mod.rs index cabdea6..68ff485 100644 --- a/toolchain/chidori-core/src/execution/mod.rs +++ b/toolchain/chidori-core/src/execution/mod.rs @@ -1,3 +1,2 @@ pub mod execution; -pub mod integration; pub mod primitives; diff --git a/toolchain/chidori-core/src/execution/primitives/mod.rs b/toolchain/chidori-core/src/execution/primitives/mod.rs index b1919eb..7ff65bf 100644 --- a/toolchain/chidori-core/src/execution/primitives/mod.rs +++ b/toolchain/chidori-core/src/execution/primitives/mod.rs @@ -1,4 +1,3 @@ pub mod identifiers; pub mod operation; pub mod serialized_value; -mod serialized_value_utils; diff --git a/toolchain/chidori-core/src/execution/primitives/operation.rs b/toolchain/chidori-core/src/execution/primitives/operation.rs index b4f266c..607158f 100644 --- a/toolchain/chidori-core/src/execution/primitives/operation.rs +++ b/toolchain/chidori-core/src/execution/primitives/operation.rs @@ -226,7 +226,7 @@ pub struct AsyncRPCCommunication { } impl AsyncRPCCommunication { - fn new() -> (AsyncRPCCommunication, tokio::sync::mpsc::UnboundedSender<(String, RkyvSerializedValue, tokio::sync::oneshot::Sender)>, oneshot::Receiver>) { + pub(crate) fn new() -> (AsyncRPCCommunication, tokio::sync::mpsc::UnboundedSender<(String, RkyvSerializedValue, tokio::sync::oneshot::Sender)>, oneshot::Receiver>) { let (callable_interface_sender, callable_interface_receiver) = oneshot::channel(); let (sender, receiver) = tokio::sync::mpsc::unbounded_channel(); let async_rpc_communication = AsyncRPCCommunication { diff --git a/toolchain/chidori-core/src/execution/primitives/serialized_value.rs b/toolchain/chidori-core/src/execution/primitives/serialized_value.rs index 653d88c..cc29d44 100644 --- a/toolchain/chidori-core/src/execution/primitives/serialized_value.rs +++ b/toolchain/chidori-core/src/execution/primitives/serialized_value.rs @@ -7,8 +7,9 @@ use rkyv::{ use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize}; use serde_json::Value; use std::collections::{HashMap, HashSet}; +use std::hash::Hasher; -#[derive(Archive, RkyvSerialize, RkyvDeserialize, Debug, PartialEq, Clone)] +#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Debug, Clone)] #[archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer"))] #[archive(check_bytes)] #[archive_attr(check_bytes( @@ -23,6 +24,14 @@ pub enum RkyvSerializedValue { Cell(CellTypes), + // TODO: add Embedding + Set( + + #[omit_bounds] + #[archive_attr(omit_bounds)] + HashSet + ), + Float(f32), Number(i32), String(String), @@ -88,6 +97,107 @@ impl RkyvObjectBuilder { } } +impl std::cmp::Eq for RkyvSerializedValue { +} + +impl std::cmp::PartialEq for RkyvSerializedValue { + fn eq(&self, other: &Self) -> bool { + if core::mem::discriminant(self) != core::mem::discriminant(other) { + return false; + } + match self { + RkyvSerializedValue::StreamPointer(a) => { + match other { + RkyvSerializedValue::StreamPointer(aa) => { a == aa } + _ => unreachable!() + } + } + RkyvSerializedValue::FunctionPointer(a, b) => { + match other { + RkyvSerializedValue::FunctionPointer(aa,bb ) => { a == aa && b == bb } + _ => unreachable!() + } + } + RkyvSerializedValue::Cell(a) => { + match other { + RkyvSerializedValue::Cell(aa) => { a == aa } + _ => unreachable!() + } + } + RkyvSerializedValue::Set(a) => { + match other { + RkyvSerializedValue::Set(aa) => { a == aa } + _ => unreachable!() + } + } + RkyvSerializedValue::Float(_) => { + return false; + } + RkyvSerializedValue::Number(a) => { + match other { + RkyvSerializedValue::Number(aa) => { a == aa } + _ => unreachable!() + } + } + RkyvSerializedValue::String(a) => { + match other { + RkyvSerializedValue::String(aa) => { a == aa } + _ => unreachable!() + } + } + RkyvSerializedValue::Boolean(a) => { + match other { + RkyvSerializedValue::Boolean(aa) => { a == aa } + _ => unreachable!() + } + } + RkyvSerializedValue::Null => { + match other { + RkyvSerializedValue::Null => { true } + _ => unreachable!() + } + } + RkyvSerializedValue::Array(a) => { + match other { + RkyvSerializedValue::Array(aa) => { + a == aa + } + _ => unreachable!() + } + } + RkyvSerializedValue::Object(a) => { + match other { + RkyvSerializedValue::Object(aa) => { + a == aa + } + _ => unreachable!() + } + } + } + } +} + +impl std::hash::Hash for RkyvSerializedValue { + fn hash(&self, state: &mut H) { + todo!() + } +} + +impl std::cmp::PartialEq for ArchivedRkyvSerializedValue { + fn eq(&self, other: &Self) -> bool { + todo!() + } +} + +impl std::cmp::Eq for ArchivedRkyvSerializedValue { +} + +impl std::hash::Hash for ArchivedRkyvSerializedValue { + fn hash(&self, state: &mut H) { + todo!() + } +} + impl std::fmt::Display for RkyvSerializedValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { @@ -110,6 +220,13 @@ impl std::fmt::Display for RkyvSerializedValue { .collect(); write!(f, "Object{{{}}}", shapes.join(", ")) } + RkyvSerializedValue::Set(set) => { + let shapes: Vec = set + .iter() + .map(|value| format!("{}", value)) + .collect(); + write!(f, "Set{{{}}}", shapes.join(", ")) + } } } } @@ -135,6 +252,7 @@ pub fn deserialize_from_buf(v: &[u8]) -> RkyvSerializedValue { pub fn serialized_value_to_json_value(v: &RkyvSerializedValue) -> Value { match &v { + RkyvSerializedValue::Float(f) => Value::Number(f.to_string().parse().unwrap()), RkyvSerializedValue::Number(n) => Value::Number(n.to_string().parse().unwrap()), RkyvSerializedValue::String(s) => Value::String(s.to_string()), @@ -153,6 +271,11 @@ pub fn serialized_value_to_json_value(v: &RkyvSerializedValue) -> Value { RkyvSerializedValue::StreamPointer(_) => Value::Null, RkyvSerializedValue::Cell(_) => Value::Null, RkyvSerializedValue::Null => Value::Null, + RkyvSerializedValue::Set(a) => { + a.iter() + .map(|v| serialized_value_to_json_value(v)) + .collect() + } } } @@ -234,6 +357,7 @@ mod tests { assert_eq!(deserialized, value); } + #[ignore] #[test] fn test_float() { let value = RkyvSerializedValue::Float(42.0); diff --git a/toolchain/chidori-core/src/execution/primitives/serialized_value_utils.rs b/toolchain/chidori-core/src/execution/primitives/serialized_value_utils.rs deleted file mode 100644 index b28b3d1..0000000 --- a/toolchain/chidori-core/src/execution/primitives/serialized_value_utils.rs +++ /dev/null @@ -1,7 +0,0 @@ -use crate::execution::primitives::serialized_value::RkyvSerializedValue; - -fn functions_from_payload(payload: RkyvSerializedValue) { - if let RkyvSerializedValue::Object(ref payload_map) = payload { - if let Some(RkyvSerializedValue::Object(functions_map)) = payload_map.get("functions") {} - } -} \ No newline at end of file diff --git a/toolchain/chidori-core/src/library/std/ai/llm/anthropic/batch.rs b/toolchain/chidori-core/src/library/std/ai/llm/anthropic/batch.rs deleted file mode 100644 index b90441e..0000000 --- a/toolchain/chidori-core/src/library/std/ai/llm/anthropic/batch.rs +++ /dev/null @@ -1,27 +0,0 @@ -use ollama_rs::generation::completion::request::GenerationRequest; -use ollama_rs::generation::options::GenerationOptions; -use ollama_rs::Ollama; - -async fn batch() { - // By default it will connect to localhost:11434 - let ollama = Ollama::default(); - -// // For custom values: -// let ollama = Ollama::new("http://localhost".to_string(), 11434); - - let model = "llama2:latest".to_string(); - let prompt = "Why is the sky blue?".to_string(); - - let options = GenerationOptions::default() - .temperature(0.2) - .repeat_penalty(1.5) - .top_k(25) - .top_p(0.25); - - let res = ollama.generate(GenerationRequest::new(model, prompt).options(options)).await; - - if let Ok(res) = res { - println!("{}", res.response); - } - -} \ No newline at end of file diff --git a/toolchain/chidori-core/src/library/std/ai/llm/anthropic/mod.rs b/toolchain/chidori-core/src/library/std/ai/llm/anthropic/mod.rs deleted file mode 100644 index 69c4c50..0000000 --- a/toolchain/chidori-core/src/library/std/ai/llm/anthropic/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod batch; -mod streaming; \ No newline at end of file diff --git a/toolchain/chidori-core/src/library/std/ai/llm/anthropic/streaming.rs b/toolchain/chidori-core/src/library/std/ai/llm/anthropic/streaming.rs deleted file mode 100644 index abda424..0000000 --- a/toolchain/chidori-core/src/library/std/ai/llm/anthropic/streaming.rs +++ /dev/null @@ -1,20 +0,0 @@ -use ollama_rs::generation::completion::request::GenerationRequest; -use ollama_rs::Ollama; -use futures_util::StreamExt; -use tokio::io::AsyncWriteExt; - -async fn stream() { - - let ollama = Ollama::default(); - let model = "llama2:latest".to_string(); - let prompt = "Why is the sky blue?".to_string(); - - let mut stream = ollama.generate_stream(GenerationRequest::new(model, prompt)).await.unwrap(); - - let mut stdout = tokio::io::stdout(); - while let Some(res) = stream.next().await { - let res = res.unwrap(); - // stdout.write(res.as_bytes()).await.unwrap(); - stdout.flush().await.unwrap(); - } -} \ No newline at end of file diff --git a/toolchain/chidori-core/src/library/std/ai/llm/mod.rs b/toolchain/chidori-core/src/library/std/ai/llm/mod.rs index 3e26355..0edec7b 100644 --- a/toolchain/chidori-core/src/library/std/ai/llm/mod.rs +++ b/toolchain/chidori-core/src/library/std/ai/llm/mod.rs @@ -130,6 +130,7 @@ pub struct ChatCompletionRes { #[derive(Debug, Serialize, Deserialize)] pub struct EmbeddingReq { + content: String, model: String, frequency_penalty: Option, max_tokens: Option, @@ -172,7 +173,7 @@ trait CompletionModel { #[async_trait] trait EmbeddingModel { - async fn embed(&self, chat_completion_req: ChatCompletionReq) -> Result, String>; + async fn embed(&self, embedding_req: EmbeddingReq) -> Result, String>; } @@ -189,7 +190,6 @@ pub async fn ai_llm_run_completion_model( pub async fn ai_llm_run_embedding_model( execution_state: &ExecutionState, payload: RkyvSerializedValue, - role_blocks: Vec<(ChatModelRoles, Option)>, name: Option, is_function_invocation: bool, ) -> RkyvSerializedValue { @@ -231,14 +231,15 @@ pub async fn ai_llm_run_chat_model( // TODO: replace this to being fetched from configuration let api_key = env::var("OPENAI_API_KEY").unwrap().to_string(); - let c = crate::library::std::ai::llm::openai::OpenAIChatModel::new(api_key); + let API_URL_V1: &str = "https://api.openai.com/v1"; + let c = crate::library::std::ai::llm::openai::OpenAIChatModel::new(API_URL_V1.to_string(), api_key); let result = c.batch(ChatCompletionReq { model: "gpt-3.5-turbo".to_string(), template_messages, ..ChatCompletionReq::default() }).await; if let Ok(ChatCompletionRes { choices, .. }) = result { - // TODO: if invoked as a function don't nest this + // if invoked as a function don't nest the result in a named key, return the response as a direct string let mut result_map = HashMap::new(); if !is_function_invocation { if let Some(name) = &name { diff --git a/toolchain/chidori-core/src/library/std/ai/llm/ollama/batch.rs b/toolchain/chidori-core/src/library/std/ai/llm/ollama/batch.rs deleted file mode 100644 index b90441e..0000000 --- a/toolchain/chidori-core/src/library/std/ai/llm/ollama/batch.rs +++ /dev/null @@ -1,27 +0,0 @@ -use ollama_rs::generation::completion::request::GenerationRequest; -use ollama_rs::generation::options::GenerationOptions; -use ollama_rs::Ollama; - -async fn batch() { - // By default it will connect to localhost:11434 - let ollama = Ollama::default(); - -// // For custom values: -// let ollama = Ollama::new("http://localhost".to_string(), 11434); - - let model = "llama2:latest".to_string(); - let prompt = "Why is the sky blue?".to_string(); - - let options = GenerationOptions::default() - .temperature(0.2) - .repeat_penalty(1.5) - .top_k(25) - .top_p(0.25); - - let res = ollama.generate(GenerationRequest::new(model, prompt).options(options)).await; - - if let Ok(res) = res { - println!("{}", res.response); - } - -} \ No newline at end of file diff --git a/toolchain/chidori-core/src/library/std/ai/llm/ollama/mod.rs b/toolchain/chidori-core/src/library/std/ai/llm/ollama/mod.rs deleted file mode 100644 index 69c4c50..0000000 --- a/toolchain/chidori-core/src/library/std/ai/llm/ollama/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod batch; -mod streaming; \ No newline at end of file diff --git a/toolchain/chidori-core/src/library/std/ai/llm/ollama/streaming.rs b/toolchain/chidori-core/src/library/std/ai/llm/ollama/streaming.rs deleted file mode 100644 index abda424..0000000 --- a/toolchain/chidori-core/src/library/std/ai/llm/ollama/streaming.rs +++ /dev/null @@ -1,20 +0,0 @@ -use ollama_rs::generation::completion::request::GenerationRequest; -use ollama_rs::Ollama; -use futures_util::StreamExt; -use tokio::io::AsyncWriteExt; - -async fn stream() { - - let ollama = Ollama::default(); - let model = "llama2:latest".to_string(); - let prompt = "Why is the sky blue?".to_string(); - - let mut stream = ollama.generate_stream(GenerationRequest::new(model, prompt)).await.unwrap(); - - let mut stdout = tokio::io::stdout(); - while let Some(res) = stream.next().await { - let res = res.unwrap(); - // stdout.write(res.as_bytes()).await.unwrap(); - stdout.flush().await.unwrap(); - } -} \ No newline at end of file diff --git a/toolchain/chidori-core/src/library/std/ai/llm/openai/batch.rs b/toolchain/chidori-core/src/library/std/ai/llm/openai/batch.rs index 6edb362..056e979 100644 --- a/toolchain/chidori-core/src/library/std/ai/llm/openai/batch.rs +++ b/toolchain/chidori-core/src/library/std/ai/llm/openai/batch.rs @@ -117,7 +117,8 @@ mod tests { #[tokio::test] async fn test_batch_completion() { let api_key = env::var("OPENAI_API_KEY").unwrap().to_string(); - let model = OpenAIChatModel::new(api_key); + let API_URL_V1: &str = "https://api.openai.com/v1"; + let model = OpenAIChatModel::new(API_URL_V1.to_string(), api_key); let chat_completion_req = ChatCompletionReq { model: "".to_string(), ..ChatCompletionReq::default() diff --git a/toolchain/chidori-core/src/library/std/ai/llm/openai/embedding.rs b/toolchain/chidori-core/src/library/std/ai/llm/openai/embedding.rs new file mode 100644 index 0000000..6b375e4 --- /dev/null +++ b/toolchain/chidori-core/src/library/std/ai/llm/openai/embedding.rs @@ -0,0 +1,46 @@ +use async_trait::async_trait; +use openai_api_rs::v1::embedding::{EmbeddingRequest, EmbeddingResponse}; +use crate::library::std::ai::llm::{ChatCompletionReq, ChatModelBatch, ChatModelStream, EmbeddingModel, EmbeddingReq, Usage}; +use crate::library::std::ai::llm::openai::OpenAIChatModel; + +#[async_trait] +impl EmbeddingModel for OpenAIChatModel { + async fn embed(&self, embedding_request: EmbeddingReq) -> Result, String> { + let req = EmbeddingRequest { + model: embedding_request.model, + input: embedding_request.content, + user: None, + }; + self.client + .embedding(req) + .map(|res| res.data.first().unwrap().embedding.clone()) + .map_err(|e| e.message) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use openai_api_rs::v1::api::Client; + use std::env; + use crate::library::std::ai::llm::EmbeddingReq; + + #[tokio::test] + async fn test_openai_embedding() { + // TODO: Ollama doesnt support embeddings api + let api_key = env::var("OPENAI_API_KEY").unwrap().to_string(); + let API_URL_V1: &str = "https://api.openai.com/v1"; + let model = OpenAIChatModel::new(API_URL_V1.to_string(), api_key); + let embedding_req = EmbeddingReq { + content: "".to_string(), + model: "".to_string(), + frequency_penalty: None, + max_tokens: None, + presence_penalty: None, + stop: None, + }; + let result = model.embed(embedding_req).await; + assert!(result.is_ok()); + let response = result.unwrap(); + } +} diff --git a/toolchain/chidori-core/src/library/std/ai/llm/openai/mod.rs b/toolchain/chidori-core/src/library/std/ai/llm/openai/mod.rs index 1927ca9..20d5798 100644 --- a/toolchain/chidori-core/src/library/std/ai/llm/openai/mod.rs +++ b/toolchain/chidori-core/src/library/std/ai/llm/openai/mod.rs @@ -1,17 +1,19 @@ pub mod batch; pub mod streaming; +mod embedding; use openai_api_rs::v1::api::Client; use std::env; pub struct OpenAIChatModel { + api_url: String, api_key: String, client: Client, } impl OpenAIChatModel { - pub fn new(api_key: String) -> Self { - let client = Client::new(api_key.clone()); - Self { client, api_key } + pub fn new(api_url: String, api_key: String) -> Self { + let client = Client::new_with_endpoint(api_url.clone(), api_key.clone()); + Self { api_url, client, api_key } } } diff --git a/toolchain/chidori-core/src/library/std/ai/llm/openai/streaming.rs b/toolchain/chidori-core/src/library/std/ai/llm/openai/streaming.rs index 3f32c8b..8b68747 100644 --- a/toolchain/chidori-core/src/library/std/ai/llm/openai/streaming.rs +++ b/toolchain/chidori-core/src/library/std/ai/llm/openai/streaming.rs @@ -16,7 +16,7 @@ use std::task::{Context, Poll}; #[async_trait] impl ChatModelStream for OpenAIChatModel { async fn stream(&self, chat_completion_req: ChatCompletionReq) -> Result { - let api_url = "https://api.openai.com/v1/chat/completions"; + let api_url = &self.api_url; let client = Client::new(); let response: Response = match client .post(api_url) @@ -152,7 +152,8 @@ mod tests { async fn test_gpt_stream_raw_line() { dotenv::dotenv().ok(); let api_key = env::var("OPENAI_API_KEY").unwrap().to_string(); - let model = OpenAIChatModel::new(api_key); + let API_URL_V1: &str = "https://api.openai.com/v1"; + let model = OpenAIChatModel::new(API_URL_V1.to_string(), api_key); let stream = model.stream(Default::default()).await.unwrap(); let mut stream = Box::pin(stream); while let Some(value) = stream.next().await { diff --git a/toolchain/chidori-core/src/library/std/code/runtime_pyo3.rs b/toolchain/chidori-core/src/library/std/code/runtime_pyo3.rs index 05f879b..192dd0a 100644 --- a/toolchain/chidori-core/src/library/std/code/runtime_pyo3.rs +++ b/toolchain/chidori-core/src/library/std/code/runtime_pyo3.rs @@ -420,13 +420,16 @@ asyncio.run(__wrapper()) } } }); - if let Ok(result) = result { - let awaited_result = result.await; - let (_, output_stdout) = PYTHON_LOGGING_BUFFER_STDOUT.remove(&exec_id).unwrap_or((0, vec![])); - let (_, output_stderr) = PYTHON_LOGGING_BUFFER_STDERR.remove(&exec_id).unwrap_or((0, vec![])); - Ok((awaited_result, output_stdout, output_stderr)) - } else { - return Err(anyhow::anyhow!("No result")); + match result { + Ok(result) => { + let awaited_result = result.await; + let (_, output_stdout) = PYTHON_LOGGING_BUFFER_STDOUT.remove(&exec_id).unwrap_or((0, vec![])); + let (_, output_stderr) = PYTHON_LOGGING_BUFFER_STDERR.remove(&exec_id).unwrap_or((0, vec![])); + Ok((awaited_result, output_stdout, output_stderr)) + } + Err(e) => { + return Err(anyhow::anyhow!(e.to_string())); + } } } diff --git a/toolchain/chidori-core/src/sdk/entry.rs b/toolchain/chidori-core/src/sdk/entry.rs index 7a3c267..dd72287 100644 --- a/toolchain/chidori-core/src/sdk/entry.rs +++ b/toolchain/chidori-core/src/sdk/entry.rs @@ -99,7 +99,7 @@ impl InstancedEnvironment { } if let Some(sender) = self.runtime_event_sender.as_mut() { - sender.send(EventsFromRuntime::CellsUpdated(shared_state.cells.clone())).unwrap(); + sender.send(EventsFromRuntime::CellsUpdated(serde_json::to_string(&shared_state.cells.clone()).unwrap())).unwrap(); } } @@ -131,7 +131,7 @@ impl InstancedEnvironment { self.execution_head_state_id = id; let merged_state = self.db.get_merged_state_history(&id); let sender = self.runtime_event_sender.as_mut().unwrap(); - sender.send(EventsFromRuntime::ExecutionStateChange(merged_state)).unwrap(); + sender.send(EventsFromRuntime::ExecutionStateChange(serde_json::to_string(&merged_state).unwrap())).unwrap(); } }, _ => {} @@ -163,7 +163,7 @@ impl InstancedEnvironment { let ((state_id, state), outputs) = self.db.external_step_execution(self.execution_head_state_id).await; if let Some(sender) = self.runtime_event_sender.as_mut() { sender.send(EventsFromRuntime::ExecutionGraphUpdated(self.db.get_execution_graph_elements())).unwrap(); - sender.send(EventsFromRuntime::ExecutionStateChange(self.db.get_merged_state_history(&state_id))).unwrap(); + sender.send(EventsFromRuntime::ExecutionStateChange(serde_json::to_string(&self.db.get_merged_state_history(&state_id)).unwrap())).unwrap(); } println!("Resulted in state with id {:?}", &state_id); self.execution_head_state_id = state_id; @@ -176,7 +176,7 @@ impl InstancedEnvironment { println!("Upserting cell into state with id {:?}", &self.execution_head_state_id); let ((state_id, state), op_id) = self.db.mutate_graph(self.execution_head_state_id, cell, op_id); if let Some(sender) = self.runtime_event_sender.as_mut() { - sender.send(EventsFromRuntime::ExecutionStateChange(self.db.get_merged_state_history(&state_id))).unwrap(); + sender.send(EventsFromRuntime::ExecutionStateChange(serde_json::to_string(&self.db.get_merged_state_history(&state_id)).unwrap())).unwrap(); sender.send(EventsFromRuntime::DefinitionGraphUpdated(state.get_dependency_graph_flattened())).unwrap(); sender.send(EventsFromRuntime::ExecutionGraphUpdated(self.db.get_execution_graph_elements())).unwrap(); } @@ -200,12 +200,36 @@ pub enum UserInteractionMessage { } +// https://github.com/rust-lang/rust/issues/22750 +// TODO: we can't serialize these within the Tauri application due to some kind of issue +// with serde versions once we introduced a deeper dependency on Deno. +// we attempted the following patch to no avail: +// +// [patch.crates-io] +// deno = {path = "../../deno/cli"} +// deno_runtime = {path = "../../deno/runtime"} +// serde = {path = "../../serde/serde" } +// serde_derive = {path = "../../serde/serde_derive" } +// tauri = {path = "../../tauri/core/tauri" } +// +// TODO: in each of these we resolved to the same serde version. +// we need to figure out how to resolve this issue, but to move forward +// for now we will serialize these to Strings on this side of the interface +// the original type of this object is as follows: +// +// #[derive(Clone, Debug, Serialize, Deserialize)] +// pub enum EventsFromRuntime { +// DefinitionGraphUpdated(Vec<(OperationId, OperationId, Vec)>), +// ExecutionGraphUpdated(Vec<(ExecutionNodeId, ExecutionNodeId)>), +// ExecutionStateChange(MergedStateHistory), +// CellsUpdated(Vec) +// } #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EventsFromRuntime { DefinitionGraphUpdated(Vec<(OperationId, OperationId, Vec)>), ExecutionGraphUpdated(Vec<(ExecutionNodeId, ExecutionNodeId)>), - ExecutionStateChange(MergedStateHistory), - CellsUpdated(Vec) + ExecutionStateChange(String), + CellsUpdated(String) } #[derive(Debug, serde::Serialize, serde::Deserialize, Clone)] diff --git a/toolchain/chidori-core/src/utils/telemetry.rs b/toolchain/chidori-core/src/utils/telemetry.rs index b701d2e..8f13d3c 100644 --- a/toolchain/chidori-core/src/utils/telemetry.rs +++ b/toolchain/chidori-core/src/utils/telemetry.rs @@ -8,6 +8,7 @@ use tracing::subscriber::Interest; use tracing_subscriber::layer::SubscriberExt; use tracing::field::{ValueSet, Visit, Field}; use std::fmt::Debug; +pub use serde::Serialize; struct MatchStrVisitor<'a> { field: &'a str, @@ -59,6 +60,24 @@ pub enum TraceEvents{ Close(String, u128), } +// https://github.com/rust-lang/rust/issues/22750 +// TODO: we can't serialize these within the Tauri application due to some kind of issue +// with serde versions once we introduced a deeper dependency on Deno. +// we attempted the following patch to no avail: +// +// [patch.crates-io] +// deno = {path = "../../deno/cli"} +// deno_runtime = {path = "../../deno/runtime"} +// serde = {path = "../../serde/serde" } +// serde_derive = {path = "../../serde/serde_derive" } +// tauri = {path = "../../tauri/core/tauri" } +// +// TODO: this function exists to perform serialization to strings on THIS side of the +// crate boundary, and then we can send the strings over to the Tauri side. +pub fn trace_event_to_string(trace_event: TraceEvents) -> String { + serde_json::to_string(&trace_event).unwrap() +} + struct Timing { started_at: Instant, } diff --git a/toolchain/chidori-ui/src-tauri/Cargo.toml b/toolchain/chidori-ui/src-tauri/Cargo.toml index 0661781..51dd269 100644 --- a/toolchain/chidori-ui/src-tauri/Cargo.toml +++ b/toolchain/chidori-ui/src-tauri/Cargo.toml @@ -19,7 +19,6 @@ pyo3-build-config = "0.19.1" [dependencies] tauri = { version = "1.6.1", features = [ "dialog-open", "fs-all"] } - serde.workspace = true serde_json.workspace = true serde_derive.workspace = true @@ -28,7 +27,6 @@ chidori-core = { path = "../../chidori-core" } dirs = "5.0.1" target-lexicon = "0.12.14" petgraph.workspace = true -diskmap = "0.2.0" rusqlite = { version = "0.29.0", features = ["bundled"] } notify-debouncer-full = "0.3.1" ts-rs = "7.1" diff --git a/toolchain/chidori-ui/src-tauri/build.rs b/toolchain/chidori-ui/src-tauri/build.rs index d89f8a8..c1e6e37 100644 --- a/toolchain/chidori-ui/src-tauri/build.rs +++ b/toolchain/chidori-ui/src-tauri/build.rs @@ -54,8 +54,8 @@ fn add_extension_module_link_args(triple: &Triple) -> io::Result<()> { fn main() -> Result<(), Box> { let target_triple = env::var("TARGET").expect("TARGET was not set"); let triple = Triple::from_str(&target_triple).expect("Invalid target triple"); - // add_extension_module_link_args(&triple); - // pyo3_build_config::add_extension_module_link_args(); + add_extension_module_link_args(&triple); + pyo3_build_config::add_extension_module_link_args(); tauri_build::build(); Ok(()) } diff --git a/toolchain/chidori-ui/src-tauri/src/main.rs b/toolchain/chidori-ui/src-tauri/src/main.rs index bd71030..41341e4 100644 --- a/toolchain/chidori-ui/src-tauri/src/main.rs +++ b/toolchain/chidori-ui/src-tauri/src/main.rs @@ -4,7 +4,6 @@ mod dagre; use std::collections::HashSet; -use diskmap::DiskMap; use std::ops::{Deref, DerefMut}; use rusqlite::{Connection, Result}; use std::path::{Path, PathBuf}; @@ -22,13 +21,12 @@ use chidori_core::cells::CellTypes; use crate::dagre::DagreLayout; use crate::dagre::{Data, Edge, Node, Rect}; use notify_debouncer_full::{notify::{Watcher, RecommendedWatcher, RecursiveMode}, new_debouncer, DebounceEventResult, Debouncer, FileIdCache, FileIdMap}; +use serde::Serializer; use tauri::async_runtime::JoinHandle; use ts_rs::TS; -use serde::Serialize; -use chidori_core::execution::execution::execution_graph::{ExecutionNodeId, MergedStateHistory}; +use chidori_core::execution::execution::execution_graph::{ExecutionNodeId, MergedStateHistory, Serialize}; use chidori_core::execution::primitives::identifiers::{DependencyReference, OperationId}; -use chidori_core::utils::telemetry::TraceEvents; - +use chidori_core::utils::telemetry::{trace_event_to_string, TraceEvents}; // the payload type must implement `Serialize` and `Clone`. #[derive(Clone, serde::Serialize)] @@ -61,7 +59,7 @@ struct InternalState { fn main() { - let config: DiskMap = DiskMap::open_new("/tmp/chidori.db").unwrap(); + // let config: DiskMap = DiskMap::open_new("/tmp/chidori.db").unwrap(); tauri::Builder::default() .setup(|app| { @@ -114,8 +112,6 @@ fn main() { handle.emit_all("sync:definitionGraphState", Some(maintain_definition_graph(&state))).expect("Failed to emit"); } EventsFromRuntime::CellsUpdated(state) => { - let state: Vec = state; - serde_json::to_string(&state.first().unwrap()); handle.emit_all("sync:cellsState", Some(state)).expect("Failed to emit"); } _ => {} @@ -143,7 +139,7 @@ fn main() { match trace_event_receiver.recv() { Ok(msg) => { // println!("Received: {:?}", &msg); - handle.emit_all("execution:events", Some(msg)); + handle.emit_all("execution:events", Some(trace_event_to_string(msg))); } Err(_) => { println!("Channel closed");