-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- introspection protocol - more nodes - arrows into sub canvas - library build - factor out experimental dependency bloat - add library build target
- Loading branch information
1 parent
0520c15
commit 52312a8
Showing
23 changed files
with
538 additions
and
26 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
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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {GlobalContext} from "./types" | ||
import {parseCanvas} from "./compile/parse-canvas" | ||
import {execCanvas} from "./runtime/exec-canvas" | ||
import {ExecutableCanvas} from "./runtime/ExecutableCanvas" | ||
import {Introspection} from "./runtime/runtime-types" | ||
|
||
|
||
export const createCanvasEngine = async (vault_dir: string, canvas_path: string, introspection: Introspection) => { | ||
let global_context: GlobalContext = { | ||
vault_dir, | ||
loaded_files: {} | ||
} | ||
global_context.introspection = introspection | ||
let node_data = await parseCanvas(canvas_path, global_context) | ||
await execCanvas(new ExecutableCanvas(canvas_path, node_data), global_context) | ||
} |
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
4 changes: 3 additions & 1 deletion
4
packages/canvas-engine/src/node_library/magic-word/canvas-io/index.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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import emitInput from "./emit-input" | ||
import emitState from "./emit-state" | ||
import on from "./on" | ||
|
||
export default [ | ||
emitInput, | ||
emitState | ||
emitState, | ||
on | ||
] |
16 changes: 16 additions & 0 deletions
16
packages/canvas-engine/src/node_library/magic-word/canvas-io/on.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,16 @@ | ||
import {NodeCompiler} from "../../../compile/template" | ||
import {NodeReturnNotIntendedByDesign} from "../../../runtime/errors" | ||
|
||
|
||
export default { | ||
magic_word: true, | ||
lang: 'on', | ||
compile: async (code) => { | ||
return (ctx) => { | ||
if (ctx.frame.edge?.label?.trim() === code.trim()) { | ||
return ctx.input | ||
} | ||
throw new NodeReturnNotIntendedByDesign() | ||
} | ||
} | ||
} satisfies NodeCompiler |
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
6 changes: 6 additions & 0 deletions
6
packages/canvas-engine/src/node_library/magic-word/llm/index.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,6 @@ | ||
import lchain from "./lchain" | ||
|
||
|
||
export default [ | ||
lchain | ||
] |
48 changes: 48 additions & 0 deletions
48
packages/canvas-engine/src/node_library/magic-word/llm/lchain.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,48 @@ | ||
import {NodeCompiler} from "../../../compile/template" | ||
import {logger} from "../../../globals" | ||
import {template_render} from "../../lang/yaml" | ||
import chalk from "chalk" | ||
import {ChatOllama} from "@langchain/community/chat_models/ollama"; | ||
import {StringOutputParser} from "@langchain/core/output_parsers"; | ||
import {HumanMessage} from "@langchain/core/messages"; | ||
import {zRLLMChunk, zRUpdate} from "../../../runtime/inspection/protocol" | ||
import {z} from "zod" | ||
|
||
|
||
const model_ollama_gemma = new ChatOllama({ | ||
baseUrl: "http://localhost:11434", // Default value | ||
model: "gemma", // Default value | ||
}); | ||
|
||
|
||
|
||
export default { | ||
lang: 'lchain', | ||
magic_word: true, | ||
compile: async (code) => { | ||
return async (ctx) => { | ||
const final_prompt = template_render(code, ctx).trim() | ||
logger.debug(`${chalk.green('llm-prompt')}: `, chalk.gray(final_prompt)) | ||
|
||
const stream = await model_ollama_gemma | ||
.pipe(new StringOutputParser()) | ||
.stream([ | ||
new HumanMessage(final_prompt) | ||
]) | ||
|
||
|
||
const chunks: string[] = [] | ||
for await (const message of stream) { | ||
process.stdout.write(message) | ||
chunks.push(message) | ||
ctx.gctx.introspection?.inform({ | ||
type: 'llm-chunk', | ||
chunk: message, | ||
frame_id: ctx.frame.id | ||
} satisfies z.input<typeof zRLLMChunk>) | ||
} | ||
|
||
return chunks.join('') | ||
} | ||
} | ||
} satisfies NodeCompiler |
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
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,15 @@ | ||
# example-call-canvas | ||
|
||
To install dependencies: | ||
|
||
```bash | ||
bun install | ||
``` | ||
|
||
To run: | ||
|
||
```bash | ||
bun run index.ts | ||
``` | ||
|
||
This project was created using `bun init` in bun v1.0.26. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. |
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 @@ | ||
console.log("Hello via Bun!"); |
Oops, something went wrong.