Skip to content

Commit

Permalink
Fix conversational RAG example for collab
Browse files Browse the repository at this point in the history
An import wont work because google collab doesn't load
surrounding files.
  • Loading branch information
skrawcz committed Apr 19, 2024
1 parent e38b5e7 commit c3810dc
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion examples/conversational-rag/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit c3810dc

Please sign in to comment.