Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.
Python aiburrchatbot-frameworkdagsgenerative-aigraphshacktoberfestllmopsllmsmlopspersistent-data-structurestate-machinestate-managementvisibility
Fixes cowsay example
Stefan Krawczyk8ef2665e01b0
diff --git a/docs/examples/simple/cowsay.ipynb b/docs/examples/simple/cowsay.ipynbindex edf53656..a65cb543 100644--- a/docs/examples/simple/cowsay.ipynb+++ b/docs/examples/simple/cowsay.ipynb@@ -10,19 +10,17 @@},{"cell_type": "code",- "execution_count": 1,"id": "initial_id","metadata": {- "ExecuteTime": {- "end_time": "2024-03-27T00:12:50.561804Z",- "start_time": "2024-03-27T00:12:50.531039Z"- },"collapsed": true,"jupyter": {"outputs_hidden": true+ },+ "ExecuteTime": {+ "end_time": "2024-12-13T21:01:40.623161Z",+ "start_time": "2024-12-13T21:01:39.314706Z"}},- "outputs": [],"source": ["import random\n","import time\n",@@ -33,23 +31,23 @@"from burr.core import Action, Application, ApplicationBuilder, State, default, expr\n","from burr.core.action import action\n","from burr.lifecycle import PostRunStepHook"- ]+ ],+ "outputs": [],+ "execution_count": 1},{"cell_type": "code",- "execution_count": 3,"id": "9f5b9bfc78851a59","metadata": {- "ExecuteTime": {- "end_time": "2024-03-27T00:13:03.529875Z",- "start_time": "2024-03-27T00:13:03.524449Z"- },"collapsed": false,"jupyter": {"outputs_hidden": false+ },+ "ExecuteTime": {+ "end_time": "2024-12-13T21:01:40.637573Z",+ "start_time": "2024-12-13T21:01:40.632290Z"}},- "outputs": [],"source": ["# create some hooks!\n","class PrintWhatTheCowSaid(PostRunStepHook):\n",@@ -66,28 +64,28 @@" def post_run_step(self, *, state: \"State\", action: \"Action\", **future_kwargs):\n"," if action.name != \"cow_should_say\": # no need to print if we're not saying anything\n"," time.sleep(self.sleep_time)"- ]+ ],+ "outputs": [],+ "execution_count": 2},{"cell_type": "code",- "execution_count": 4,"id": "5b29e9de2ca536b9","metadata": {- "ExecuteTime": {- "end_time": "2024-03-27T00:13:12.756137Z",- "start_time": "2024-03-27T00:13:12.750764Z"- },"collapsed": false,"jupyter": {"outputs_hidden": false+ },+ "ExecuteTime": {+ "end_time": "2024-12-13T21:02:32.928090Z",+ "start_time": "2024-12-13T21:02:32.923286Z"}},- "outputs": [],"source": ["# instantiate actions\n","@action(reads=[], writes=[\"cow_said\"])\n","def cow_said(state: State, say_what: list[str]) -> Tuple[dict, State]:\n",- " said = random.choice(say_what)\n",+ " said = random.choice(say_what) if say_what is not None else None\n"," result = {\"cow_said\": cowsay.get_output_string(\"cow\", said) if say_what is not None else None}\n"," return result, state.update(**result)\n","\n",@@ -96,23 +94,23 @@"def cow_should_speak(state: State) -> Tuple[dict, State]:\n"," result = {\"cow_should_speak\": random.randint(0, 3) == 0}\n"," return result, state.update(**result)\n"- ]+ ],+ "outputs": [],+ "execution_count": 7},{"cell_type": "code",- "execution_count": 5,"id": "271b868317fbbdf4","metadata": {- "ExecuteTime": {- "end_time": "2024-03-27T00:14:10.836543Z",- "start_time": "2024-03-27T00:14:10.829258Z"- },"collapsed": false,"jupyter": {"outputs_hidden": false+ },+ "ExecuteTime": {+ "end_time": "2024-12-13T21:02:33.629009Z",+ "start_time": "2024-12-13T21:02:33.613724Z"}},- "outputs": [],"source": ["# build application\n","hooks = [\n",@@ -139,233 +137,111 @@" .with_hooks(*hooks)\n"," .build()\n",")"- ]+ ],+ "outputs": [],+ "execution_count": 8},{"cell_type": "code",- "execution_count": 6,"id": "794bc0abda9e48ad","metadata": {- "ExecuteTime": {- "end_time": "2024-03-27T00:14:29.829383Z",- "start_time": "2024-03-27T00:14:29.511355Z"- },"collapsed": false,"jupyter": {"outputs_hidden": false+ },+ "ExecuteTime": {+ "end_time": "2024-12-13T21:02:34.796777Z",+ "start_time": "2024-12-13T21:02:34.484247Z"}},+ "source": [+ "app.visualize(include_conditions=True)"+ ],"outputs": [{"data": {- "image/svg+xml": [- "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",- "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",- " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",- "<!-- Generated by graphviz version 9.0.0 (20230911.1827)\n",- " -->\n",- "<!-- Pages: 1 -->\n",- "<svg width=\"192pt\" height=\"209pt\"\n",- " viewBox=\"0.00 0.00 192.02 209.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",- "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 205)\">\n",- "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-205 188.02,-205 188.02,4 -4,4\"/>\n",- "<!-- say_nothing -->\n",- "<g id=\"node1\" class=\"node\">\n",- "<title>say_nothing</title>\n",- "<path fill=\"none\" stroke=\"black\" d=\"M89.27,-201C89.27,-201 31.27,-201 31.27,-201 25.27,-201 19.27,-195 19.27,-189 19.27,-189 19.27,-177 19.27,-177 19.27,-171 25.27,-165 31.27,-165 31.27,-165 89.27,-165 89.27,-165 95.27,-165 101.27,-171 101.27,-177 101.27,-177 101.27,-189 101.27,-189 101.27,-195 95.27,-201 89.27,-201\"/>\n",- "<text text-anchor=\"middle\" x=\"60.27\" y=\"-177.95\" font-family=\"Times,serif\" font-size=\"14.00\">say_nothing</text>\n",- "</g>\n",- "<!-- cow_should_speak -->\n",- "<g id=\"node3\" class=\"node\">\n",- "<title>cow_should_speak</title>\n",- "<path fill=\"none\" stroke=\"black\" d=\"M107.65,-118.5C107.65,-118.5 12.9,-118.5 12.9,-118.5 6.9,-118.5 0.9,-112.5 0.9,-106.5 0.9,-106.5 0.9,-94.5 0.9,-94.5 0.9,-88.5 6.9,-82.5 12.9,-82.5 12.9,-82.5 107.65,-82.5 107.65,-82.5 113.65,-82.5 119.65,-88.5 119.65,-94.5 119.65,-94.5 119.65,-106.5 119.65,-106.5 119.65,-112.5 113.65,-118.5 107.65,-118.5\"/>\n",- "<text text-anchor=\"middle\" x=\"60.27\" y=\"-95.45\" font-family=\"Times,serif\" font-size=\"14.00\">cow_should_speak</text>\n",- "</g>\n",- "<!-- say_nothing->cow_should_speak -->\n",- "<g id=\"edge4\" class=\"edge\">\n",- "<title>say_nothing->cow_should_speak</title>\n",- "<path fill=\"none\" stroke=\"black\" d=\"M58.99,-164.74C58.7,-159.97 58.42,-154.78 58.27,-150 58.04,-142.67 58.04,-140.83 58.27,-133.5 58.31,-132.3 58.35,-131.08 58.41,-129.85\"/>\n",- "<polygon fill=\"black\" stroke=\"black\" points=\"61.88,-130.45 58.91,-120.27 54.89,-130.07 61.88,-130.45\"/>\n",- "</g>\n",- "<!-- say_hello -->\n",- "<g id=\"node2\" class=\"node\">\n",- "<title>say_hello</title>\n",- "<path fill=\"none\" stroke=\"black\" d=\"M82.15,-36C82.15,-36 38.4,-36 38.4,-36 32.4,-36 26.4,-30 26.4,-24 26.4,-24 26.4,-12 26.4,-12 26.4,-6 32.4,0 38.4,0 38.4,0 82.15,0 82.15,0 88.15,0 94.15,-6 94.15,-12 94.15,-12 94.15,-24 94.15,-24 94.15,-30 88.15,-36 82.15,-36\"/>\n",- "<text text-anchor=\"middle\" x=\"60.27\" y=\"-12.95\" font-family=\"Times,serif\" font-size=\"14.00\">say_hello</text>\n",- "</g>\n",- "<!-- say_hello->cow_should_speak -->\n",- "<g id=\"edge2\" class=\"edge\">\n",- "<title>say_hello->cow_should_speak</title>\n",- "<path fill=\"none\" stroke=\"black\" d=\"M93.05,-36.42C97.97,-40.53 102.37,-45.38 105.27,-51 108.63,-57.52 108.63,-60.98 105.27,-67.5 104.09,-69.78 102.67,-71.94 101.06,-73.97\"/>\n",- "<polygon fill=\"black\" stroke=\"black\" points=\"98.65,-71.43 94.11,-81 103.63,-76.35 98.65,-71.43\"/>\n",- "</g>\n",- "<!-- cow_should_speak->say_nothing -->\n",- "<g id=\"edge3\" class=\"edge\">\n",- "<title>cow_should_speak->say_nothing</title>\n",- "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M60.27,-118.93C60.27,-128.95 60.27,-141.78 60.27,-153.25\"/>\n",- "<polygon fill=\"black\" stroke=\"black\" points=\"56.77,-153.02 60.27,-163.02 63.77,-153.02 56.77,-153.02\"/>\n",- "<text text-anchor=\"middle\" x=\"122.15\" y=\"-136.7\" font-family=\"Times,serif\" font-size=\"14.00\">not cow_should_speak</text>\n",- "</g>\n",- "<!-- cow_should_speak->say_hello -->\n",- "<g id=\"edge1\" class=\"edge\">\n",- "<title>cow_should_speak->say_hello</title>\n",- "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M16.41,-82.17C10.87,-78.17 5.95,-73.33 2.52,-67.5 -4.42,-55.72 3.91,-45.49 16.2,-37.49\"/>\n",- "<polygon fill=\"black\" stroke=\"black\" points=\"17.9,-40.55 24.87,-32.57 14.44,-34.46 17.9,-40.55\"/>\n",- "<text text-anchor=\"middle\" x=\"54.65\" y=\"-54.2\" font-family=\"Times,serif\" font-size=\"14.00\">cow_should_speak</text>\n",- "</g>\n",- "</g>\n",- "</svg>\n"- ],+ "image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 12.0.0 (20240704.0754)\n -->\n<!-- Pages: 1 -->\n<svg width=\"200pt\" height=\"211pt\"\n viewBox=\"0.00 0.00 199.93 210.80\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 206.8)\">\n<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-206.8 195.93,-206.8 195.93,4 -4,4\"/>\n<!-- say_nothing -->\n<g id=\"node1\" class=\"node\">\n<title>say_nothing</title>\n<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M103.35,-202.8C103.35,-202.8 33,-202.8 33,-202.8 27,-202.8 21,-196.8 21,-190.8 21,-190.8 21,-178.2 21,-178.2 21,-172.2 27,-166.2 33,-166.2 33,-166.2 103.35,-166.2 103.35,-166.2 109.35,-166.2 115.35,-172.2 115.35,-178.2 115.35,-178.2 115.35,-190.8 115.35,-190.8 115.35,-196.8 109.35,-202.8 103.35,-202.8\"/>\n<text text-anchor=\"middle\" x=\"68.17\" y=\"-178.7\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">say_nothing</text>\n</g>\n<!-- cow_should_speak -->\n<g id=\"node3\" class=\"node\">\n<title>cow_should_speak</title>\n<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M124.35,-119.7C124.35,-119.7 12,-119.7 12,-119.7 6,-119.7 0,-113.7 0,-107.7 0,-107.7 0,-95.1 0,-95.1 0,-89.1 6,-83.1 12,-83.1 12,-83.1 124.35,-83.1 124.35,-83.1 130.35,-83.1 136.35,-89.1 136.35,-95.1 136.35,-95.1 136.35,-107.7 136.35,-107.7 136.35,-113.7 130.35,-119.7 124.35,-119.7\"/>\n<text text-anchor=\"middle\" x=\"68.17\" y=\"-95.6\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">cow_should_speak</text>\n</g>\n<!-- say_nothing->cow_should_speak -->\n<g id=\"edge4\" class=\"edge\">\n<title>say_nothing->cow_should_speak</title>\n<path fill=\"none\" stroke=\"black\" d=\"M66.88,-165.74C66.59,-161.02 66.32,-155.92 66.17,-151.2 65.95,-143.87 65.95,-142.03 66.17,-134.7 66.21,-133.67 66.24,-132.62 66.29,-131.56\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"69.78,-131.84 66.8,-121.67 62.79,-131.48 69.78,-131.84\"/>\n</g>\n<!-- say_hello -->\n<g id=\"node2\" class=\"node\">\n<title>say_hello</title>\n<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M95.47,-36.6C95.47,-36.6 40.88,-36.6 40.88,-36.6 34.88,-36.6 28.88,-30.6 28.88,-24.6 28.88,-24.6 28.88,-12 28.88,-12 28.88,-6 34.88,0 40.88,0 40.88,0 95.47,0 95.47,0 101.47,0 107.47,-6 107.47,-12 107.47,-12 107.47,-24.6 107.47,-24.6 107.47,-30.6 101.47,-36.6 95.47,-36.6\"/>\n<text text-anchor=\"middle\" x=\"68.17\" y=\"-12.5\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">say_hello</text>\n</g>\n<!-- say_hello->cow_should_speak -->\n<g id=\"edge2\" class=\"edge\">\n<title>say_hello->cow_should_speak</title>\n<path fill=\"none\" stroke=\"black\" d=\"M100.96,-36.93C105.88,-41.07 110.28,-45.95 113.17,-51.6 116.52,-58.12 116.52,-61.58 113.17,-68.1 112,-70.39 110.57,-72.56 108.97,-74.6\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"106.52,-72.1 102.02,-81.69 111.52,-77 106.52,-72.1\"/>\n</g>\n<!-- cow_should_speak->say_nothing -->\n<g id=\"edge3\" class=\"edge\">\n<title>cow_should_speak->say_nothing</title>\n<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M68.17,-119.96C68.17,-130.05 68.17,-142.98 68.17,-154.53\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"64.68,-154.39 68.18,-164.39 71.68,-154.39 64.68,-154.39\"/>\n<text text-anchor=\"middle\" x=\"130.05\" y=\"-137.9\" font-family=\"Times,serif\" font-size=\"14.00\">not cow_should_speak</text>\n</g>\n<!-- cow_should_speak->say_hello -->\n<g id=\"edge1\" class=\"edge\">\n<title>cow_should_speak->say_hello</title>\n<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M25.76,-82.82C12.58,-74.62 3.19,-63.94 10.42,-51.6 12.84,-47.48 16,-43.84 19.6,-40.64\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"21.46,-43.61 27.42,-34.85 17.3,-37.99 21.46,-43.61\"/>\n<text text-anchor=\"middle\" x=\"62.55\" y=\"-54.8\" font-family=\"Times,serif\" font-size=\"14.00\">cow_should_speak</text>\n</g>\n</g>\n</svg>\n","text/plain": [- "<graphviz.graphs.Digraph at 0x1107a98a0>"+ "<graphviz.graphs.Digraph at 0x128b199c0>"]},- "execution_count": 6,+ "execution_count": 9,"metadata": {},"output_type": "execute_result"}],- "source": [- "app.visualize(include_conditions=True)"- ]+ "execution_count": 9},{"cell_type": "code",- "execution_count": 11,"id": "2facfb753233cd7d","metadata": {- "ExecuteTime": {- "end_time": "2024-03-27T00:16:40.234406Z",- "start_time": "2024-03-27T00:16:32.211734Z"- },"collapsed": false,"jupyter": {"outputs_hidden": false+ },+ "ExecuteTime": {+ "end_time": "2024-12-13T21:02:43.025443Z",+ "start_time": "2024-12-13T21:02:35.007367Z"}},- "outputs": [- {- "name": "stdout",- "output_type": "stream",- "text": [- " ____________\n",- "| Hello world! |\n",- " ============\n",- " \\\n",- " \\\n",- " ^__^\n",- " (oo)\\_______\n",- " (__)\\ )\\/\\\n",- " ||----w |\n",- " || ||\n",- " ____________\n",- "| Hello world! |\n",- " ============\n",- " \\\n",- " \\\n",- " ^__^\n",- " (oo)\\_______\n",- " (__)\\ )\\/\\\n",- " ||----w |\n",- " || ||\n",- " ____________\n",- "| Hello world! |\n",- " ============\n",- " \\\n",- " \\\n",- " ^__^\n",- " (oo)\\_______\n",- " (__)\\ )\\/\\\n",- " ||----w |\n",- " || ||\n",- " ____________\n",- "| Hello world! |\n",- " ============\n",- " \\\n",- " \\\n",- " ^__^\n",- " (oo)\\_______\n",- " (__)\\ )\\/\\\n",- " ||----w |\n",- " || ||\n"- ]- }- ],"source": ["# run things!\n","for i in range(0, 4):\n"," # step through 4 times\n"," a_obj, result, state = app.step()"- ]+ ],+ "outputs": [],+ "execution_count": 10},{"cell_type": "code",- "execution_count": 16,"id": "fed65721e7cc457a","metadata": {- "ExecuteTime": {- "end_time": "2024-03-27T00:17:18.640978Z",- "start_time": "2024-03-27T00:17:10.619878Z"- },"collapsed": false,"jupyter": {"outputs_hidden": false+ },+ "ExecuteTime": {+ "end_time": "2024-12-13T21:02:51.055716Z",+ "start_time": "2024-12-13T21:02:43.033412Z"}},+ "source": [+ "# Run some more\n",+ "for i in range(0, 4):\n",+ " # step through 4 times\n",+ " a_obj, result, state = app.step()"+ ],"outputs": [{"name": "stdout","output_type": "stream","text": [- " ________________________\n",- "| Are you Aaron Burr, sir? |\n",- " ========================\n",- " \\\n",- " \\\n",- " ^__^\n",- " (oo)\\_______\n",- " (__)\\ )\\/\\\n",- " ||----w |\n",- " || ||\n",- " ________________________\n",- "| Are you Aaron Burr, sir? |\n",- " ========================\n",- " \\\n",- " \\\n",- " ^__^\n",- " (oo)\\_______\n",- " (__)\\ )\\/\\\n",- " ||----w |\n",- " || ||\n",- " ____________\n",- "| Hello world! |\n",- " ============\n",- " \\\n",- " \\\n",- " ^__^\n",- " (oo)\\_______\n",- " (__)\\ )\\/\\\n",- " ||----w |\n",- " || ||\n",- " ____________\n",- "| Hello world! |\n",- " ============\n",- " \\\n",- " \\\n",- " ^__^\n",- " (oo)\\_______\n",- " (__)\\ )\\/\\\n",- " ||----w |\n",- " || ||\n"+ " __________\n",+ "| What's up? |\n",+ " ==========\n",+ " \\\n",+ " \\\n",+ " ^__^\n",+ " (oo)\\_______\n",+ " (__)\\ )\\/\\\n",+ " ||----w |\n",+ " || ||\n",+ " __________\n",+ "| What's up? |\n",+ " ==========\n",+ " \\\n",+ " \\\n",+ " ^__^\n",+ " (oo)\\_______\n",+ " (__)\\ )\\/\\\n",+ " ||----w |\n",+ " || ||\n"]}],- "source": [- "# Run some more\n",- "for i in range(0, 4):\n",- " # step through 4 times\n",- " a_obj, result, state = app.step()"- ]+ "execution_count": 11},{"cell_type": "code",