Skip to content

Commit

Permalink
Fix: sequence handling when streaming large chunks (rather than per t…
Browse files Browse the repository at this point in the history
…oken)
  • Loading branch information
ddebowczyk committed Dec 21, 2024
1 parent 44da2b9 commit b281aef
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions docs/cookbook/examples/extras/complex_extraction_gemini.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $loader = require 'vendor/autoload.php';
$loader->add('Cognesy\\Instructor\\', __DIR__ . '../../src/');

use Cognesy\Instructor\Enums\Mode;
use Cognesy\Instructor\Events\Inference\PartialLLMResponseReceived;
use Cognesy\Instructor\Extras\Sequence\Sequence;
use Cognesy\Instructor\Instructor;
use Cognesy\Instructor\Utils\Debug\Debug;
Expand Down Expand Up @@ -87,7 +88,7 @@ class Stakeholder {
/** Role of the stakeholder, if specified */
public StakeholderRole $role = StakeholderRole::Other;
/** Any details on the stakeholder, if specified - any mentions of company, organization, structure, group, team, function */
public string $details = '';
public ?string $details = '';
}

enum StakeholderRole: string {
Expand All @@ -101,19 +102,21 @@ $instructor = (new Instructor)->withConnection('gemini');

echo "PROJECT EVENTS:\n\n";

//Debug::enable();

$events = $instructor
->onSequenceUpdate(fn($sequence) => displayEvent($sequence->last()))
//->onEvent(PartialLLMResponseReceived::class, fn(PartialLLMResponseReceived $e) => print "---\n".$e->partialLLMResponse->content()."---\n")
->request(
messages: $report,
responseModel: Sequence::of(ProjectEvent::class),
examples: [['input' => 'Acme Insurance project to implement SalesTech CRM solution is currently in RED status due to delayed delivery of document production system, led by 3rd party vendor - Alfatech. Customer (Acme) is discussing the resolution with the vendor. Production deployment plan has been finalized on Aug 15th and awaiting customer approval.', 'output' => [["type" => "object", "title" => "sequenceOfProjectEvent", "description" => "A sequence of ProjectEvent", "properties" => ["list" => [["title" => "Absorbing delay by deploying extra resources", "description" => "System integrator (SysCorp) are working to absorb some of the delay by deploying extra resources to speed up development when the doc production is done.", "type" => "action", "status" => "open", "stakeholders" => [["name" => "SysCorp", "role" => "system integrator", "details" => "System integrator",],], "date" => "2021-09-01",], ["title" => "Finalization of production deployment plan", "description" => "Production deployment plan has been finalized on Aug 15th and awaiting customer approval.", "type" => "progress", "status" => "open", "stakeholders" => [["name" => "Acme", "role" => "customer", "details" => "Customer",],], "date" => "2021-08-15",],],]]]]],
model: 'gemini-1.5-flash',
//model: 'gemini-2.0-flash-exp',
//model: 'gemini-2.0-flash-thinking-exp',
options: [
'max_tokens' => 2048,
'stream' => true,
],
mode: Mode::Tools,
mode: Mode::Json,
)->get();

echo "TOTAL EVENTS: " . count($events) . "\n";
Expand Down

0 comments on commit b281aef

Please sign in to comment.