@1kbirds/chidori 0.1.21 → 0.1.23

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 CHANGED
@@ -53,7 +53,6 @@ pyo3-log = { version = "0.8.2", optional = true }
53
53
 
54
54
  neon-serde3 = "0.10.0"
55
55
 
56
- tracing = "0.1"
57
56
 
58
57
  [dependencies.prompt-graph-exec]
59
58
  path = "../prompt-graph-exec"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1kbirds/chidori",
3
- "version": "v0.1.21",
3
+ "version": "v0.1.23",
4
4
  "description": "Chidori is a library for building and running reactive AI agents.",
5
5
  "main": "package_node/index.js",
6
6
  "scripts": {
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
2
 
3
- const { promisify } = require("util");
4
-
5
3
  const {
6
4
  simpleFun,
7
- nodehandleDebugExample,
8
5
  nodehandleRunWhen,
9
6
  nodehandleQuery,
10
7
  chidoriNew,
@@ -15,21 +12,37 @@ const {
15
12
  chidoriBranch,
16
13
  chidoriQuery,
17
14
  chidoriGraphStructure,
18
- chidoriCustomNode,
19
- chidoriDenoCodeNode,
20
- chidoriVectorMemoryNode
15
+ chidoriRegisterCustomNodeHandle,
16
+ chidoriRunCustomNodeLoop,
17
+ graphbuilderNew,
18
+ graphbuilderCustomNode,
19
+ graphbuilderPromptNode,
20
+ graphbuilderDenoCodeNode,
21
+ graphbuilderVectorMemoryNode,
22
+ graphbuilderCommit
21
23
  } = require("./native/chidori.node");
22
24
 
25
+ const toSnakeCase = str => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
23
26
 
27
+ const transformKeys = (obj) => {
28
+ if (Array.isArray(obj)) {
29
+ return obj.map(val => transformKeys(val));
30
+ } else if (obj !== null && obj.constructor === Object) {
31
+ return Object.keys(obj).reduce((accumulator, key) => {
32
+ accumulator[toSnakeCase(key)] = transformKeys(obj[key]);
33
+ return accumulator;
34
+ }, {});
35
+ }
36
+ return obj;
37
+ };
24
38
 
25
- // Wrapper class for the boxed `Database` for idiomatic JavaScript usage
26
39
  class NodeHandle {
27
- constructor() {
28
- this.nh = nodehandleDebugExample();
40
+ constructor(nh) {
41
+ this.nh = nh;
29
42
  }
30
43
 
31
- runWhen(otherNodeHandle) {
32
- return nodehandleRunWhen.call(this.nh, otherNodeHandle);
44
+ runWhen(graphBuilder, otherNodeHandle) {
45
+ return nodehandleRunWhen.call(this.nh, graphBuilder.g, otherNodeHandle.nh);
33
46
  }
34
47
 
35
48
  query(branch, frame) {
@@ -43,8 +56,8 @@ class Chidori {
43
56
  this.chi = chidoriNew(fileId, url);
44
57
  }
45
58
 
46
- startServer() {
47
- return chidoriStartServer.call(this.chi);
59
+ startServer(filePath) {
60
+ return chidoriStartServer.call(this.chi, filePath);
48
61
  }
49
62
 
50
63
  objectInterface(executionStatus) {
@@ -55,7 +68,7 @@ class Chidori {
55
68
  return chidoriPlay.call(this.chi, branch, frame);
56
69
  }
57
70
 
58
- pause() {
71
+ pause(branch, frame) {
59
72
  return chidoriPause.call(this.chi, branch, frame);
60
73
  }
61
74
 
@@ -63,34 +76,55 @@ class Chidori {
63
76
  return chidoriQuery.call(this.chi, query, branch, frame)
64
77
  }
65
78
 
66
- branch() {
79
+ branch(branch, frame) {
67
80
  return chidoriBranch.call(this.chi, branch, frame);
68
81
  }
69
82
 
70
- graphStructure() {
71
- return chidoriGraphStructure.call(this.chi);
83
+ graphStructure(branch) {
84
+ return chidoriGraphStructure.call(this.chi, branch);
85
+ }
86
+
87
+ registerCustomNodeHandle(nodeTypeName, handle) {
88
+ // TODO: we actually pass a callback to the function provided by the user, which they invoke with their result
89
+ return chidoriRegisterCustomNodeHandle.call(this.chi, nodeTypeName, handle);
90
+ }
91
+
92
+ runCustomNodeLoop() {
93
+ return chidoriRunCustomNodeLoop.call(this.chi);
72
94
  }
73
95
 
74
- objInterface() {
75
- return chidoriObjInterface.call(this.chi, branch, frame);
96
+ }
97
+
98
+ class GraphBuilder {
99
+ constructor() {
100
+ this.g = graphbuilderNew();
76
101
  }
77
102
 
78
- customNode(customNodeCreateOpts) {
79
- return chidoriCustomNode.call(this.chi, createCustomNodeOpts);
103
+ customNode(createCustomNodeOpts) {
104
+ return new NodeHandle(graphbuilderCustomNode.call(this.g, transformKeys(createCustomNodeOpts)));
105
+ }
106
+
107
+ promptNode(promptNodeCreateOpts) {
108
+ return new NodeHandle(graphbuilderPromptNode.call(this.g, transformKeys(promptNodeCreateOpts)));
80
109
  }
81
110
 
82
111
  denoCodeNode(denoCodeNodeCreateOpts) {
83
- return chidoriDenoCodeNode.call(this.chi, denoCodeNodeCreateOpts);
112
+ return new NodeHandle(graphbuilderDenoCodeNode.call(this.g, transformKeys(denoCodeNodeCreateOpts)));
84
113
  }
85
114
 
86
115
  vectorMemoryNode(vectorMemoryNodeCreateOpts) {
87
- return chidoriVectorMemoryNode.call(this.chi, vectorMemoryNodeCreateOpts);
116
+ return new NodeHandle(graphbuilderVectorMemoryNode.call(this.g, transformKeys(vectorMemoryNodeCreateOpts)));
117
+ }
118
+
119
+ commit(chidori) {
120
+ return graphbuilderCommit.call(this.g, chidori.chi, 0);
88
121
  }
89
122
  }
90
123
 
91
124
 
92
125
  module.exports = {
93
126
  Chidori: Chidori,
127
+ GraphBuilder: GraphBuilder,
94
128
  NodeHandle: NodeHandle,
95
129
  simpleFun: simpleFun
96
130
  };
@@ -2,13 +2,6 @@ from __future__ import annotations
2
2
 
3
3
  from typing import *
4
4
 
5
- class NodeHandle:
6
- def get_name(self) -> str: ...
7
- def run_when(self, node_handle: Optional[NodeHandle]) -> None: ...
8
- def query(self, branch: int, frame: int) -> None: ...
9
- def __str__(self) -> str: ...
10
- def __repr__(self) -> str: ...
11
-
12
5
  class Chidori:
13
6
  def start_server(self, file_path: Optional[str]) -> None: ...
14
7
  def play(self, branch: int, frame: int) -> None: ...
@@ -20,11 +13,20 @@ class Chidori:
20
13
  def list_registered_graphs(self) -> None: ...
21
14
  def list_input_proposals(self) -> None: ...
22
15
  def list_change_events(self, callback: object) -> None: ...
23
- def load_zip_file(self, name: str, output_tables: List[str], output: str, bytes: bytes) -> None: ...
24
- def prompt_node(self, name: str, queries: List[Optional[str]], output_tables: List[str], template: str, model: str) -> None: ...
25
16
  def poll_local_code_node_execution(self) -> None: ...
26
17
  def ack_local_code_node_execution(self, branch: int, counter: int) -> None: ...
27
18
  def respond_local_code_node_execution(self, branch: int, counter: int, node_name: str, response: Optional[object]) -> None: ...
19
+
20
+ class GraphBuilder:
28
21
  def custom_node(self, name: str, queries: List[Optional[str]], output_tables: List[str], output: str, node_type_name: str) -> None: ...
29
22
  def deno_code_node(self, name: str, queries: List[Optional[str]], output_tables: List[str], output: str, code: str, is_template: bool) -> None: ...
30
23
  def vector_memory_node(self, name: str, queries: List[Optional[str]], output_tables: List[str], output: str, template: str, action: str, embedding_model: str, db_vendor: str, collection_name: str) -> None: ...
24
+ def prompt_node(self, name: str, queries: List[Optional[str]], output_tables: List[str], template: str, model: str) -> None: ...
25
+ def commit(self, c: Chidori, branch: int) -> None: ...
26
+
27
+ class NodeHandle:
28
+ def get_name(self) -> str: ...
29
+ def run_when(self, node_handle: Optional[NodeHandle]) -> None: ...
30
+ def query(self, branch: int, frame: int) -> None: ...
31
+ def __str__(self) -> str: ...
32
+ def __repr__(self) -> str: ...
@@ -1,19 +1,20 @@
1
1
  import pytest
2
2
  from unittest.mock import AsyncMock, MagicMock
3
- from chidori import Chidori
3
+ from chidori import Chidori, GraphBuilder
4
4
 
5
5
 
6
6
  @pytest.mark.asyncio
7
7
  async def test_simple_agent():
8
8
  client = Chidori("100", "http://localhost:9800")
9
+ g = GraphBuilder()
9
10
  await client.start_server(":memory:")
10
- await client.deno_code_node(
11
+ await g.deno_code_node(
11
12
  name="InspirationalQuote",
12
13
  code="""
13
14
  return {"promptResult": "placeholder for openai call" }
14
15
  """
15
16
  )
16
- pn = await client.deno_code_node(
17
+ pn = await g.deno_code_node(
17
18
  name="CodeNode",
18
19
  queries=["""
19
20
  query Q {
@@ -27,8 +28,8 @@ async def test_simple_agent():
27
28
  """,
28
29
  is_template=True
29
30
  )
30
- await client.play(0, 0)
31
- await pn.query(0, 100)
31
+ # await g.commit(client, 0)
32
+ # await client.play(0, 0)
32
33
  assert 1 == 1
33
34
 
34
35
 
package/src/lib.rs CHANGED
@@ -2,8 +2,9 @@ extern crate protobuf;
2
2
  extern crate neon_serde3;
3
3
  pub mod translations;
4
4
 
5
- use prompt_graph_core::proto2::{ChangeValue, Path, SerializedValue};
6
- use prompt_graph_core::proto2::serialized_value::Val;
5
+ pub use prompt_graph_core::proto2::{ChangeValue, Path, SerializedValue};
6
+ pub use prompt_graph_core::proto2::serialized_value::Val;
7
+ pub use prompt_graph_core::proto2::*;
7
8
 
8
9
 
9
10
  /// Our local server implementation is an extension of this. Implementing support for multiple
@@ -5,4 +5,5 @@ mod python;
5
5
  pub mod nodejs;
6
6
 
7
7
  mod wasm;
8
- mod rust;
8
+ pub mod rust;
9
+ mod shared;