To constrain a model’s response to fit the boundaries of our task, we can specify a style.
<?php
$loader = require 'vendor/autoload.php';
$loader->add('Cognesy\\Instructor\\', __DIR__.'../../src/');
use Cognesy\Instructor\Extras\Sequence\Sequence;
use Cognesy\Instructor\Instructor;
use Cognesy\Instructor\Utils\Arrays;
class Company {
public string $name;
public string $country;
public string $industry;
public string $websiteUrl;
public string $description;
}
class GenerateCompanyProfiles {
public function __invoke(array $criteria, array $styles) : array {
$criteriaStr = Arrays::toBullets($criteria);
$stylesStr = Arrays::toBullets($styles);
return (new Instructor)->respond(
messages: [
['role' => 'user', 'content' => "List companies meeting criteria:\n{$criteriaStr}\n\n"],
['role' => 'user', 'content' => "Use following styles for descriptions:\n{$stylesStr}\n\n"],
],
responseModel: Sequence::of(Company::class),
)->toArray();
}
}
$companies = (new GenerateCompanyProfiles)(
criteria: [
"insurtech",
"located in US, Canada or Europe",
"mentioned on ProductHunt"
],
styles: [
"brief",
"journalistic",
]
);
dump($companies);
?>