since the endpoint url is changed now my code is giving me this error ,
failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
function search_api($question) {
$apiEndpoint = ‘API URL HERE/v1/chat/completions’; // Updated API endpoint
$apiKey = ‘MY_API_KEY_HERE’; // Replace with your OpenAI API key
There’s no other errors. The only way I got this is from adding a custom debug script I was told to add, drove me nuts for hours. I was using the older url for completions that’s deprecated now and saw you have to use that new url now and that’s just where I’m stuck at.
If you use /chat/completions you need to use one of the gpt-* models.
(Also, unless you really want text-davinci you should probably try the chat/completion with gpt-3.5-turbo
how im calling it is by fetching chatbot.php on html front-end
my code is fairly simple, i cant share i have a lot going on here really dont want to get out there, but the connection should be fairly simple, im not sure whats going on, my other project im using the chat/completions url fine with JS onpage but this is the first time i call it from PHP and its not working. with the same data, etc.
The chat completions endpoint is for the gpt-3.5-xxx models, and requires the ChatML list format.
For a chat completion endpoint, you will be bounced with 400 if you aren’t passing a pythonic list as $question.
davinci is a completion engine and doesn’t use completion/chat.