Skip to content

Instantly share code, notes, and snippets.

@gregpriday
Last active June 29, 2021 18:28
Show Gist options
  • Save gregpriday/8f2a113773d61cf6f9053b7a6de18677 to your computer and use it in GitHub Desktop.
Save gregpriday/8f2a113773d61cf6f9053b7a6de18677 to your computer and use it in GitHub Desktop.
Example GPT-3 Laravel Factory Uses

These are some theoretical example uses for a GPT-3 Laravel Factory.

<?php
use SiteOrigin\LaravelOpenAI\Factory as GPT3Factory
class MyModelFactory extends GPT3Factory {
protected $model = MyModel::class;
}
$models = MyModelFactory::withPrompt("This is a list of MyModels. Each one represents some_realworld_thing:")
->withFields(['tags', 'excerpt'])
->withFieldCast('tags', 'array')
->withTitle(function(Model $v){
return $v->title . ':' . $v->excerpt;
})
->withTitleToAttributes(function(string $v){
// Convert the title string back into attributes
list($title, $excerpt) = explode(':', $v, 2);
return compat($title, $excerpt);
})
->create(5);
dd($models);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment