Skip to content

Commit

Permalink
update examples / feature-tour
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidiusdadi committed Apr 25, 2024
1 parent 2f08c84 commit 440fff0
Show file tree
Hide file tree
Showing 22 changed files with 264 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .env.exampe
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ GROQ_BASE_URL=https://api.groq.com/openai/v1
MISTRAL_API_KEY=
MISTRAL_API_MODEL=mistral-medium
MISTRAL_BASE_URL=https://api.mistral.ai/v1



ANTROPIC=
ANTROPIC_API_MODEL=antropic-ai-7b
ANTROPIC_BASE_URL=https://api.antropic.com/v1
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,6 @@ dist
.DS_Store

build
local
local
old
.obsidian
37 changes: 37 additions & 0 deletions examples/feature-tour/1-arrow-propagation/propagation.canvas
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"nodes":[
{"id":"312705e29b96a272","type":"text","text":"start","x":-508,"y":-609,"width":121,"height":60,"color":"6"},
{"id":"79d4cebb7bb90a06","type":"text","text":"Here we print `input` and `state`!\n```ts\nconsole.log(input) // 2\nconsole.log(state.foo) // bar\nreturn 3\n```\n\nWe do not modify `state` - it is however anyways forwarded.","x":-225,"y":-240,"width":470,"height":240},
{"id":"e3d8cad7405cd110","type":"text","text":"```ts\nconsole.log(input) // 3\nconsole.log(state.foo) // bar\nreturn 10\n```","x":-225,"y":120,"width":470,"height":160},
{"id":"74e896e3e37fe457","type":"text","text":"","x":-1097,"y":466,"width":50,"height":50},
{"id":"af7d21a7d4da246a","type":"text","text":"empty node just for a cleaner look.\n`state` and `input` are both forwarded","x":-1030,"y":415,"width":207,"height":153,"color":"5"},
{"id":"a043b5759b55375f","type":"text","text":"```ts\nconsole.log(input) // 7\nconsole.log(state.foo) // B\n\n```","x":-881,"y":200,"width":340,"height":120},
{"id":"ff232e68056c62e7","type":"text","text":"There are 2 special variables:\n- `input` - the value received via an arrow\n- `state` - starting out as `{}` it can be reassigned \n\t- it is [shallowly cloned](https://lodash.com/docs/4.17.15#clone) whenever it is passed on\n```ts\nconsole.log(input) // undefined\nstate = {\n foo: 'bar'\n}\nconst local_var = 'local_var'\nreturn 2\n```","x":-255,"y":-717,"width":500,"height":354},
{"id":"04690b6c718c409b","type":"text","text":"`state` and `input` passed on","x":41,"y":-320,"width":204,"height":60,"color":"5"},
{"id":"2b63c752ded0afb8","type":"text","text":"you will learn - the *boring basics*:\n- how nodes receive input\n- how `state` propagates along arrows\n- how to use arrows\n- how to use **named arrows**\n- how to use the `this` variable","x":-1145,"y":-728,"width":529,"height":238,"color":"5"},
{"id":"dd5b074f7ac37197","type":"text","text":"`emit` is another way to send `state` and `input` along named arrows. \n\n```ts\nconsole.log(input) // 3\nconsole.log(state.foo) // bar\nemit('a', 5)\nstate.foo = 'A'\nemit('b', 6)\nstate.foo = 'B'\nreturn 7\n```","x":-914,"y":-460,"width":406,"height":300},
{"id":"76f7c024f19dd178","type":"text","text":"```ts\nconsole.log(input) // 5\nconsole.log(state.foo) // A\n// return undefined\n```","x":-1145,"y":-20,"width":340,"height":120},
{"id":"1a8f4d78596a33bb","type":"text","text":"```ts\nconsole.log(input) // 6\nconsole.log(state.foo) // B\nreturn input\n```","x":-617,"y":-20,"width":340,"height":120},
{"id":"3c07b23f84c68f41","type":"text","text":"","x":-360,"y":200,"width":50,"height":50},
{"id":"723bbd9e2d66d791","type":"text","text":"different `state` versions passed on","x":-1145,"y":-160,"width":204,"height":60,"color":"5"},
{"id":"3ec3bc45cac87c5c","type":"text","text":"This node will called **5** times - once form each in-arrow.\n```ts\nconsole.log(input) // ...\nconsole.log(state.foo) // ...\n\nemit('x', input)\nemit('x', state.foo)\n\nreturn 42 // this is never used \n```\n\n- the `42` is never used as there is no unnamed outgoing arrow.\n- other ways to await / join incoming arrows will be showin in [[zip-demo.canvas|zip-demo]] and [[zip-and-aggregate.canvas|zip-and-aggregate]]","x":-711,"y":460,"width":470,"height":400,"color":"6"},
{"id":"c318b1f3ef183b07","type":"text","text":"This node will called **10** times.\nAs the `emit` is called 2 times in the previous node.\n\n`this` can be used to preserve a variable across multiple invocations.\n\n```ts\nthis.i = (this.i ?? 0) + 1\n\nconsole.log('called', this.i)\n\nreturn this.i\n```","x":-140,"y":488,"width":385,"height":372}
],
"edges":[
{"id":"67433558d47dc9b1","fromNode":"312705e29b96a272","fromSide":"right","toNode":"ff232e68056c62e7","toSide":"left"},
{"id":"9f417c6d86136d78","fromNode":"ff232e68056c62e7","fromSide":"bottom","toNode":"79d4cebb7bb90a06","toSide":"top"},
{"id":"88ea517f38cb8bb4","fromNode":"79d4cebb7bb90a06","fromSide":"left","toNode":"dd5b074f7ac37197","toSide":"right"},
{"id":"8a9abb41e8e0623e","fromNode":"79d4cebb7bb90a06","fromSide":"bottom","toNode":"e3d8cad7405cd110","toSide":"top"},
{"id":"7939cfc621b90d66","fromNode":"dd5b074f7ac37197","fromSide":"bottom","toNode":"76f7c024f19dd178","toSide":"top","label":"a"},
{"id":"0f86025acaf98d6a","fromNode":"dd5b074f7ac37197","fromSide":"bottom","toNode":"1a8f4d78596a33bb","toSide":"top","label":"b"},
{"id":"0c903cbe31e43c33","fromNode":"dd5b074f7ac37197","fromSide":"bottom","toNode":"a043b5759b55375f","toSide":"top"},
{"id":"7a077fa13115c115","fromNode":"1a8f4d78596a33bb","fromSide":"bottom","toNode":"3ec3bc45cac87c5c","toSide":"top"},
{"id":"24621476d771e47f","fromNode":"e3d8cad7405cd110","fromSide":"bottom","toNode":"3ec3bc45cac87c5c","toSide":"top"},
{"id":"95bac9b4264ee8f2","fromNode":"76f7c024f19dd178","fromSide":"bottom","toNode":"74e896e3e37fe457","toSide":"top"},
{"id":"71d3e167cd0dd9df","fromNode":"74e896e3e37fe457","fromSide":"bottom","toNode":"3ec3bc45cac87c5c","toSide":"left"},
{"id":"d4d4b083fbb342b0","fromNode":"a043b5759b55375f","fromSide":"bottom","toNode":"3ec3bc45cac87c5c","toSide":"top"},
{"id":"c2fef52f6fbcdece","fromNode":"79d4cebb7bb90a06","fromSide":"bottom","toNode":"3c07b23f84c68f41","toSide":"top"},
{"id":"77424283215a8854","fromNode":"3c07b23f84c68f41","fromSide":"bottom","toNode":"3ec3bc45cac87c5c","toSide":"top"},
{"id":"0449712e6fb01b6a","fromNode":"3ec3bc45cac87c5c","fromSide":"right","toNode":"c318b1f3ef183b07","toSide":"left","label":"x"}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"nodes":[
{"id":"367f2fabbc0ee841","type":"text","text":"```ts\nreturn {\n id: 'a', \n key1: 'key1'\n}\n``` ","x":-259,"y":-60,"width":250,"height":140},
{"id":"bfd2de90be95a59c","type":"text","text":"```ts\nreturn {\n id: 'a', \n key2: 'key2'\n}\n``` ","x":40,"y":-60,"width":236,"height":140},
{"id":"335af68f62fea62f","type":"text","text":"```ts\nfor(let i = 0; i <= 10; i++) {\n emit('count', i)\n}\n```","x":583,"y":252,"width":377,"height":128},
{"id":"5fd6841400f9083f","type":"text","text":"```ts\naggregate()\n\nconsole.log('a: counter now', input)\n```","x":358,"y":533,"width":414,"height":167},
{"id":"f0b9fdb709d7430d","type":"text","text":"```ts\nconst inputs = aggregate().list()\n\nconsole.log('counter vals:', inputs)\nconsole.log('b: counter now', input)\n```","x":820,"y":533,"width":480,"height":167},
{"id":"4f3293d8c9e8f499","type":"text","text":"```ts\naggregate()\n```","x":886,"y":958,"width":314,"height":83},
Expand All @@ -16,7 +15,8 @@
{"id":"f34d176e9901212b","type":"text","text":"```ts\nconst obj = zipOnInput('id').merge()\nconsole.log('1. merge on id:', obj)\nreturn obj\n```","x":-103,"y":196,"width":522,"height":120},
{"id":"4542eba5d1247c99","type":"text","text":"```ts\nreturn {\n id: 'a', \n key3: 'key3'\n}\n```","x":-420,"y":380,"width":370,"height":153},
{"id":"26484d7c5e9c5181","type":"text","text":"**log** an aggregate completed","x":415,"y":970,"width":300,"height":60},
{"id":"2bb0a8756165dac5","type":"text","text":"start","x":-59,"y":-400,"width":99,"height":60}
{"id":"2bb0a8756165dac5","type":"text","text":"start","x":-59,"y":-400,"width":99,"height":60},
{"id":"335af68f62fea62f","type":"text","text":"```ts\nfor(let i = 0; i <= 10; i++) {\n emit('count', i)\n}\n```","x":584,"y":252,"width":377,"height":128}
],
"edges":[
{"id":"ebc1fd2def1cc442","fromNode":"2bb0a8756165dac5","fromSide":"bottom","toNode":"95109145540231cf","toSide":"top"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"nodes":[
{"id":"f70bcccd70759f3c","type":"text","text":"**log** callee started","x":-245,"y":-45,"width":250,"height":60},
{"id":"6bcf5525ff11a12b","type":"text","text":"start","x":-173,"y":-200,"width":104,"height":60},
{"id":"2ea2dd4dd04392f4","type":"text","text":"```ts\nstate = 1\nreturn 2\n```","x":-423,"y":125,"width":250,"height":80},
{"id":"2ea2dd4dd04392f4","type":"text","text":"```ts\nstate = 1\nreturn 2\n```","x":-460,"y":125,"width":287,"height":80},
{"id":"cfa4041fa0079c00","type":"text","text":"```ts\nstate = 3\nreturn 4\n```","x":-92,"y":125,"width":303,"height":80},
{"id":"1da991a70beb4502","type":"text","text":"**emit** signal1","x":-423,"y":280,"width":250,"height":60},
{"id":"510bb6758d3f7caf","type":"text","text":"**emit-state** signal2","x":-65,"y":280,"width":250,"height":60},
{"id":"2e15bbe9302389da","type":"text","text":"```ts\naggregate()\n```","x":-280,"y":460,"width":320,"height":60},
{"id":"18a842d2a968ebe1","type":"text","text":"**log** callee is done","x":-245,"y":580,"width":250,"height":60}
{"id":"18a842d2a968ebe1","type":"text","text":"**log** callee is done","x":-245,"y":580,"width":250,"height":60},
{"id":"5d08b8e5b7fd6761","type":"text","text":"**on**: example-in","x":40,"y":-200,"width":200,"height":60},
{"id":"1da991a70beb4502","type":"text","text":"**emit** signal1","x":-441,"y":280,"width":250,"height":60}
],
"edges":[
{"id":"c8c0b29e61c6bac5","fromNode":"6bcf5525ff11a12b","fromSide":"bottom","toNode":"f70bcccd70759f3c","toSide":"top"},
Expand All @@ -17,6 +18,7 @@
{"id":"3d8e90f7d4f4a6f9","fromNode":"2e15bbe9302389da","fromSide":"bottom","toNode":"18a842d2a968ebe1","toSide":"top"},
{"id":"1b28f1e4e6e3973a","fromNode":"f70bcccd70759f3c","fromSide":"bottom","toNode":"cfa4041fa0079c00","toSide":"top"},
{"id":"660fca963ee9d0d0","fromNode":"2ea2dd4dd04392f4","fromSide":"bottom","toNode":"1da991a70beb4502","toSide":"top"},
{"id":"5c6b6af2e768766d","fromNode":"cfa4041fa0079c00","fromSide":"bottom","toNode":"510bb6758d3f7caf","toSide":"top"}
{"id":"5c6b6af2e768766d","fromNode":"cfa4041fa0079c00","fromSide":"bottom","toNode":"510bb6758d3f7caf","toSide":"top"},
{"id":"f8e90a1f306da7db","fromNode":"5d08b8e5b7fd6761","fromSide":"bottom","toNode":"cfa4041fa0079c00","toSide":"top"}
]
}
18 changes: 18 additions & 0 deletions examples/feature-tour/3-canvas-signals/caller.canvas
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"nodes":[
{"id":"38d076dde3453210","type":"text","text":"start","x":-406,"y":-300,"width":104,"height":60},
{"id":"8dadc3e54b9e3466","type":"text","text":"**log** signal1: {{input}}","x":-42,"y":-219,"width":250,"height":60},
{"id":"8aece518d556e700","type":"text","text":"**log** signal2: {{input}}","x":-42,"y":81,"width":250,"height":60},
{"id":"9ccfd075233cc00e","type":"text","text":"","x":-194,"y":-276,"width":54,"height":60},
{"id":"72044e2f556b0ea5","type":"text","text":"**log** aaa","x":-840,"y":-300,"width":233,"height":60},
{"id":"b4dcbb1fd8690ae8","type":"file","file":"feature-tour/3-canvas-signals/callee.canvas","x":-480,"y":-139,"width":252,"height":220}
],
"edges":[
{"id":"870b140a50bd116f","fromNode":"38d076dde3453210","fromSide":"bottom","toNode":"b4dcbb1fd8690ae8","toSide":"top"},
{"id":"fb967c8b3c4298c0","fromNode":"b4dcbb1fd8690ae8","fromSide":"right","toNode":"9ccfd075233cc00e","toSide":"bottom","label":"signal1"},
{"id":"61896b1c3d1ba79a","fromNode":"b4dcbb1fd8690ae8","fromSide":"right","toNode":"8aece518d556e700","toSide":"left","label":"signal2"},
{"id":"ae725e20bedbcff4","fromNode":"38d076dde3453210","fromSide":"left","toNode":"72044e2f556b0ea5","toSide":"right"},
{"id":"5d5cf02302a22109","fromNode":"72044e2f556b0ea5","fromSide":"bottom","toNode":"b4dcbb1fd8690ae8","toSide":"left","label":"example-in"},
{"id":"1cb8bb926c04eb8c","fromNode":"9ccfd075233cc00e","fromSide":"right","toNode":"8dadc3e54b9e3466","toSide":"left"}
]
}
13 changes: 13 additions & 0 deletions examples/feature-tour/4-canvas-overload/caller.canvas
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"nodes":[
{"id":"8e79f5bbfedb7392","type":"file","file":"feature-tour/4-canvas-overload/clock.canvas","x":-380,"y":-160,"width":400,"height":400},
{"id":"7b6e9276abb8733c","type":"text","text":"start","x":-380,"y":-340,"width":116,"height":60},
{"id":"33830d534879be52","type":"text","text":"**log** overload {{input}} & {{ state.id}}.{{ state.iter}}","x":200,"y":-10,"width":420,"height":100},
{"id":"25efc78f9b3de1e1","type":"text","text":"**return**\n","x":220,"y":178,"width":380,"height":62}
],
"edges":[
{"id":"ffd26bb196941b17","fromNode":"7b6e9276abb8733c","fromSide":"right","toNode":"8e79f5bbfedb7392","toSide":"top","label":"kick-off"},
{"id":"897fd8028b33e0f2","fromNode":"33830d534879be52","fromSide":"left","toNode":"8e79f5bbfedb7392","toSide":"right","toEnd":"none","color":"5","label":"action"},
{"id":"80c8c2548241dac7","fromNode":"33830d534879be52","fromSide":"bottom","toNode":"25efc78f9b3de1e1","toSide":"top"}
]
}
19 changes: 19 additions & 0 deletions examples/feature-tour/4-canvas-overload/clock.canvas
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"nodes":[
{"id":"425a66bac331a247","type":"text","text":"```ts\nawait sleep('1000')\nreturn state.iter\n```","x":-820,"y":-140,"width":380,"height":100},
{"id":"403e6f490b6afde6","type":"text","text":"**inject**: action","x":-420,"y":-380,"width":200,"height":80,"color":"6"},
{"id":"a4080def3227bf8a","type":"text","text":"Here we create a loop.\nA caller will need to invoke the `kick-off` and would also provide an **injection** called `action`.","x":-820,"y":-410,"width":340,"height":170,"color":"5"},
{"id":"458edf2d0ed179a0","type":"text","text":"**on**: kick-off","x":-511,"y":-780,"width":200,"height":60,"color":"6"},
{"id":"28ed82dfad8b0a2e","type":"text","text":"```ts\nstate.iter++;\n```","x":-1060,"y":-540,"width":230,"height":80},
{"id":"a724f16ba737ecca","type":"text","text":"```ts\nthis.id = (this.id ?? 0) + 1\nstate = {\n id: this.id,\n iter: 0,\n ...state\n}\n```","x":-1135,"y":-820,"width":380,"height":200},
{"id":"43ab8a173c6227c4","type":"text","text":"**log** injected: {{input}} & {{state | json}}","x":-720,"y":-530,"width":360,"height":70}
],
"edges":[
{"id":"4d71b411254d8345","fromNode":"458edf2d0ed179a0","fromSide":"bottom","toNode":"a724f16ba737ecca","toSide":"right"},
{"id":"4c31d261b8fa7235","fromNode":"a724f16ba737ecca","fromSide":"bottom","toNode":"28ed82dfad8b0a2e","toSide":"top"},
{"id":"d01b6251d2d5b661","fromNode":"28ed82dfad8b0a2e","fromSide":"bottom","toNode":"425a66bac331a247","toSide":"left"},
{"id":"9d0652828304786a","fromNode":"425a66bac331a247","fromSide":"right","toNode":"403e6f490b6afde6","toSide":"bottom"},
{"id":"b7596ebe574dce38","fromNode":"403e6f490b6afde6","fromSide":"top","toNode":"43ab8a173c6227c4","toSide":"right"},
{"id":"1eead511be4a9436","fromNode":"43ab8a173c6227c4","fromSide":"left","toNode":"28ed82dfad8b0a2e","toSide":"right"}
]
}
File renamed without changes
18 changes: 18 additions & 0 deletions examples/feature-tour/shell/bash.canvas
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"nodes":[
{"id":"19dbef8d1cab897c","type":"text","text":"```ts\nreturn {\n question: \"What is my OS version?\"\n}\n```","x":-840,"y":-760,"width":500,"height":120},
{"id":"d1bc397ca9927711","type":"text","text":"```yaml\nmodel: \"gpt-3.5-turbo\"\nmessages:\n - role: \"system\"\n content: >\n\tYou are bash terminal. \n\tThe user specifies his intention.\n\tYou produce the bash code.\n\t\n\tReject all requests to change anything.\n\tNo changes to environment, file or the system in general.\n\tYou are only allowd reading access.\n\tReject requests by just giving `exit 69;`\n\tIf alls good `exit 0`\n\t```\n - role: \"user\"\n content: \"{{input.question}}\"\n```\n\n\n","x":-944,"y":-560,"width":708,"height":420},
{"id":"3c59a61cb36a6eb8","type":"text","text":"```ts\nconst c = this.conv = this.conv ?? []\n\nc.push('>', input.previous.trim())\nc.push('agent:', input.response.trim())\n\nstate.history = c.join('\\n')\n```","x":-160,"y":-198,"width":466,"height":240},
{"id":"3857a7ff0df57bb5","type":"text","text":"**log** {{input}}","x":-833,"y":-78,"width":487,"height":160,"color":"#143bff"},
{"id":"fa8d7baa8a1797da","type":"text","text":"```bash\n{{input}}\n```","x":-717,"y":220,"width":371,"height":140},
{"id":"186bd0d14d6df121","type":"text","text":"**log** {{input}}","x":-702,"y":460,"width":356,"height":68},
{"id":"f9600a39c1822868","type":"text","text":"start","x":-641,"y":-900,"width":103,"height":50}
],
"edges":[
{"id":"820ec138fe03b507","fromNode":"d1bc397ca9927711","fromSide":"bottom","toNode":"3857a7ff0df57bb5","toSide":"top"},
{"id":"7438dd8b0f97ce69","fromNode":"19dbef8d1cab897c","fromSide":"bottom","toNode":"d1bc397ca9927711","toSide":"top"},
{"id":"32eb76533f94559e","fromNode":"f9600a39c1822868","fromSide":"bottom","toNode":"19dbef8d1cab897c","toSide":"top"},
{"id":"24828ec9f5506964","fromNode":"3857a7ff0df57bb5","fromSide":"bottom","toNode":"fa8d7baa8a1797da","toSide":"top"},
{"id":"ee57e5e7787c27ba","fromNode":"fa8d7baa8a1797da","fromSide":"bottom","toNode":"186bd0d14d6df121","toSide":"top","label":"stdout"}
]
}
Loading

0 comments on commit 440fff0

Please sign in to comment.