|
3 | 3 |
|
4 | 4 | 
|
5 | 5 |
|
6 |
| - |
7 | 6 | > [!IMPORTANT]
|
8 |
| -> Please note that this code example is for a basic web application to show "How to do it?", not production use! |
| 7 | +> Please note that this code example is for a basic web application to show "How to do it?", not for production use! |
9 | 8 |
|
10 |
| -### Other Important sources for you! Please read befor! |
| 9 | +### Other Important sources for you! Please read before! |
11 | 10 | - [Secure Implementation of Artificial Intelligence (AI)](https://github.com/VolkanSah/Implementing-AI-Systems-Whitepaper)
|
12 | 11 | - [GPT Security Best Practices (with GPT3.5-Turbo Example)](https://github.com/VolkanSah/GPT-Security-Best-Practices)
|
13 | 12 | ###### GPT is interesting, let's use it to create a better world.
|
14 | 13 |
|
15 |
| -This README.md file will guide you through the process of integrating the GPT API into your PHP-based website, enabling chat functionality using OpenAI's API. |
16 |
| - |
| 14 | +This README.md file will guide you through the process of integrating the GPT-4 API into your PHP-based website, enabling chat functionality using OpenAI's API. |
17 | 15 |
|
18 | 16 | ## Prerequisites
|
19 |
| -- PHP 7.4 or higher installed on your web server |
20 |
| -- A web server with support for PHP (e.g., Apache or Nginx) |
21 |
| -- Knowledge of HTML, CSS, and JavaScript (for designing the chat interface) |
22 |
| -- An API key for the GPT API from Openai.com |
| 17 | +- PHP 7.4 or higher installed on your web server |
| 18 | +- A web server with support for PHP (e.g., Apache or Nginx) |
| 19 | +- Knowledge of HTML, CSS, and JavaScript (for designing the chat interface) |
| 20 | +- An API key for the GPT API from Openai.com |
23 | 21 |
|
24 | 22 | ## API Key
|
25 |
| -- Register for an account or log in to the OpenAi platform. |
| 23 | +- Register for an account or log in to the OpenAI platform. |
26 | 24 | - Navigate to the API Keys section and generate a new API key.
|
27 | 25 | - Store the API key safely, as you will need it in the next step.
|
28 | 26 |
|
29 | 27 | ## Setting Up
|
30 |
| -- Clone or download this repository. |
31 |
| -- Replace YOUR_API_KEY and MODEL in config.php. |
32 |
| -- Replace the API_ENDPOINT URL in gptchat.php according to your needs (see list below). |
33 |
| -- Upload index.html, style.css, script.js, and gptchat.php files to your web server. |
34 |
| -- Access index.html in your browser (e.g., https://yourdomain.com/index.html). |
35 |
| -- Type a message in the chat input field and press Enter or click the Send button to send the message. |
36 |
| -- The OpenAI API should respond with a message from the language model. |
37 |
| -- Be cautious and set limits on your OpenAI Dashboard. |
38 |
| -## OpenAi-API Endpoints |
39 |
| -**please change gptchat.php & config.php to your needs** |
40 |
| - |
41 |
| -ENDPOINT | MODEL NAME |
42 |
| --- | -- |
43 |
| -/v1/chat/completions | gpt-4, gpt-4-0314, gpt-4-0613, gpt-4-32k, gpt-4-32k-0314, gpt-4-32k-0613, gpt-4-2024, gpt-4-32k-2024, gpt-3.5-turbo, gpt-3.5-turbo-0301, gpt-3.5-turbo-0613, gpt-3.5-turbo-16k, gpt-3.5-turbo-16k-0613, gpt-3.5-turbo-2024, gpt-3.5-turbo-16k-2024, gpt-3.5-turbo-0125 |
44 |
| -/v1/completions | ada, ada-code-search-code, ada-code-search-text, ada-search-document, ada-search-query, ada-similarity, babbage, babbage-code-search-code, babbage-code-search-text, babbage-search-document, babbage-search-query, babbage-similarity, code-davinci-edit-001, code-search-ada-code-001, code-search-ada-text-001, code-search-babbage-code-001, code-search-babbage-text-001, curie, curie-instruct-beta, curie-search-document, curie-search-query, curie-similarity, davinci, davinci-instruct-beta, davinci-search-document, davinci-search-query, davinci-similarity, text-ada-001, text-babbage-001, text-curie-001, text-davinci-001, text-davinci-002, text-davinci-003, text-davinci-edit-001, text-embedding-ada-002, text-embedding-3-small, text-embedding-3-large, text-search-ada-doc-001, text-search-ada-query-001, text-search-babbage-doc-001, text-search-babbage-query-001, text-search-curie-doc-001, text-search-curie-query-001, text-search-davinci-doc-001, text-search-davinci-query-001, text-similarity-ada-001, text-similarity-babbage-001, text-similarity-curie-001, text-similarity-davinci-001 |
45 |
| -/v1/edits | text-davinci-edit-001, code-davinci-edit-001 |
46 |
| -/v1/audio/transcriptions | whisper-1 |
47 |
| -/v1/audio/translations | whisper-1 |
48 |
| -/v1/fine-tunes | davinci, curie, babbage, ada |
49 |
| -/v1/embeddings | text-embedding-ada-002, text-embedding-3-small, text-embedding-3-large, text-search-ada-doc-001, text-search-ada-query-001, text-search-babbage-doc-001, text-search-babbage-query-001, text-search-curie-doc-001, text-search-curie-query-001, text-search-davinci-doc-001, text-search-davinci-query-001 |
50 |
| -/v1/moderations | text-moderation-latest, text-moderation-stable, text-moderation-007 |
51 |
| - |
52 |
| - |
53 |
| -You've successfully integrated the GPT API into your PHP website! Now, you can customize the chat interface and enhance the user experience as needed. |
54 |
| -## Screenshot |
55 |
| -<img src="screenshot.png"> |
56 |
| - |
57 |
| -**Please note that this code example is for a basic web application, and you should consider additional security measures please read [GPT Security Best Practices](https://github.com/VolkanSah/GPT-Security-Best-Practices)!** |
58 |
| - |
59 |
| - |
60 |
| - |
61 |
| -### Thanks |
62 |
| -**"Thank you! Your support is appreciated, and I would be grateful if you could share this project with others, giving a :star: to my projects, or |
63 |
| -[becoming a 'Sponsor'](https://github.com/sponsors/volkansah). Don't forget to follow me for more free ideas and updates!"** |
64 |
| - |
65 |
| -### Copyright |
66 |
| -- Volkan (Sah) Kücükbudak |
67 |
| -- [VolkanSah on Github](https://github.com/volkansah) |
68 |
| -- [Developer Site](https://volkansah.github.io) |
69 |
| - |
70 |
| -### Other cool stuff for GPT! |
71 |
| -- [OpenAI Text-to-Speech Interface](https://github.com/VolkanSah/OpenAI-Text-to-Speech-Interface) |
72 |
| -- [ChatGPT ShellMaster (ChatGPT4 Plugin](https://github.com/VolkanSah/GPT-ShellMaster) |
73 |
| -- ['GPT Comment reply' Plugin for WordPress](https://github.com/VolkanSah/GPT-Comments-Reply-WordPress-Plugin) |
74 |
| -- [GPT over CLI](https://github.com/VolkanSah/GPT-over-CLI) |
75 |
| -- [GPT-Security-Best-Practices](https://github.com/VolkanSah/GPT-Security-Best-Practices) |
76 |
| -- [OpenAi cost calculator](https://github.com/VolkanSah/OpenAI-Cost-Calculator) |
77 |
| -- [Secure Implementation of Artificial Intelligence (AI)](https://github.com/VolkanSah/Implementing-AI-Systems-Whitepaper) |
78 |
| -- [Exploring the Code Interpreter in OpenAI](https://github.com/VolkanSah/The-Code-Interpreter-in-OpenAI-ChatGPT) |
79 |
| - |
80 |
| - |
81 |
| -### License |
82 |
| -This project is copyright © [VolkanSah](https://github.com/volkansah) and is licensed under the [MIT LICENSE](LICENSE). You are free to use, modify, and distribute the code and assets, as long as the copyright notice and permission notice are preserved in all copies or substantial portions of the software." |
83 |
| - |
84 |
| - |
| 28 | +1. Clone or download this repository. |
| 29 | +2. Replace `YOUR_API_KEY` in `index.php` with your actual API key. |
| 30 | +3. Upload `index.php`, `style.css`, `script.js`, and the `templates` folder to your web server. |
| 31 | +4. Ensure the `uploads` folder exists and is writable by the web server. |
| 32 | +5. Access `index.php` in your browser (e.g., https://yourdomain.com/index.php). |
| 33 | +6. Type a message in the chat input field and press Enter or click the Send button to send the message. |
| 34 | +7. The OpenAI API should respond with a message from the language model. |
| 35 | +8. Be cautious and set limits on your OpenAI Dashboard. |
| 36 | + |
| 37 | +## OpenAI API Endpoints |
| 38 | +Ensure to adjust the API endpoint URL in `index.php` if needed. Here is an example of the API endpoint used for GPT-4: |
| 39 | +- `https://api.openai.com/v1/engines/gpt-4/completions` |
| 40 | + |
| 41 | +### File Descriptions |
| 42 | +- **index.php**: Main PHP file that handles the chat logic, communication with the OpenAI API, and file uploads. |
| 43 | +- **style.css**: CSS file for styling the chat interface. |
| 44 | +- **script.js**: JavaScript file for handling form submission and dynamically updating the chat interface. |
| 45 | +- **templates/chat.html**: HTML template for the chat interface. |
| 46 | +- **uploads/**: Directory to store uploaded images. |
| 47 | + |
| 48 | +### Example Usage |
| 49 | +1. Open `index.php` in your browser. |
| 50 | +2. Enter a message in the chat input field. |
| 51 | +3. (Optional) Upload an image. |
| 52 | +4. Click "Send" to communicate with the GPT-4 API and receive a response. |
| 53 | +5. The response will be displayed in the chat interface. |
| 54 | + |
| 55 | +Be sure to customize the application as needed to fit your requirements. |
0 commit comments