Back to articles
Calling OpenAI from a PHP framework the same way you query a database

Calling OpenAI from a PHP framework the same way you query a database

via Dev.to WebdevAmaury

Temma is a PHP MVC framework designed to be easy to pick up and use. It sits between micro-frameworks (too bare) and full-stack ones (too heavy), and tries to get out of your way as much as possible. One of its core concepts is the datasource: a unified way to declare and access any external connection, whether it's a database, a cache, a message queue, or an API. In Temma 2.16.0, OpenAI joins that list. Most PHP tutorials on OpenAI integration involve installing a SDK, writing a service class, injecting it manually, and wiring everything together. It works, but it's a lot of plumbing for what is ultimately a remote call. In Temma, OpenAI is a datasource. The same way you declare a MySQL connection, you declare an OpenAI connection. One line in your config, and you're done. Configuration In etc/temma.php : <?php return [ 'application' => [ 'dataSources' => [ 'db' => 'mysql://user:passwd@localhost/mybase' , 'openai' => 'openai://chat/gpt-4o/sk-proj-xxxxxxxxxxxxx' , ], ], ]; That's it. O

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles