Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BFCL] Added reading_manager_api for multi-turn for BFCL #695

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions reading_manager_api.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "e23c929f-bdeb-4b13-ae88-74b590980a66",
"metadata": {},
"outputs": [],
"source": [
"from typing import Dict, List, Union, Optional\n",
"from datetime import datetime\n",
"\n",
"class ReadingManager:\n",
" \"\"\"\n",
" This class is the Reading Manager API, which tracks reading progress and related statistics.\n",
" \"\"\"\n",
"\n",
" def __init__(self):\n",
" \"\"\"\n",
" Initialize the ReadingManager instance.\n",
" \"\"\"\n",
" self.reading_entries: List[Dict[str, Union[str, int]]] = []\n",
" self.total_pages_read: int = 0\n",
" self.reading_sessions: List[Dict[str, Union[str, float]]] = []\n",
" self.daily_reading_goal: Optional[int] = None\n",
" self.current_session_start: Optional[datetime] = None\n",
"\n",
" def add_book(self, title: str, author: str, total_pages: int) -> Dict[str, str]:\n",
" \"\"\"\n",
" Add a book to the reading list.\n",
"\n",
" Args:\n",
" title (str): Title of the book.\n",
" author (str): Author of the book.\n",
" total_pages (int): Total number of pages in the book.\n",
"\n",
" Returns:\n",
" result (Dict[str, str]): Book added confirmation message.\n",
" \"\"\"\n",
" if total_pages <= 0:\n",
" return {\"error\": \"Total pages must be greater than zero.\"}\n",
" \n",
" self.reading_entries.append({\"title\": title, \"author\": author, \"total_pages\": total_pages, \"pages_read\": 0})\n",
" return {\"result\": f\"Added '{title}' by {author} with {total_pages} total pages.\"}\n",
"\n",
" def create_reading_goal(self, pages: int) -> Dict[str, str]:\n",
" \"\"\"\n",
" Set a specific reading goal in pages.\n",
"\n",
" Args:\n",
" pages (int): The target number of pages to read.\n",
"\n",
" Returns:\n",
" result (Dict[str, str]): Goal created confirmation message.\n",
" \"\"\"\n",
" if pages <= 0:\n",
" return {\"error\": \"Reading goal must be greater than zero.\"}\n",
"\n",
" self.daily_reading_goal = pages\n",
" return {\"result\": f\"Daily reading goal set to {pages} pages.\"}\n",
"\n",
" def pages_read(self, pages: int) -> Dict[str, str]:\n",
" \"\"\"\n",
" Log the number of pages read in the current session.\n",
"\n",
" Args:\n",
" pages (int): Number of pages read.\n",
"\n",
" Returns:\n",
" result (Dict[str, str]): Pages logged confirmation message.\n",
" \"\"\"\n",
" if pages <= 0:\n",
" return {\"error\": \"Pages read must be greater than zero.\"}\n",
" \n",
" self.total_pages_read += pages\n",
" for entry in self.reading_entries:\n",
" if entry['pages_read'] + pages <= entry['total_pages']:\n",
" entry['pages_read'] += pages\n",
" break\n",
"\n",
" return {\"result\": f\"Logged {pages} pages read.\"}\n",
"\n",
" def start_reading_session(self) -> Dict[str, str]:\n",
" \"\"\"\n",
" Start a new reading session.\n",
"\n",
" Returns:\n",
" result (Dict[str, str]): Confirmation message.\n",
" \"\"\"\n",
" self.current_session_start = datetime.now()\n",
" return {\"result\": \"Reading session has started.\"}\n",
"\n",
" def end_reading_session(self) -> Dict[str, Union[str, float]]:\n",
" \"\"\"\n",
" End the current reading session and log the duration.\n",
"\n",
" Returns:\n",
" result (Dict[str, Union[str, float]]): Duration of the session in minutes.\n",
" \"\"\"\n",
" if not self.current_session_start:\n",
" return {\"error\": \"No active reading session.\"}\n",
"\n",
" session_end_time = datetime.now()\n",
" duration = (session_end_time - self.current_session_start).total_seconds() / 60\n",
" self.current_session_start = None\n",
" self.reading_sessions.append({\"duration\": duration})\n",
" return {\"result\": f\"Reading session ended. Duration: {duration:.2f} minutes.\"}\n",
"\n",
" def calculate_reading_speed(self) -> Optional[float]:\n",
" \"\"\"\n",
" Calculate reading speed in pages per minute.\n",
"\n",
" Returns:\n",
" speed (Optional[float]): Pages read per minute, or None if no session occurred.\n",
" \"\"\"\n",
" if not self.reading_sessions:\n",
" return None\n",
"\n",
" total_duration = sum(session['duration'] for session in self.reading_sessions)\n",
" return self.total_pages_read / total_duration if total_duration > 0 else None\n",
"\n",
" def pages_left_to_goal(self) -> int:\n",
" \"\"\"\n",
" Calculate how many pages remain to meet the daily goal.\n",
"\n",
" Returns:\n",
" remaining (int): Pages remaining to reach the goal.\n",
" \"\"\"\n",
" if self.daily_reading_goal is None:\n",
" return 0\n",
" return max(0, self.daily_reading_goal - self.total_pages_read)\n",
"\n",
" def reading_overview(self) -> Dict[str, Union[int, Optional[int]]]:\n",
" \"\"\"\n",
" Provide an overview of reading progress.\n",
"\n",
" Returns:\n",
" overview (Dict[str, Union[int, Optional[int]]]): Total pages read and remaining pages to the goal.\n",
" \"\"\"\n",
" return {\n",
" \"total_pages_read\": self.total_pages_read,\n",
" \"daily_goal\": self.daily_reading_goal,\n",
" \"remaining_pages\": self.pages_left_to_goal(),\n",
" \"message\": \"Your reading progress overview.\"\n",
" }\n",
"\n",
" def goal_status(self) -> Dict[str, str]:\n",
" \"\"\"\n",
" Check if the reading goal has been met.\n",
"\n",
" Returns:\n",
" status (Dict[str, str]): Goal achievement status.\n",
" \"\"\"\n",
" status = \"met\" if self.daily_reading_goal and self.total_pages_read >= self.daily_reading_goal else \"not met\"\n",
" return {\"goal_status\": f\"Your daily reading goal is {status}.\"}\n",
"\n",
" def get_reading_summary(self) -> Dict[str, Union[str, float]]:\n",
" \"\"\"\n",
" Provide a summary of reading activities.\n",
"\n",
" Returns:\n",
" summary (Dict[str, Union[str, float]]): Summary of reading progress, sessions, and speed.\n",
" \"\"\"\n",
" reading_speed = self.calculate_reading_speed()\n",
" return {\n",
" \"total_pages_read\": self.total_pages_read,\n",
" \"total_sessions\": len(self.reading_sessions),\n",
" \"reading_speed\": reading_speed,\n",
" \"message\": \"Summary of your reading progress.\"\n",
" }\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "98a00b3e-0f67-41dd-909f-56609561b0fb",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}