Skip to content

Commit

Permalink
Example: transcription to tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ddebowczyk committed Aug 8, 2024
1 parent 3f5e3f2 commit 2dfab3d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
83 changes: 83 additions & 0 deletions docs/cookbook/examples/techniques/transcription_to_tasks.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: 'Create tasks from meeting transcription'
docname: 'transcription_to_tasks'
---

## Overview

This example demonstrates how you can create task assignments based on a transcription of meeting recording.

## Example

```php
<?php
$loader = require 'vendor/autoload.php';
$loader->add('Cognesy\\Instructor\\', __DIR__ . '../../src/');

use Cognesy\Instructor\Enums\Mode;
use Cognesy\Instructor\Instructor;
use Cognesy\Instructor\Schema\Attributes\Description;

// Step 1: Define a class that represents the structure and semantics
// of the data you want to extract
enum TaskStatus : string {
case Pending = 'pending';
case Completed = 'completed';
}

enum Role : string {
case PM = 'pm';
case Dev = 'dev';
}

class Task {
public string $title;
public string $description;
#[Description("Due date in ISO 8601 format")]
public DateTime $dueDate;
public Role $owner;
public TaskStatus $status;
}

class Tasks {
public DateTime $meetingDate;
/** @var Task[] */
public array $tasks;
}

// Step 2: Get the text (or chat messages) you want to extract data from
$text = <<<TEXT
Transcription of meeting from 2024-01-15, 16:00
---
PM: Hey, how's progress on the video transcription engine?
Dev: I've got basic functionality working, but accuracy isn't great yet. Might need to switch to a different API.
PM: So the plan is to research alternatives and provide a comparison? Is it possible by Jan 20th?
Dev: Sure, I'll make it available before the meeting.
PM: The one at 12?
Dev: Yes, at 12. By the way, are we still planning to support real-time transcription?
PM: Yes, it's a key feature. Speaking of which, I need to update the product roadmap. I'll have that ready by Jan 18th.
Dev: Got it. I'll keep that in mind while evaluating APIs. Oh, and the UI for the summary view is ready for review.
PM: Great, I'll take a look tomorrow by 10.
TEXT;

print("Input text:\n");
print($text . "\n\n");

// Step 3: Extract structured data using default language model API (OpenAI)
print("Extracting structured data using LLM...\n\n");
$tasks = (new Instructor)->respond(
messages: $text,
responseModel: Tasks::class,
model: 'gpt-4o',
mode: Mode::Json,
);

// Step 4: Now you can use the extracted data in your application
print("Extracted data:\n");

dump($tasks);

assert($tasks->meetingDate->format('Y-m-d') === '2024-01-15');
assert(count($tasks->tasks) > 1);
?>
```
9 changes: 8 additions & 1 deletion docs/cookbook/examples/troubleshooting/debugging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ $instructor = (new Instructor)->withClient(new OpenAIClient(
));

echo "Debugging request and response:\n\n";
$user = $instructor->withDebug()->respond(
$user = $instructor->respond(
messages: "Jason is 25 years old.",
responseModel: User::class,
options: [ 'stream' => true ]
);

$user2 = $instructor->respond(
messages: "Jason is 25 years old.",
responseModel: User::class,
options: [ 'stream' => true ]
);

echo "\nResult:\n";
dump($user);
dump($user2);

assert(isset($user->name));
assert(isset($user->age));
Expand Down
1 change: 1 addition & 0 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"cookbook/examples/techniques/search_query_expansion",
"cookbook/examples/techniques/component_reuse",
"cookbook/examples/techniques/component_reuse_cot",
"cookbook/examples/techniques/transcription_to_tasks",
"cookbook/examples/techniques/translate_ui_fields"
]
},
Expand Down

0 comments on commit 2dfab3d

Please sign in to comment.