Skip to main content

OpenAI experiments

· 3 min read
Stephan Hochdörfer
Head of IT Business Operations

AI and services like ChatGPT have been all over the place since last year. Every day, new AI-powered services appear on the horizon. How can we use AI (or ChatGPT specifically) in our daily work or our applications?

Thanks to the orhanerday/open-ai package, consuming the OpenAI API is not too complicated. First, let's install the Composer package:

composer require orhanerday/open-ai

For the next step, an OpenAI access token is needed. Create an account at and access this link to create a new API token:

The simplest way of using the library works like this:



require __DIR__ . '/vendor/autoload.php';

use Orhanerday\OpenAi\OpenAi;

$apiKey = '...';
$openAI = new OpenAi($apiKey);

$content = <<<CHAT
Here be dragons...

$chat = $openAI->chat([
'model' => 'gpt-3.5-turbo',
'messages' => [
"role" => "system",
"content" => $content,
'temperature' => 1.0,
'frequency_penalty' => 0,
'presence_penalty' => 0,

// decode response
$response = json_decode($chat);

Why am I experimenting with OpenAI? I've been using ChatGPT and other tools in my daily work to improve all sorts of content that I am writing (this blog post included).

I've been wondering if ChatGPT could also help me save time promoting the PHP meetups I am organizing. I have realized I spent a lot of time writing and scheduling social media posts to announce the meetups on the various platforms. Spoiler: Yes, ChatGPT can save me some time.

This is the prompt I've been experimenting with:

Assume you are the organizer of phpugmrn meetup, and you want to advertise the next event happening on the [DATE] on social media. The next event will take place at the [COMPANY] office in [CITY]. You found 2 speakers for the event. 

The first speaker is [FIRST SPEAKER], and his talk is called '[FIRST TALK]' and the speaker will introduce us [FIRST TALK DETAILS].
The second speaker is [SECOND SPEAKER], and his talk is called '[SECOND TALK]'. The talk covers [SECOND TALK DETAILS].

To advertise the event, please create 3 social media posts that include the date and at least one of the speakers and their talks. Include the hashtags #phpugmrn #phpc #rheinneckarrocks as well as the sign-up link [LINK]

What does the response look like? Well, see below for the output to advertise the phpugmrn meetup on December 14th:

📣 Get ready for the next #phpugmrn meetup on December 14th! Join us at Wawibox, Heidelberg, and dive into the world of authentication methods with Niko Köbler. Don't miss his talk 'Auth{N,Z}: OAuth2, OpenID Connect und JWT einfach erklärt'. Sign up now: #phpc #rheinneckarrocks

🚀 Exciting news! We have Simon Brüchner joining us at the #phpugmrn meetup on December 14th. He will be sharing insights on how Wawibox utilizes Domain Driven Design in their daily work. Make sure to attend his talk 'PHP & DDD bei Wawibox' and level up your skills. Sign up here: #phpc #rheinneckarrocks

🎉 Mark your calendars for December 14th! The #phpugmrn meetup is back with an amazing lineup of speakers. Join us at Wawibox, Heidelberg, and learn from Niko Köbler as he simplifies authentication methods in his talk 'Auth{N,Z}: OAuth2, OpenID Connect und JWT einfach erklärt'. Secure your spot now: