Skip to content

Commit

Permalink
neon interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kvey committed Jan 18, 2024
1 parent 88fbaeb commit 847d487
Show file tree
Hide file tree
Showing 26 changed files with 2,641 additions and 77 deletions.
2 changes: 1 addition & 1 deletion devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# https://devenv.sh/scripts/
scripts.hello.exec = "echo Welcome to the Chidori dev enviroment";
scripts.run-ui.exec = "(cd toolchain/prompt-graph-ui && yarn run tauri dev";
scripts.run-ui.exec = "(cd toolchain/prompt-graph-ui && yarn run tauri dev)";

enterShell = ''
REPO_ROOT=`git rev-parse --show-toplevel`
Expand Down
78 changes: 76 additions & 2 deletions toolchain/Cargo.lock

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

2 changes: 2 additions & 0 deletions toolchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ repository = "https://github.com/ThousandBirdsInc/chidori"

[profile.release]
lto = true
# Tell `rustc` to optimize for small code size.
#opt-level = "s"

[workspace.dependencies]
rkyv = {version = "0.7.42", features = ["validation"]}
Expand Down
11 changes: 8 additions & 3 deletions toolchain/chidori-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ description = "Core of Chidori, compiles graph and node definitions into an inte

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "chidori_core"
crate-type = ["cdylib", "lib"]
name = "_chidori_core"
crate-type = ["lib", "cdylib"]
bench = false
proc-macro = true

Expand Down Expand Up @@ -70,6 +70,8 @@ rustpython-parser = "0.3.0"
chidori-prompt-format = { path = "../chidori-prompt-format" }
chidori-static-analysis = { path = "../chidori-static-analysis" }

ts-rs = "7.1"


# TODO: make optional
yaml-front-matter = "0.1.0"
Expand All @@ -90,12 +92,15 @@ num = "0.4.1"

once_cell = "1"
neon-serde3 = "0.10.0"
target-lexicon = "0.12.13"
dirs = "5.0.1"

[dependencies.neon]
version = "0.10.1"
default-features = false
features = ["napi-6", "channel-api", "promise-api", "try-catch-api"]


[build-dependencies]
tonic-build = "0.9.2"
target-lexicon = "0.12"
dirs = "3.0"
63 changes: 50 additions & 13 deletions toolchain/chidori-core/build.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=./protobufs/DSL_v1.proto");
use dirs::home_dir;
use std::env;
use std::io::{self, Write};
use std::str::FromStr;
use target_lexicon::{OperatingSystem, Triple};

fn add_extension_module_link_args(triple: &Triple) -> io::Result<()> {
let mut writer = io::stdout();
match triple.operating_system {
OperatingSystem::Darwin => {
writeln!(writer, "cargo:rustc-cdylib-link-arg=-undefined")?;
writeln!(writer, "cargo:rustc-cdylib-link-arg=dynamic_lookup")?;

// Assuming the toolchain directory is part of the RUSTUP_HOME environment variable
let home_directory = home_dir().expect("Could not find the home directory");

let rustup_home = env::var("RUSTUP_HOME").unwrap_or_else(|_| {
let default_rustup_path = home_directory.join(".rustup");
eprintln!(
"RUSTUP_HOME not set. Using default: {:?}",
default_rustup_path
);
default_rustup_path.display().to_string()
});

let toolchain_path = format!(
"{}/toolchains/nightly-aarch64-apple-darwin/lib",
rustup_home
);

#[cfg(feature = "build-protos")]
tonic_build::configure()
.out_dir("./src/generated_protobufs")
.build_server(true)
.type_attribute(".", "#[derive(serde::Deserialize, serde::Serialize)]") // adding attributes
.type_attribute(
"promptgraph.ExecutionStatus",
"#[derive(typescript_type_def::TypeDef)]",
) // adding attributes
.compile(&["./protobufs/DSL_v1.proto"], &["./protobufs/"])
.unwrap_or_else(|e| panic!("protobuf compile error: {}", e));
// Setting the RUSTFLAGS environment variable
println!(
"cargo:rustc-env=RUSTFLAGS=-C link-arg=-Wl,-rpath,{}",
toolchain_path
);

// Optional: print out the toolchain path for debugging
println!("Using toolchain path: {}", toolchain_path);
}
_ if triple == &Triple::from_str("wasm32-unknown-emscripten").unwrap() => {
writeln!(writer, "cargo:rustc-cdylib-link-arg=-sSIDE_MODULE=2")?;
writeln!(writer, "cargo:rustc-cdylib-link-arg=-sWASM_BIGINT")?;
}
_ => {}
}
Ok(())
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
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);
Ok(())
}
1 change: 1 addition & 0 deletions toolchain/chidori-core/chidori-core
2 changes: 1 addition & 1 deletion toolchain/chidori-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Chidori is a library for building and running reactive AI agents.",
"main": "package_node/index.js",
"scripts": {
"build": "cargo-cp-artifact -a cdylib _chidori_core ./package_node/native/chidori-core.node -- cargo build --message-format=json-render-diagnostics --features nodejs",
"build": "RUSTFLAGS=\"-C link-arg=-Wl,-rpath,/Users/coltonpierson/.rustup/toolchains/nightly-aarch64-apple-darwin/lib\" cargo-cp-artifact -a cdylib _chidori_core ./package_node/native/chidori-core.node -- cargo build --message-format=json-render-diagnostics",
"build-debug": "npm run build --",
"build-release": "npm run build -- --release",
"test-rust": "cargo test",
Expand Down
7 changes: 7 additions & 0 deletions toolchain/chidori-core/package_node/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ChatCompletionReq } from "./types/ChatCompletionReq"

declare module '@1kbirds/chidori-core' {
export function std_code_rustpython_source_code_run_python(source: string): any;

export function std_ai_llm_openai_batch(api_key: string, payload: ChatCompletionReq): Promise<any>;
}
27 changes: 27 additions & 0 deletions toolchain/chidori-core/package_node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";

const {
std_ai_llm_openai_batch,
std_code_rustpython_source_code_run_python,
} = require("./native/chidori-core.node");

const toSnakeCase = str => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);

const transformKeys = (obj) => {
if (Array.isArray(obj)) {
return obj.map(val => transformKeys(val));
} else if (obj !== null && obj.constructor === Object) {
return Object.keys(obj).reduce((accumulator, key) => {
accumulator[toSnakeCase(key)] = transformKeys(obj[key]);
return accumulator;
}, {});
}
return obj;
};



module.exports = {
std_ai_llm_openai_batch: std_ai_llm_openai_batch,
std_code_rustpython_source_code_run_python: std_code_rustpython_source_code_run_python
};
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { TemplateMessage } from "./TemplateMessage";

export interface ChatCompletionReq { model: string, frequency_penalty: number | null, max_tokens: bigint | null, presence_penalty: number | null, stop: Array<string> | null, temperature: number | null, response_format: any, logit_bias: Record<string, number> | null, user: string | null, seed: bigint | null, top_p: number | null, template_messages: Array<TemplateMessage>, }
3 changes: 3 additions & 0 deletions toolchain/chidori-core/package_node/types/FunctionCall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface FunctionCall { name: string | null, arguments: string | null, }
3 changes: 3 additions & 0 deletions toolchain/chidori-core/package_node/types/MessageRole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type MessageRole = "User" | "System" | "Assistant" | "Function";
5 changes: 5 additions & 0 deletions toolchain/chidori-core/package_node/types/TemplateMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { FunctionCall } from "./FunctionCall";
import type { MessageRole } from "./MessageRole";

export interface TemplateMessage { role: MessageRole, content: string, name: string | null, function_call: FunctionCall | null, }
19 changes: 3 additions & 16 deletions toolchain/chidori-core/src/execution/execution/execution_graph.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
use crate::execution::execution::execution_state::{ExecutionState};
use crate::execution::execution::execution_state::{DependencyGraphMutation, ExecutionState};

use crate::execution::primitives::identifiers::{ArgumentIndex, OperationId};









use petgraph::data::Build;
use petgraph::dot::{Dot};
use petgraph::dot::Dot;

use petgraph::graphmap::DiGraphMap;
use petgraph::visit::{IntoEdgesDirected};
use petgraph::visit::IntoEdgesDirected;
use petgraph::Direction;






// TODO: update all of these identifies to include a "space" they're within

type EdgeIdentity = (OperationId, OperationId, ArgumentIndex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rkyv::{
archived_root,
archived_root, check_archived_root,
ser::{serializers::AllocSerializer, Serializer},
Archive, Deserialize, Serialize,
};
Expand Down
Loading

0 comments on commit 847d487

Please sign in to comment.