VolkanSah / GPT-API-Integration-in-HTML-CSS-with-JS-PHP

A basic GPT conversation script designed to help you learn to interact with OpenAI's GPT technology. Includes best practices and a free security whitepaper.
https://github.com/VolkanSah/GPT-API-Integration-in-HTML-CSS-with-JS-PHP
MIT License
76 stars 55 forks source link

Issue with turbo #9

Closed oleteacher closed 1 year ago

oleteacher commented 1 year ago

Nice job!

I try to use:

define('MODEL', 'gpt-3.5-turbo');

and get the following error in console:

script.js:27 
 Error: Unexpected response format 
{error: {…}}
error
: 
{message: 'This is a chat model and not supported in the v1/c…ndpoint. Did you mean to use v1/chat/completions?', type: 'invalid_request_error', param: 'model', code: null}
[[Prototype]]
: 
Object
constructor
VolkanSah commented 1 year ago

Hi Susanne,

I hope you're doing well. I saw your GitHub issue regarding an error you encountered while using a chatbot model in your code. After reviewing your code and the error message, it appears that the model you're using, 'gpt-3.5-turbo', is not supported by the OpenAI API for the V1/c endpoint. This is because the model is a chat model, and not suitable for the V1/c endpoint.

OpenAI offers a variety of models for different use cases, including chatbots. If you're looking to create a chatbot, I recommend selecting a supported chatbot model like Davinci, Curie, Ada, Babbage, or Codex.

It's also important to ensure that the selected model is suitable for the API version you're using. Please make sure you choose the correct API version and model for your application.

-> you must use ' /v1/chat/completions' for ' gpt-3.5-turbo or gpt-3.5-turbo-0301' and not '/v1/engines/' what I use in this example setup gptchat.php & config.php to your needs

More Infos

ENDPOINT MODEL NAME
/v1/chat/completions gpt-4, gpt-4-0314, gpt-4-32k, gpt-4-32k-0314, gpt-3.5-turbo, gpt-3.5-turbo-0301
/v1/completions text-davinci-003, text-davinci-002, text-curie-001, text-babbage-001, text-ada-001
/v1/edits text-davinci-edit-001, code-davinci-edit-001
/v1/audio/transcriptions whisper-1
/v1/audio/translations whisper-1
/v1/fine-tunes davinci, curie, babbage, ada
/v1/embeddings text-embedding-ada-002, text-search-ada-doc-001
/v1/moderations text-moderation-stable, text-moderation-latest
/v1/engines/ engine v1

I hope this helps you solve the issue you encountered. If you have any further questions or concerns, please don't hesitate to reach out.

Best regards,

Volkan Sah

oleteacher commented 1 year ago

Thank you for the reply and information.

I had assumed that one could use with your chatgpt example with gpt-3.5-turbo after seeing this in your readme:

"Example for integration from GPT 3, 3.5 & 4 for your websites in HTML, CSS, JS & PHP"

Tried in your config.php:

<?php
// config file
define('OPENAI_API_KEY', 'sk-.................................');
define('MODEL', gpt-3.5-turbo');
define('TEMPERATURE', 0.9);
define('MAX_TOKENS', 1000);
define('TOP_P', 1);
define('FREQUENCY_PENALTY', 0.0);
define('PRESENCE_PENALTY', 0.0);

So, this was just misunderstanding with what was written in your readme. No biggie just thought it would be worth asking about.

Thanks again.

VolkanSah commented 1 year ago

I update the readme.md with the endpoints. Set to your needs. a 'star' will be cool if my work helps you

oleteacher commented 1 year ago

Oh yes, gave you a star!

I am doing something wrong it appears. My old brain is not grasping what you are providing:)

I have changed the following to use chatgpt-3.5-turbo:

define('MODEL', 'gpt-3.5-turbo');

Then:

curl_setopt($ch, CURLOPT_URL, "https://api.openai.com/v1/chat/" . MODEL . "/completions");

Not working, get this dev console error:

script.js:27 Error: Unexpected response format Objecterror: {message: 'Invalid URL (POST /v1/chat/gpt-3.5-turbo/completions)', type: 'invalid_request_error', param: null, code: null}[[Prototype]]: Object (anonymous) @ script.js:27

VolkanSah commented 1 year ago

look for /v1/chat/completions than . Model. use this curl_setopt($ch, CURLOPT_URL, "https://api.openai.com/v1/chat/completions" .... i will check it too, later. Must sleep :( sorry you must understand what you do there or you can harm yourself. It is a simple function. Please read https://platform.openai.com/docs/api-reference/introduction on openAi

VolkanSah commented 1 year ago

It works well please adust to your needs! Here a guidline for how handel with security tipps https://github.com/VolkanSah/ChatGPT-Security-Best-Practices