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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners