Skip to content

Commit

Permalink
partial and iterable examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanleifer committed Feb 20, 2024
1 parent 584108b commit de2a114
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
7. [How are complex queries decomposed into subqueries in a single request?](planning-tasks.md)
8. [How are entities extracted and resolved from documents?](entity_resolution.md)
9. [How is Personally Identifiable Information sanitized from documents?](pii.md)
10. [How are action items and dependencies generated from transcripts?](action_items.md)
10. [How are action items and dependencies generated from transcripts?](../hub/action_items.md)
11. [How to enable OpenAI's moderation](moderation.md)
12. [How to extract tables using GPT-Vision?](extracting_tables.md)
13. [How to generate advertising copy from image inputs](image_to_ad_copy.md)
Expand Down
38 changes: 22 additions & 16 deletions docs/examples/action_items.md → docs/hub/action_items.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

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.

If you want to try outs via `instructor hub`, you can pull it by running

```bash
instructor hub pull --slug action_items --py > action_items.py
```

For multi-label classification, we introduce a new enum class and a different Pydantic model to handle multiple labels.


!!! tips "Motivation"

Significant amount of time is dedicated to meetings, where action items are generated as the actionable outcomes of these discussions. Automating the extraction of action items can save time and guarantee that no critical tasks are overlooked.
Expand All @@ -10,10 +19,21 @@ In this guide, we'll walk through how to extract action items from meeting trans

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.

## 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`**.

## 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
import instructor
from openai import OpenAI
from typing import Iterable, List, Optional
from enum import Enum
from pydantic import BaseModel
from typing import List, Optional


class PriorityEnum(str, Enum):
Expand All @@ -39,16 +59,7 @@ class Ticket(BaseModel):
assignees: List[str]
subtasks: Optional[List[Subtask]]
dependencies: Optional[List[int]]
```

## 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 instructor
from openai import OpenAI
from typing import Iterable

# Apply the patch to the OpenAI client
# enables response_model keyword
Expand All @@ -70,13 +81,8 @@ def generate(data: str) -> Iterable[Ticket]:
},
],
)
```

## 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.
Expand Down Expand Up @@ -109,7 +115,7 @@ Alice: Sounds like a plan. Let's get these tasks modeled out and get started."""

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)
![action items](../img/action_items.png)

```json
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
If you want to try outs via `instructor hub`, you can pull it by running

```bash
instructor hub pull --slug partial_streaming --py > partial_streaming.py
```

```python
import instructor
from openai import OpenAI
from pydantic import BaseModel
Expand Down Expand Up @@ -58,3 +65,4 @@ class MeetingInfo(BaseModel):
obj = extraction.model_dump()
console.clear()
console.print(obj)
```
File renamed without changes
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ nav:
- Extracting Complex Entities: 'examples/entity_resolution.md'
- Expanding Search Queries (RAG): 'examples/search.md'
- Query Planning (RAG): 'examples/planning-tasks.md'
- Extracting Related Action Items: 'examples/action_items.md'
- PII Data Sanitization: 'examples/pii.md'
- Enabling Open Source Models: 'examples/open_source.md'
- Image to Ad Copy: 'examples/image_to_ad_copy.md'
Expand All @@ -175,6 +174,8 @@ nav:
- Using Together Compute: 'hub/together.md'
- Using Anyscale: 'hub/anyscale.md'
- Batch Async Classification w/ Langsmith: 'hub/batch_classification_langsmith.md'
- Action Items: 'hub/action_items.md'
- Partial Streaming: 'hub/partial_streaming.md'

- Tutorials:
- Tutorials (Notebooks): 'tutorials/1-introduction.ipynb'
Expand Down Expand Up @@ -230,6 +231,7 @@ plugins:
'blob/posts/llama-cpp-python.md': 'hub/llama-cpp-python.md'
'blog/posts/together.md': 'hub/together.md'
'blog/posts/anyscale.md': 'hub/anyscale.md'
'examples/action_items.md': 'hub/action_items.md'
extra:
analytics:
provider: google
Expand Down

0 comments on commit de2a114

Please sign in to comment.