Source: juststeveking.uk

Using OpenAI in Laravel
AI is it a buzzword, or is it something we should be thinking about? With the release of the OpenAI package, we can dive into AI-powered Laravel applications

Now, anytime I try to inject the OpenAI Client class into a constructor or anywhere else, it will come pre-setup for me.

final class AdvertisementTransformer { public static function transform(string $prompt): array { return [ 'model' => Model::DAVINCI->value, 'prompt' => $prompt, 'temperature' => 0.5, 'max_tokens' => 100, 'top_p' => 1.0, 'frequency_penalty' => 0.0, 'presence_penalty' => 0.0, ]; }}

Let’s look back at the OpenAI client request now: $client->completions()->create( parameters: AdvertisementTransformer::transform( prompt: $this->text, ), ); This, to me, at least, is clean and understandable.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners