From e833aef2bec2b697f2fd042d37444b72f33e6c1c Mon Sep 17 00:00:00 2001 From: Peter Leupi Date: Fri, 23 Aug 2024 02:14:11 +0200 Subject: [PATCH] Use dataclass --- examples/notebooks/simple_task_manager.ipynb | 75 +++++++++++++++----- 1 file changed, 56 insertions(+), 19 deletions(-) diff --git a/examples/notebooks/simple_task_manager.ipynb b/examples/notebooks/simple_task_manager.ipynb index 2d14dc8..8c0e27e 100644 --- a/examples/notebooks/simple_task_manager.ipynb +++ b/examples/notebooks/simple_task_manager.ipynb @@ -26,17 +26,18 @@ "metadata": {}, "outputs": [], "source": [ - "from pydantic import BaseModel\n", + "from dataclasses import dataclass\n", "from typing import Literal\n", "\n", "\n", - "# Define task model\n", - "class Task(BaseModel):\n", + "@dataclass\n", + "class Task:\n", " id: int\n", " name: str\n", " description: str\n", " status: Literal[\"todo\", \"doing\", \"done\"] = \"todo\"\n", "\n", + "\n", "# (for demonstration purposes) Define a list of tasks\n", "TASKS: list[Task] = []" ] @@ -170,7 +171,7 @@ "output_type": "stream", "text": [ "** Listing tasks\n", - "** Bot: You currently have no tasks listed. Would you like to add a new task?\n" + "** Bot: It seems you don't have any tasks currently. Would you like to add a new task?\n" ] }, { @@ -233,14 +234,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "** Adding task 'Grocery Shopping' with status 'todo'\n", - "** Bot (message_handler): 'I have added your grocery shopping task. If you need anything else, just let me know!'\n" + "** Adding task 'Grocery' with status 'todo'\n", + "** Bot (message_handler): 'I've added a grocery task to buy eggs, bacon, bread, tomatoes, and orange juice. If you need anything else, feel free to let me know!'\n" ] }, { "data": { "text/plain": [ - "[Task(id=1, name='Grocery Shopping', description='Buy eggs, bacon, bread, tomatoes and orange juice', status='todo')]" + "[Task(id=1, name='Grocery', description='Buy eggs, bacon, bread, tomatoes and orange juice', status='todo')]" ] }, "execution_count": 7, @@ -263,15 +264,15 @@ "name": "stdout", "output_type": "stream", "text": [ - "** Adding task 'Clean the House' with status 'todo'\n", - "** Bot (message_handler): 'I have added the task to clean the house. If you have any more tasks or need further assistance, feel free to ask!'\n" + "** Adding task 'Clean the house' with status 'todo'\n", + "** Bot (message_handler): 'I've added the task to clean the house. If there's anything more you'd like to do, just let me know!'\n" ] }, { "data": { "text/plain": [ - "[Task(id=1, name='Grocery Shopping', description='Buy eggs, bacon, bread, tomatoes and orange juice', status='todo'),\n", - " Task(id=2, name='Clean the House', description='Thoroughly clean all rooms in the house.', status='todo')]" + "[Task(id=1, name='Grocery', description='Buy eggs, bacon, bread, tomatoes and orange juice', status='todo'),\n", + " Task(id=2, name='Clean the house', description='Thoroughly clean all rooms including dusting, vacuuming, and mopping.', status='todo')]" ] }, "execution_count": 8, @@ -295,14 +296,14 @@ "output_type": "stream", "text": [ "** Updating task 1\n", - "** Bot (message_handler): 'I have updated the grocery shopping task to include milk. If there's anything else you need, just let me know!'\n" + "** Bot (message_handler): 'I've updated the grocery task to include milk. If you need any further assistance, just let me know!'\n" ] }, { "data": { "text/plain": [ - "[Task(id=1, name='Grocery Shopping', description='Buy eggs, bacon, bread, tomatoes, orange juice, and milk', status='todo'),\n", - " Task(id=2, name='Clean the House', description='Thoroughly clean all rooms in the house.', status='todo')]" + "[Task(id=1, name='Grocery', description='Buy eggs, bacon, bread, tomatoes, orange juice, and milk', status='todo'),\n", + " Task(id=2, name='Clean the house', description='Thoroughly clean all rooms including dusting, vacuuming, and mopping.', status='todo')]" ] }, "execution_count": 9, @@ -326,14 +327,14 @@ "output_type": "stream", "text": [ "** Updating task 1\n", - "** Bot (message_handler): 'The grocery task has been marked as done. If you have any more tasks or need assistance, feel free to let me know!'\n" + "** Bot (message_handler): 'I've marked the grocery task as done. If there's anything else you'd like to manage or update, feel free to ask!'\n" ] }, { "data": { "text/plain": [ - "[Task(id=1, name='Grocery Shopping', description='Buy eggs, bacon, bread, tomatoes, orange juice, and milk', status='done'),\n", - " Task(id=2, name='Clean the House', description='Thoroughly clean all rooms in the house.', status='todo')]" + "[Task(id=1, name='Grocery', description='Buy eggs, bacon, bread, tomatoes, orange juice, and milk', status='done'),\n", + " Task(id=2, name='Clean the house', description='Thoroughly clean all rooms including dusting, vacuuming, and mopping.', status='todo')]" ] }, "execution_count": 10, @@ -357,13 +358,13 @@ "output_type": "stream", "text": [ "** Removing task 1\n", - "** Bot (message_handler): 'The completed grocery task has been removed. Now, you only have the task to clean the house. If you need anything else, just let me know!'\n" + "** Bot (message_handler): 'I've removed the completed grocery task. If you need help with anything else, just let me know!'\n" ] }, { "data": { "text/plain": [ - "[Task(id=2, name='Clean the House', description='Thoroughly clean all rooms in the house.', status='todo')]" + "[Task(id=2, name='Clean the house', description='Thoroughly clean all rooms including dusting, vacuuming, and mopping.', status='todo')]" ] }, "execution_count": 11, @@ -376,6 +377,42 @@ "\n", "TASKS" ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "** Listing tasks\n", + "** Bot (message_handler): 'You currently have one task:\n", + "\n", + "1. **Clean the house**\n", + " - Description: Thoroughly clean all rooms including dusting, vacuuming, and mopping.\n", + " - Status: To Do\n", + "\n", + "If you need to update or add anything, just let me know!'\n" + ] + }, + { + "data": { + "text/plain": [ + "[Task(id=2, name='Clean the house', description='Thoroughly clean all rooms including dusting, vacuuming, and mopping.', status='todo')]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response = await agent.speak(\"can you list my current tasks?\", history=response.history)\n", + "\n", + "TASKS" + ] } ], "metadata": {