@1kbirds/chidori 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +77 -0
- package/build.rs +7 -0
- package/package.json +39 -0
- package/package_node/index.d.ts +0 -0
- package/package_node/index.js +96 -0
- package/package_python/.idea/inspectionProfiles/profiles_settings.xml +6 -0
- package/package_python/.idea/misc.xml +4 -0
- package/package_python/.idea/modules.xml +8 -0
- package/package_python/.idea/package_python.iml +8 -0
- package/package_python/.idea/vcs.xml +6 -0
- package/package_python/__init__.py +0 -0
- package/package_python/__pycache__/__init__.cpython-310.pyc +0 -0
- package/package_python/__pycache__/test_chidori.cpython-310-pytest-7.4.0.pyc +0 -0
- package/package_python/__pycache__/test_promptgraph.cpython-310-pytest-7.4.0.pyc +0 -0
- package/package_python/chidori.pyi +30 -0
- package/package_python/py.typed +0 -0
- package/package_python/test_chidori.py +33 -0
- package/pyproject.toml +33 -0
- package/src/lib.rs +22 -0
- package/src/translations/mod.rs +8 -0
- package/src/translations/nodejs.rs +1239 -0
- package/src/translations/python.rs +964 -0
- package/src/translations/rust.rs +177 -0
- package/src/translations/wasm.rs +1 -0
- package/tests/nodejs/chidori.test.js +54 -0
- package/tests/nodejs/nodeHandle.test.js +17 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
use anyhow::Result;
|
|
3
|
+
|
|
4
|
+
use prompt_graph_core::graph_definition::DefinitionGraph;
|
|
5
|
+
use prompt_graph_core::build_runtime_graph::graph_parse::CleanedDefinitionGraph;
|
|
6
|
+
use prompt_graph_core::proto2::execution_runtime_client::ExecutionRuntimeClient;
|
|
7
|
+
use prompt_graph_core::proto2::RequestFileMerge;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
// TODO: need to define pattern for automatically wiring dependencies
|
|
11
|
+
// TODO: add methods
|
|
12
|
+
// create_entrypoint_query
|
|
13
|
+
|
|
14
|
+
pub fn new_graph() -> DefinitionGraph {
|
|
15
|
+
DefinitionGraph::zero()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
#[macro_export]
|
|
19
|
+
macro_rules! register_all {
|
|
20
|
+
($graph:expr, $($statement:expr,)*) => {
|
|
21
|
+
$( $graph.register_node($statement); )*
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#[macro_export]
|
|
26
|
+
macro_rules! parameter {
|
|
27
|
+
($output_def:expr) => {
|
|
28
|
+
create_node_parameter(
|
|
29
|
+
format!("{}:{}", file!(), line!()),
|
|
30
|
+
String::from($output_def)
|
|
31
|
+
)
|
|
32
|
+
};
|
|
33
|
+
($name:expr, $output_def:expr) => {
|
|
34
|
+
create_node_parameter(
|
|
35
|
+
String::from($name),
|
|
36
|
+
String::from($output_def)
|
|
37
|
+
)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#[macro_export]
|
|
42
|
+
macro_rules! map {
|
|
43
|
+
($query_def:expr, $path:expr) => {
|
|
44
|
+
create_op_map(
|
|
45
|
+
format!("{}:{}", file!(), line!()),
|
|
46
|
+
String::from($query_def),
|
|
47
|
+
String::from($path),
|
|
48
|
+
)
|
|
49
|
+
};
|
|
50
|
+
($name:expr, $query_def:expr, $path:expr) => {
|
|
51
|
+
create_code_node(
|
|
52
|
+
String::from($name),
|
|
53
|
+
String::from($query_def),
|
|
54
|
+
String::from($path),
|
|
55
|
+
)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
#[macro_export]
|
|
61
|
+
macro_rules! code_node {
|
|
62
|
+
($query_def:expr, $output_def:expr, $source_type:expr) => {
|
|
63
|
+
create_code_node(
|
|
64
|
+
format!("{}:{}", file!(), line!()),
|
|
65
|
+
String::from($query_def),
|
|
66
|
+
String::from($output_def),
|
|
67
|
+
$source_type,
|
|
68
|
+
)
|
|
69
|
+
};
|
|
70
|
+
($name:expr, $query_def:expr, $output_def:expr, $source_type:expr) => {
|
|
71
|
+
create_code_node(
|
|
72
|
+
String::from($name),
|
|
73
|
+
String::from($query_def),
|
|
74
|
+
String::from($output_def),
|
|
75
|
+
String::from($source_type),
|
|
76
|
+
)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
#[macro_export]
|
|
82
|
+
macro_rules! observation_node {
|
|
83
|
+
($query_def:expr, $output_def:expr) => {
|
|
84
|
+
create_observation_node(
|
|
85
|
+
format!("{}:{}", file!(), line!()),
|
|
86
|
+
String::from($query_def),
|
|
87
|
+
String::from($output_def),
|
|
88
|
+
)
|
|
89
|
+
};
|
|
90
|
+
($name:expr, $query_def:expr, $output_def:expr) => {
|
|
91
|
+
create_observation_node(
|
|
92
|
+
String::from($name),
|
|
93
|
+
String::from($query_def),
|
|
94
|
+
String::from($output_def),
|
|
95
|
+
)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
#[macro_export]
|
|
101
|
+
macro_rules! memory_node {
|
|
102
|
+
($query_def:expr, $output_def:expr, $model:expr, $db:expr) => {
|
|
103
|
+
create_vector_memory_node(
|
|
104
|
+
format!("{}:{}", file!(), line!()),
|
|
105
|
+
String::from($query_def),
|
|
106
|
+
String::from($output_def),
|
|
107
|
+
String::from($model),
|
|
108
|
+
String::from($db)
|
|
109
|
+
)
|
|
110
|
+
};
|
|
111
|
+
($name:expr, $query_def:expr, $output_def:expr, $model:expr, $db:expr) => {
|
|
112
|
+
create_vector_memory_node(
|
|
113
|
+
String::from($name),
|
|
114
|
+
String::from($query_def),
|
|
115
|
+
String::from($output_def),
|
|
116
|
+
String::from($model),
|
|
117
|
+
String::from($db)
|
|
118
|
+
)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
#[macro_export]
|
|
123
|
+
macro_rules! component_node {
|
|
124
|
+
($query_def:expr, $output_def:expr) => {
|
|
125
|
+
create_component_node(
|
|
126
|
+
format!("{}:{}", file!(), line!()),
|
|
127
|
+
String::from($query_def),
|
|
128
|
+
String::from($output_def),
|
|
129
|
+
)
|
|
130
|
+
};
|
|
131
|
+
($name:expr, $query_def:expr, $output_def:expr) => {
|
|
132
|
+
create_component_node(
|
|
133
|
+
String::from($name),
|
|
134
|
+
String::from($query_def),
|
|
135
|
+
String::from($output_def),
|
|
136
|
+
)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#[macro_export]
|
|
141
|
+
macro_rules! prompt_node {
|
|
142
|
+
($query_def:expr, $template:expr, $model:expr) => {
|
|
143
|
+
create_prompt_node(
|
|
144
|
+
format!("{}:{}", file!(), line!()),
|
|
145
|
+
String::from($query_def),
|
|
146
|
+
String::from($template),
|
|
147
|
+
String::from($model),
|
|
148
|
+
)
|
|
149
|
+
};
|
|
150
|
+
($name:expr, $query_def:expr, $template:expr, $model:expr) => {
|
|
151
|
+
create_prompt_node(
|
|
152
|
+
String::from($name),
|
|
153
|
+
String::from($query_def),
|
|
154
|
+
String::from($template),
|
|
155
|
+
String::from($model),
|
|
156
|
+
)
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
pub async fn run_worker(url: String, graph: DefinitionGraph) -> Result<()> {
|
|
161
|
+
// validate the graph
|
|
162
|
+
CleanedDefinitionGraph::new(&graph);
|
|
163
|
+
let file_merge = RequestFileMerge{ file: Some(graph.get_file().clone()), branch: 0, id: "".to_string() };
|
|
164
|
+
let mut client = ExecutionRuntimeClient::connect(url).await?;
|
|
165
|
+
let _response = client.merge(file_merge).await?.into_inner();
|
|
166
|
+
Ok(())
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
#[cfg(test)]
|
|
170
|
+
mod tests {
|
|
171
|
+
use super::new_graph;
|
|
172
|
+
|
|
173
|
+
#[test]
|
|
174
|
+
fn test_new_graph() {
|
|
175
|
+
new_graph();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// https://crates.io/crates/grpc-web-client
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const {Chidori} = require("../..");
|
|
2
|
+
|
|
3
|
+
async function delay(ms) {
|
|
4
|
+
// Returns a promise that resolves after "ms" milliseconds
|
|
5
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
test('initialize without error', () => {
|
|
10
|
+
expect(new Chidori("1", "localhost:9800")).toEqual({"chi": {}});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('coerce to and from structure', async () => {
|
|
14
|
+
const chi = new Chidori("1", "http://localhost:9800");
|
|
15
|
+
chi.startServer()
|
|
16
|
+
expect(chi.objectInterface({
|
|
17
|
+
"id": "1",
|
|
18
|
+
"monotonic_counter": 0,
|
|
19
|
+
"branch": 0
|
|
20
|
+
})).toEqual({
|
|
21
|
+
"id": "1",
|
|
22
|
+
"monotonic_counter": 0,
|
|
23
|
+
"branch": 0
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
test('start server', async () => {
|
|
29
|
+
const chi = new Chidori("21", "http://127.0.0.1:9800");
|
|
30
|
+
await chi.startServer();
|
|
31
|
+
await chi.play(0,0);
|
|
32
|
+
await chi.denoCodeNode({
|
|
33
|
+
name: "InspirationalQuote",
|
|
34
|
+
code: `return {"promptResult": "Believe"}`,
|
|
35
|
+
output: `type InspirationalQuote { promptResult: String }`,
|
|
36
|
+
is_template: true
|
|
37
|
+
});
|
|
38
|
+
await chi.denoCodeNode({
|
|
39
|
+
name: "CodeNode",
|
|
40
|
+
queries: ["query Q { InspirationalQuote { promptResult } }"],
|
|
41
|
+
code: `return {"output": "Here is your quote for " + \`{{InspirationalQuote.promptResult}}\` }`,
|
|
42
|
+
output: `type CodeNode { output: String }`,
|
|
43
|
+
is_template: true
|
|
44
|
+
});
|
|
45
|
+
await delay(1000);
|
|
46
|
+
console.log(await chi.graphStructure())
|
|
47
|
+
expect((await chi.query(`
|
|
48
|
+
query Q { InspirationalQuote { promptResult } }
|
|
49
|
+
`, 0, 100))["values"].length).toBe(1)
|
|
50
|
+
console.log(await chi.query(`
|
|
51
|
+
query Q { CodeNode { output } }
|
|
52
|
+
`, 0, 100))
|
|
53
|
+
});
|
|
54
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const {simpleFun, NodeHandle} = require("../..");
|
|
2
|
+
const {Chidori} = require("../../package_node");
|
|
3
|
+
|
|
4
|
+
test('sdk', () => {
|
|
5
|
+
expect(simpleFun("1")).toBe("1");
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test('adds 1 + 2 to equal 3', () => {
|
|
9
|
+
expect(new NodeHandle()).toEqual({"nh": {}});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('nodehandle query', async () => {
|
|
13
|
+
const chi = new Chidori("1", "http://localhost:9800");
|
|
14
|
+
await chi.startServer();
|
|
15
|
+
const nh = new NodeHandle();
|
|
16
|
+
expect(await nh.query(0, 0)).toEqual({});
|
|
17
|
+
});
|