{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "from datetime import datetime\n", "\n", "from utils import get_context\n", "from inference import fetch as fetch_inflection" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# **Meeting Scheduling with Structured JSON Output and Inflection AI**\n", "\n", "This notebook demonstrates an approach to **meeting scheduling** using **structured prompting** and **JSON-based extraction**. The goal is to parse user requests and generate structured meeting details for efficient scheduling automation. By leveraging **instruction-based prompting**, this method enhances **accuracy** and ensures **consistent, machine-readable outputs**.\n", "\n", "## **Overview**\n", "\n", "- Utilizes **structured prompting** to extract key meeting details from user input.\n", "- Employs a **guiding system instruction prompt** to maintain consistency.\n", "- The model performs the following tasks:\n", " - Extracts **meeting duration**, **date**, **participants**, **topic**, and **additional details** from free-text inputs.\n", " - Handles **relative date references** (e.g., \"next Friday\") with **dynamic date calculations**.\n", " - Outputs results in **JSON format** for seamless integration with scheduling systems.\n", " - Uses a **task-specific inference model** optimized for structured information extraction.\n", "\n", "This approach enables **automated meeting scheduling** by transforming unstructured text into actionable data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "legacy_api = False # True if using the old API, False if using the new OpenAI Compatible API" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "system_instruction_prompt = \"\"\"\n", " You are a helpful AI assistant designed to assist users in scheduling meetings.\n", "\n", " # Your Purpose\n", " 1. You will be given a request from a user to schedule a meeting.\n", " 2. Your job is to extract the parts of the request that are relevant to scheduling the meeting.\n", " 3. Use Local Date: as a reference only when a specific date is not provided in the user's request.\n", "\n", " # Valid Parts\n", " - Time Duration: The duration of the meeting in minutes.\n", " - Date: The date of the meeting.\n", " - Participants: List of participants of the meeting.\n", " - Meeting Topic: The main topic or subject of the meeting.\n", " - Additional Details: Any additional context or details mentioned.\n", "\n", " # Example Input\n", " Schedule 30 minutes on Friday with Masha and Matt to talk about Product.\n", " Schedule half an hour on Friday with Masha and Matt to talk about Product.\n", "\n", " # Example Output\n", " {\n", " \"time_duration\": 30,\n", " \"date\": \"2024-08-09\",\n", " \"participants\": [\"Masha\", \"Matt\"],\n", " \"meeting_topic\": \"Product\",\n", " \"additional_details\": \"talk about Product\"\n", " }\n", "\n", " # Notes on the date:\n", " - The date should be in the format \"YYYY-MM-DD\".\n", " - If a specific date is provided in the user's request (e.g., \"09/13/2024\"), use that date and convert it to the YYYY-MM-DD format.\n", " - If the date is not provided, return today's date.\n", " - If the date just says \"Friday,\" calculate this week's Friday from the current date.\n", " - If the date says \"next Friday,\" calculate next week's Friday from the current date.\n", " - Ensure that the calculated date is in the future. If \"Friday\" refers to a day in the past based on the current date, assume it refers to the next occurrence of that day.\n", " - Always return a future date for relative terms like \"Friday\" or \"next Friday.\"\n", "\n", " # Notes on time duration:\n", " - The time duration should be in minutes.\n", " - The user might say \"30 minutes\" or \"half an hour,\" which should be converted to minutes.\n", " - The user might say \"1 hour,\" which should be converted to 60 minutes.\n", " - If a specific time range is provided (e.g., \"10:00am-10:30am\"), calculate the duration in minutes.\n", " - If the time duration is not provided, assume it is 30 minutes.\n", "\n", " # Output Format - JSON\n", " You will respond using a JSON object for each extracted piece of information. You don't need to provide explanation or any other information, just return the extracted parts within the appropriate JSON structure.\n", "\n", " # Format of the Output\n", " {\n", " \"time_duration\": \"extracted_time_duration\",\n", " \"date\": \"extracted_date\",\n", " \"participants\": [\"participant1\", \"participant2\"],\n", " \"meeting_topic\": \"extracted_meeting_topic\",\n", " \"additional_details\": \"extracted_additional_details\"\n", " }\n", "\"\"\"\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class color:\n", " BOLD = '\\033[1m'\n", " END = '\\033[0m'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "async def test_extract_meeting_invite_parts_basic_scenario():\n", " \"\"\"\n", " Scenario: The user provides straightforward info (a single participant,\n", " direct date, direct time duration and a topic) to schedule a meeting.\n", " Expected Outcome: correct information in every component.\n", " \"\"\"\n", " print(\"Starting test: test_extract_meeting_invite_parts_basic_scenario\")\n", "\n", " user_message = \"Schedule a meeting with Matt on 09/13/2024 for 10:00am-10:30am to discuss Products.\"\n", " today = datetime.now().strftime(\"%Y-%m-%d\")\n", "\n", " message = f\"{user_message} Today's date: {today}\"\n", " context = get_context(system_instruction_prompt, message, user_input_label=\"Schedule meeting request\", legacy_api=legacy_api)\n", "\n", " expected_output = {\n", " \"time_duration\": 30,\n", " \"date\": \"2024-09-13\",\n", " \"participants\": [\"Matt\"],\n", " \"meeting_topic\": \"Products\",\n", " \"additional_details\": \"discuss Products\",\n", " }\n", "\n", " extracted_parts = await fetch_inflection(\n", " context, model=\"inflection_3_productivity\", legacy_api=legacy_api\n", " )\n", " print(f\"{color.BOLD} Extracted parts: {color.END} {extracted_parts}\")\n", "\n", " assert (\n", " expected_output == json.loads(extracted_parts)\n", " ), f\"Extracted parts do not match the expected output. Expected: {expected_output}, Got: {extracted_parts}\"\n", "\n", " print(\"Test completed successfully! 🙌\")\n", "\n", "# Run the test\n", "await test_extract_meeting_invite_parts_basic_scenario()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.8" } }, "nbformat": 4, "nbformat_minor": 2 }