Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

Fix conversational RAG example for collab

Stefan Krawczykc3810dcf5a4a
diff --git a/examples/conversational-rag/notebook.ipynb b/examples/conversational-rag/notebook.ipynb
index ca7dca3d..b7799cb8 100644
--- a/examples/conversational-rag/notebook.ipynb
+++ b/examples/conversational-rag/notebook.ipynb
@@ -47,7 +47,6 @@
"import burr.core\n",
"from burr.core import ApplicationBuilder, State, default, expr\n",
"from burr.core.action import action\n",
- "from application import PrintStepHook # local import from application.py\n",
"from burr.tracking import LocalTrackingClient"
]
},
@@ -335,6 +334,50 @@
" return {\"question\": user_question}, state"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "4439e0dd39441414",
+ "metadata": {
+ "collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ }
+ },
+ "source": [
+ "# Add a hook to print the steps -- optional but shows that Burr is pluggable"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "e3c3af84fab14f39",
+ "metadata": {
+ "collapsed": false,
+ "jupyter": {
+ "outputs_hidden": false
+ }
+ },
+ "outputs": [],
+ "source": [
+ "from burr.core import Action\n",
+ "from burr.lifecycle import PostRunStepHook, PreRunStepHook\n",
+ "\n",
+ "class PrintStepHook(PostRunStepHook, PreRunStepHook):\n",
+ " \"\"\"Custom hook to print the action/result after each step.\"\"\"\n",
+ "\n",
+ " def pre_run_step(self, action: Action, **future_kwargs):\n",
+ " if action.name == \"ai_converse\":\n",
+ " print(\"🤔 AI is thinking...\")\n",
+ " if action.name == \"human_converse\":\n",
+ " print(\"⏳Processing input from user...\")\n",
+ "\n",
+ " def post_run_step(self, *, state: \"State\", action: Action, result: dict, **future_kwargs):\n",
+ " if action.name == \"human_converse\":\n",
+ " print(\"🎙💬\", result[\"question\"], \"\\n\")\n",
+ " if action.name == \"ai_converse\":\n",
+ " print(\"🤖💬\", result[\"conversational_rag_response\"], \"\\n\")"
+ ]
+ },
{
"cell_type": "markdown",
"id": "9579b47aac2c53a0",