diff --git a/docs/examples/action_items.md b/docs/examples/action_items.md new file mode 100644 index 0000000..5f13de5 --- /dev/null +++ b/docs/examples/action_items.md @@ -0,0 +1,163 @@ +# Example: Extracting Action Items from Meeting Transcripts + +In this guide, we'll walk through how to extract action items from meeting transcripts using OpenAI's API and Pydantic. This use case is essential for automating project management tasks, such as task assignment and priority setting. + +!!! tips "Motivation" + In the corporate world, a considerable amount of time is spent in meetings, and action items are often the actionable output of these discussions. Automating the extraction of action items can be a time-saver and ensures that nothing crucial is missed. + +## Defining the Structures + +We'll model a meeting transcript as a collection of **`Ticket`** objects, each representing an action item. Every **`Ticket`** can have multiple **`Subtask`** objects, representing smaller, manageable pieces of the main task. + +```python +from enum import Enum +from pydantic import BaseModel, Field +from typing import List, Optional + +class PriorityEnum(str, Enum): + high = "High" + medium = "Medium" + low = "Low" + +class Subtask(BaseModel): + """Correctly resolved subtask from the given transcript""" + id: int + name: str + +class Ticket(BaseModel): + """Correctly resolved ticket from the given transcript""" + id: int + name: str + description: str + priority: PriorityEnum + assignees: List[str] + subtasks: Optional[List[Subtask]] + dependencies: Optional[List[int]] + +class ActionItems(BaseModel): + """Correctly resolved set of action items from the given transcript""" + items: List[Ticket] + +``` + +## Extracting Action Items + +To extract action items from a meeting transcript, we use the **`generate`** function. It calls OpenAI's API, processes the text, and returns a set of action items modeled as **`ActionItems`**. + +```python +import openai + +def generate(data: str) -> ActionItems: + return openai.ChatCompletion.create( + model="gpt-3.5-turbo-0613", + response_model=ActionItems, + messages=[ + { + "role": "system", + "content": "The following is a transcript of a meeting...", + }, + { + "role": "user", + "content": f"Create the action items for the following transcript: {data}", + }, + ], + ) # type: ignore + +``` + +## Evaluation and Testing + +To test the **`generate`** function, we provide it with a sample transcript, and then print the JSON representation of the extracted action items. + +```python +prediction = generate( +""" +Alice: Hey team, we have several critical tasks we need to tackle for the upcoming release. First, we need to work on improving the authentication system. It's a top priority. + +Bob: Got it, Alice. I can take the lead on the authentication improvements. Are there any specific areas you want me to focus on? + +Alice: Good question, Bob. We need both a front-end revamp and back-end optimization. So basically, two sub-tasks. + +Carol: I can help with the front-end part of the authentication system. + +Bob: Great, Carol. I'll handle the back-end optimization then. + +Alice: Perfect. Now, after the authentication system is improved, we have to integrate it with our new billing system. That's a medium priority task. + +Carol: Is the new billing system already in place? + +Alice: No, it's actually another task. So it's a dependency for the integration task. Bob, can you also handle the billing system? + +Bob: Sure, but I'll need to complete the back-end optimization of the authentication system first, so it's dependent on that. + +Alice: Understood. Lastly, we also need to update our user documentation to reflect all these changes. It's a low-priority task but still important. + +Carol: I can take that on once the front-end changes for the authentication system are done. So, it would be dependent on that. + +Alice: Sounds like a plan. Let's get these tasks modeled out and get started.""" +) +``` + +## Visualizing the tasks + +In order to quickly visualize the data we used code interpreter to create a graphviz export of the json version of the ActionItems array. + +![action items](action_items.png) + +```json +{ + "items": [ + { + "id": 1, + "name": "Improve Authentication System", + "description": "Revamp the front-end and optimize the back-end of the authentication system", + "priority": "High", + "assignees": [ + "Bob", + "Carol" + ], + "subtasks": [ + { + "id": 2, + "name": "Front-end Revamp" + }, + { + "id": 3, + "name": "Back-end Optimization" + } + ], + "dependencies": [] + }, + { + "id": 4, + "name": "Integrate Authentication System with Billing System", + "description": "Integrate the improved authentication system with the new billing system", + "priority": "Medium", + "assignees": [ + "Bob" + ], + "subtasks": [], + "dependencies": [ + 1 + ] + }, + { + "id": 5, + "name": "Update User Documentation", + "description": "Update the user documentation to reflect the changes in the authentication system", + "priority": "Low", + "assignees": [ + "Carol" + ], + "subtasks": [], + "dependencies": [ + 2 + ] + } + ] +} +``` + +In this example, the **`generate`** function successfully identifies and segments the action items, assigning them priorities, assignees, subtasks, and dependencies as discussed in the meeting. + +By automating this process, you can ensure that important tasks and details are not lost in the sea of meeting minutes, making project management more efficient and effective. \ No newline at end of file diff --git a/docs/examples/action_items.png b/docs/examples/action_items.png new file mode 100644 index 0000000..6fd0f92 Binary files /dev/null and b/docs/examples/action_items.png differ diff --git a/docs/examples/index.md b/docs/examples/index.md index 6c23462..81247c8 100644 --- a/docs/examples/index.md +++ b/docs/examples/index.md @@ -5,6 +5,7 @@ Welcome to the examples page. Here you will find emails that highlight a range o ## Quick Links - [Classifying Text](classification.md) +- [Identifying Action Items with dependencies](action_items.md) - [Segmenting search requests into multiple search queries](search.md) - [One shot query planning](planning-tasks.md) - [Using recursive schema](recursive.md) @@ -18,6 +19,8 @@ In this section, you will find examples demonstrating different aspects of our p - [Classfying Text](classification.md): Doing single and multi class prediction using enums. +- [Identifying Action Items with dependencies](action_items.md): Scanning a transcript to generate action items with subtasks. + - [Segmented Search](search.md): Learn how to perform segmented search using a multi task definition using function calling - [One shot Query Planning](planning-tasks.md): Explore how to plan and decompose a complex query into multiple subqueries in a single request. diff --git a/examples/auto-ticketer/run.py b/examples/auto-ticketer/run.py new file mode 100644 index 0000000..85efcb8 --- /dev/null +++ b/examples/auto-ticketer/run.py @@ -0,0 +1,148 @@ +import openai +from typing import List, Optional +from pydantic import BaseModel, Field +from instructor import patch +from enum import Enum + +patch() + + +class PriorityEnum(str, Enum): + high = "High" + medium = "Medium" + low = "Low" + + +class Subtask(BaseModel): + """ + Correctly resolved subtask from the given transcript + """ + + id: int = Field(..., description="Unique identifier for the subtask") + name: str = Field(..., description="Informative title of the subtask") + + +class Ticket(BaseModel): + """ + Correctly resolved ticket from the given transcript + """ + + id: int = Field(..., description="Unique identifier for the ticket") + name: str = Field(..., description="Title of the task") + description: str = Field(..., description="Detailed description of the task") + priority: PriorityEnum = Field(..., description="Priority level") + assignees: List[str] = Field(..., description="List of users assigned to the task") + subtasks: Optional[List[Subtask]] = Field( + None, description="List of subtasks associated with the main task" + ) + dependencies: Optional[List[int]] = Field( + None, description="List of ticket IDs that this ticket depends on" + ) + + +class ActionItems(BaseModel): + """ + Correctly resolved set of action items from the given transcript + """ + + items: List[Ticket] + + +def generate(data: str) -> ActionItems: + return openai.ChatCompletion.create( + model="gpt-3.5-turbo-0613", + response_model=ActionItems, + messages=[ + { + "role": "system", + "content": "The following is a transcript of a meeting between a manager and their team. The manager is assigning tasks to their team members and creating action items for them to complete.", + }, + { + "role": "user", + "content": f"Create the action items for the following transcript: {data}", + }, + ], + ) # type: ignore + + +prediction = generate( + """ +Alice: Hey team, we have several critical tasks we need to tackle for the upcoming release. First, we need to work on improving the authentication system. It's a top priority. + +Bob: Got it, Alice. I can take the lead on the authentication improvements. Are there any specific areas you want me to focus on? + +Alice: Good question, Bob. We need both a front-end revamp and back-end optimization. So basically, two sub-tasks. + +Carol: I can help with the front-end part of the authentication system. + +Bob: Great, Carol. I'll handle the back-end optimization then. + +Alice: Perfect. Now, after the authentication system is improved, we have to integrate it with our new billing system. That's a medium priority task. + +Carol: Is the new billing system already in place? + +Alice: No, it's actually another task. So it's a dependency for the integration task. Bob, can you also handle the billing system? + +Bob: Sure, but I'll need to complete the back-end optimization of the authentication system first, so it's dependent on that. + +Alice: Understood. Lastly, we also need to update our user documentation to reflect all these changes. It's a low-priority task but still important. + +Carol: I can take that on once the front-end changes for the authentication system are done. So, it would be dependent on that. + +Alice: Sounds like a plan. Let's get these tasks modeled out and get started.""" +) + +print(prediction.model_dump_json(indent=2)) +""" +{ + "items": [ + { + "id": 1, + "name": "Improve Authentication System", + "description": "Revamp the front-end and optimize the back-end of the authentication system", + "priority": "High", + "assignees": [ + "Bob", + "Carol" + ], + "subtasks": [ + { + "id": 2, + "name": "Front-end Revamp" + }, + { + "id": 3, + "name": "Back-end Optimization" + } + ], + "dependencies": [] + }, + { + "id": 4, + "name": "Integrate Authentication System with Billing System", + "description": "Integrate the improved authentication system with the new billing system", + "priority": "Medium", + "assignees": [ + "Bob" + ], + "subtasks": [], + "dependencies": [ + 1 + ] + }, + { + "id": 5, + "name": "Update User Documentation", + "description": "Update the user documentation to reflect the changes in the authentication system", + "priority": "Low", + "assignees": [ + "Carol" + ], + "subtasks": [], + "dependencies": [ + 2 + ] + } + ] +} +""" diff --git a/examples/auto-ticketer/tasks.png b/examples/auto-ticketer/tasks.png new file mode 100644 index 0000000..6fd0f92 Binary files /dev/null and b/examples/auto-ticketer/tasks.png differ diff --git a/examples/reference-citation/Entity_Dependency_Graph_with_New_Entities.png b/examples/resolving-complex-entities/Entity_Dependency_Graph_with_New_Entities.png similarity index 100% rename from examples/reference-citation/Entity_Dependency_Graph_with_New_Entities.png rename to examples/resolving-complex-entities/Entity_Dependency_Graph_with_New_Entities.png diff --git a/examples/reference-citation/Entity_Dependency_Graph_with_Properties.png b/examples/resolving-complex-entities/Entity_Dependency_Graph_with_Properties.png similarity index 100% rename from examples/reference-citation/Entity_Dependency_Graph_with_Properties.png rename to examples/resolving-complex-entities/Entity_Dependency_Graph_with_Properties.png diff --git a/examples/reference-citation/Entity_Dependency_Graph_with_Properties_and_Units.png b/examples/resolving-complex-entities/Entity_Dependency_Graph_with_Properties_and_Units.png similarity index 100% rename from examples/reference-citation/Entity_Dependency_Graph_with_Properties_and_Units.png rename to examples/resolving-complex-entities/Entity_Dependency_Graph_with_Properties_and_Units.png diff --git a/examples/reference-citation/readme.md b/examples/resolving-complex-entities/readme.md similarity index 100% rename from examples/reference-citation/readme.md rename to examples/resolving-complex-entities/readme.md diff --git a/examples/reference-citation/run.py b/examples/resolving-complex-entities/run.py similarity index 100% rename from examples/reference-citation/run.py rename to examples/resolving-complex-entities/run.py diff --git a/mkdocs.yml b/mkdocs.yml index 55fbf5e..27696ff 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -49,7 +49,8 @@ nav: - Philosophy: 'philosophy.md' - Use Cases: - 'Overview': 'examples/index.md' - - 'Classification': 'examples/classification.md' + - 'Classifying Text': 'examples/classification.md' + - 'Extracting Action Items': 'examples/action_items.md' - 'Segmented Search': 'examples/search.md' - 'One shot Query Planning': 'examples/planning-tasks.md' - 'Recursive Schemas': 'examples/recursive.md'