ChatGPT / OpenAI for PHP website

Hi Team,

I am new to ChatGPT and OpenAI… Can we build OpenAI for PHP based website?

If yes can i get tutorial link or documentation to implement for my specific website which is based on PHP.

Piyush Raval


Thanks a lot for reply and guide.

I just checked below sample code

<?php require __DIR__ . '/vendor/autoload.php'; // remove this line if you use a PHP Framework. use Orhanerday\OpenAi\OpenAi; $open_ai_key = getenv('OPENAI_API_KEY'); $open_ai = new OpenAi($open_ai_key); $chat = $open_ai->chat([ 'model' => 'gpt-3.5-turbo', 'messages' => [ [ "role" => "system", "content" => "You are a helpful assistant." ], [ "role" => "user", "content" => "Who won the world series in 2020?" ], [ "role" => "assistant", "content" => "The Los Angeles Dodgers won the World Series in 2020." ], [ "role" => "user", "content" => "Where was it played?" ], ], 'temperature' => 1.0, 'max_tokens' => 4000, 'frequency_penalty' => 0, 'presence_penalty' => 0, ]); var_dump($chat); echo "
"; echo "
"; echo "
"; // decode response $d = json_decode($chat); // Get Content echo($d->choices[0]->message->content); It seems like it searches from 'model' => 'gpt-3.5-turbo', Do you know how can i make it search from my website database? As i need to build a bot for my website only. Regards, Piyush Raval

Hi @rajuroyal ,

Can you please share links?

did you just use chatgpt to generate a forum reply? because these links are all broken.
There is no “official” open ai PHP client, there are a bunch of community ones.

this is not helpful at all

1 Like

Your question is too general.
If you say exactly what you are looking to achieve with chatgpt I think I can help you.

In any case, here is some initial basic information that I hope will help you and others as a starting point for integrating gpt into a website.

In general, to create a chatbox for a php website, I came across 3 methods based on an ajax call to php script that has a simple curl command according to the chatgpt-3.5 documentation.
I’m sure there are a lot of ways and tricks that I don’t know about, I’m sharing what I know so far and that works for me after many attempts to reach the most effective chat for my sites:

  1. global chat (consulting) - {“role”: “system”, “content”: “[Providing precise instructions to gpt on how to answer according to the content of my site].”},
  • very effective in terms of the amount of tokens but the answers are too general and usually not adapted to the site, I usually present the chat box in such a way as a consultant in the field of the site.
  1. Focus on specific information on the website - {“role”: “system”, “content”: “[all the important info as text copied from my website, and answer based on this info…].”}’
  • Really focused, but the amount of tokens is very high, which makes prompts very expensive. Especially if you send the call history to the api. (which can be tricked in frontend to control it)
  1. finetuning - really accurate and helpful as a chat on the website but unfortunately not available for gpt-3.5.

instructions Tip - Provide in your gpt instructions relevant links that you have on the site or even html id tags and make them clickable in his answer in the frontend before displaying them in the conversation window.

I previously came across a post here on the forum about a conversation on this topic of how to extract massive information according to the user’s question and provide the relevant information to gpt in a prompt, but this is no longer related to working with gpt but independent analysis and extraction.

May checkout the PHP Client I’ve built.

No links allowed here, but you will find it, when searching for “openai-php/client” on packagist.