Skip to content

Commit

Permalink
Use dataclass
Browse files Browse the repository at this point in the history
  • Loading branch information
badgeir committed Aug 23, 2024
1 parent 7d53e4a commit e833aef
Showing 1 changed file with 56 additions and 19 deletions.
75 changes: 56 additions & 19 deletions examples/notebooks/simple_task_manager.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []"
]
Expand Down Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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": {
Expand Down

0 comments on commit e833aef

Please sign in to comment.