Chatbot in PHP with OpenAI API

Last time I tried connecting to the OpenAI API in this post (OpenAi en PHP), so now I wanted to build something with it.

I know there are lots of tools that make you a chatbot in minutes without programming skills and it’s super easy with an awesome UI… However, I wanted to know how a chatbot was made, at least a basic one.

So here it is my own chatbot:

It ‘s a sort of a web assistant that tries to help you in the task of hiring a web development service of a hipothetical ecommerce agency. Of course, the prompt can be better, it needs a lot of refactoring and testing of edge cases… but it makes its job 🙂

The main point was to study how to keep the entire conversation context. Because when I was triying the OpenAI API by itself, I didn’t see any option to keep track of the messages (I thought that the API maybe was handling this… but now I see it actually makes no sense).

The other point was that I wanted to slice the prompt into small pieces, so that I could reuse this code with another chatbot. Something like «presentation», «main objectives», «restrictions», «conversation tone», etc… So it can be easily reusable.