-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
2,641 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
chidori-core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
4 changes: 4 additions & 0 deletions
4
toolchain/chidori-core/package_node/types/ChatCompletionReq.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
toolchain/chidori-core/src/execution/execution/execution_graph.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
toolchain/chidori-core/src/execution/primitives/serialized_value.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.