├── License.txt ├── README.md ├── config ├── api.php ├── chatbot.sql └── db.php └── public ├── License.txt ├── Readme.md ├── css └── style.css ├── img ├── chatbot_img.png └── dots-loading.gif ├── index.html ├── index.php └── js └── app.js /License.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Vikashkumar1111 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chat_bot API Project in PHP 2 | 3 | This project is an **ChatGpt** **API** for a chat bot implemented in PHP. The API provides endpoints for sending messages to the bot, retrieving responses, and managing conversation history. 4 | 5 | Using this project integrates of OpenAI ChatGPT API for text completion. The API provides an easy way to generate human-like text using natural language processing. 6 | 7 | ## Getting Started 8 | 9 | To get started with this project, you will need to have PHP and a web server installed on your machine. You will also need a database to store conversation history. 10 | 11 | And,you will need an OpenAI API key. You can sign up for an API key on the [OpenAI website](https://beta.openai.com/signup/). 12 | 13 | ### Installation 14 | 15 | Clone the repository to your local machine. 16 | 17 | git clone https://github.com/vikashkumar1111/Chat_bot.git 18 | 19 | 20 | ## Screenshot 21 |
id, name, email, password, phone, address, city, state, zip, country, created_at, updated_at\n
\nI want to insert data into this table using phpmyadmin. I have tried the following syntax:\nINSERT INTO `users` (`id`, `name`, `email`, `password`, `phone`, `address`, `city`, `state`, `zip`, `country`, `created_at`, `updated_at`) VALUES (NULL, \'John\', \'john@gmail.com\', \'123456\', \'1234567890\', \'123 Main St\', \'New York\', \'NY\', \'10001\', \'USA\', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);\n
\nBut I get the following error:\n#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'NULL, \'John\', \'john@gmail.com\', \'123456\', \'1234567890\', \'123 Main St\', \'New York\', \' at line 1\n
\nWhat is the correct syntax to insert data into this table?\n\n\nA:\n\nYou have to remove the NULL
from the VALUES
clause.\nINSERT INTO `users` (`id`, `name`, `email`, `password`, `phone`, `address`, `city`, `state`, `zip`, `country`, `created_at`, `updated_at`) VALUES ( \'John\', \'john@gmail.com\', \'123456\', \'1234567890\', \'123 Main St\', \'New York\', \'NY\', \'10001\', \'USA\', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);\n
\n', '2023-02-20'),
54 | (18, '\"Hello\" (Php)', '2023-02-20', '\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello\" (Php)\n\n\"Hello', '2023-02-20'),
55 | (19, 'write syntax to print hello world', '2023-02-20', '\n\nconsole.log(\"Hello World!\");', '2023-02-20'),
56 | (20, 'write syntax to print hello world in php', '2023-02-20', '\n\n', '2023-02-20'),
57 | (21, 'What is UPI', '2023-02-21', 'Oops! We ran into an issue in :Internal server error', '2023-02-21'),
58 | (22, 'What is UPI', '2023-02-21', '\n\nUPI stands for Unified Payments Interface. It is an instant real-time payment system developed by the National Payments Corporation of India (NPCI) that facilitates inter-bank transactions. The interface is regulated by the Reserve Bank of India and works by instantly transferring funds between two bank accounts on a mobile platform.', '2023-02-21'),
59 | (23, 'Hi', '2023-02-21', ',\n\nI am trying to use the \"Create a new project\" feature in the Project Center. I am getting an error message that says \"The project could not be created. Please try again later.\"\n\nThis could be due to a few different reasons. First, make sure that you have the correct permissions to create a new project. If you do not have the correct permissions, contact your system administrator.\n\nSecond, make sure that you have the correct project template selected. If you are using a custom template, make sure that it is properly configured.\n\nFinally, make sure that you have the correct project information entered. If any of the required fields are missing or incorrect, the project will not be created.\n\nIf you are still having trouble, contact your system administrator for further assistance.\n\nThanks,\n\nJohn', '2023-02-21'),
60 | (24, 'Hi', '2023-02-21', ',\n\nI am trying to use the \"Create a new project\" feature in the Project Center. I am getting an error message that says \"The project could not be created. Please try again later.\"\n\nThis could be due to a few different reasons. First, make sure that you have the correct permissions to create a new project. If you do not have the correct permissions, contact your system administrator.\n\nSecond, make sure that you have the correct project template selected. If you are using a custom template, make sure that it is properly configured.\n\nFinally, make sure that you have the correct project information entered. If any of the required fields are missing or incorrect, the project will not be created.\n\nIf you are still having trouble, contact your system administrator for further assistance.\n\nThanks,\n\nJohn', '2023-02-21'),
61 | (25, 'who is the founder of mouse', '2023-02-21', '\n\nThe computer mouse was invented by Douglas Engelbart in 1964.', '2023-02-21'),
62 | (26, 'who is the founder of Keyboard', '2023-02-21', '\n\nThe first keyboard was invented by Christopher Latham Sholes in 1868.', '2023-02-21'),
63 | (27, 'who is the founder of computer', '2023-02-21', '\n\nThe first modern computer was the ENIAC (Electronic Numerical Integrator and Computer), which was invented by John Presper Eckert and John Mauchly in 1946.', '2023-02-21'),
64 | (28, 'who is the founder of AI', '2023-02-21', '\n\nThe term \"artificial intelligence\" was coined in 1956 by John McCarthy, an American computer scientist and cognitive scientist.', '2023-02-21'),
65 | (29, 'what is php', '2023-02-21', '\n\nPHP (Hypertext Preprocessor) is a server-side scripting language used to create dynamic web pages. It is a widely-used open source language that is especially suited for web development and can be embedded into HTML. PHP code is executed on the server and the result is returned to the browser as plain HTML.', '2023-02-21'),
66 | (30, 'who is vikash', '2023-02-21', '\n\nVikash is a software engineer and entrepreneur from India. He is the founder and CEO of a software development company called Vyom Labs. He has over 10 years of experience in software development and has worked on projects for companies such as Microsoft, Oracle, and IBM. He is passionate about technology and is always looking for ways to use it to make the world a better place.', '2023-02-21'),
67 | (31, 'tells me about mars', '2023-02-21', '\n\nMars is the fourth planet from the Sun and the second-smallest planet in the Solar System, after Mercury. It is named after the Roman god of war, Mars. It is a terrestrial planet with a thin atmosphere composed primarily of carbon dioxide. The surface of Mars is covered with craters, volcanoes, valleys, deserts, and polar ice caps. It has two moons, Phobos and Deimos, which are small and irregularly shaped. Mars is home to the highest mountain in the Solar System, Olympus Mons, and the deepest canyon, Valles Marineris.', '2023-02-21'),
68 | (32, 'what is light year', '2023-02-21', '\n\nA light year is a unit of distance used to measure astronomical distances. It is the distance that light travels in one year, which is approximately 9.5 trillion kilometers (or 5.9 trillion miles).', '2023-02-21'),
69 | (33, 'subset of array', '2023-02-21', '\n\nA subset of an array is a smaller array that contains elements from the original array. For example, if the original array is [1, 2, 3, 4, 5], then a subset of this array could be [2, 4].', '2023-02-21'),
70 | (34, 'amstrong in java', '2023-02-21', '\n\npublic class ArmstrongNumber {\n\n public static void main(String[] args) {\n\n int number = 153;\n int originalNumber, remainder, result = 0;\n\n originalNumber = number;\n\n while (originalNumber != 0)\n {\n remainder = originalNumber % 10;\n result += Math.pow(remainder, 3);\n originalNumber /= 10;\n }\n\n if(result == number)\n System.out.println(number + \" is an Armstrong number.\");\n else\n System.out.println(number + \" is not an Armstrong number.\");\n }\n}', '2023-02-21'),
71 | (35, 'what is ArmstrongNumber ', '2023-02-21', '\n\nAn Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits. For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153.', '2023-02-21'),
72 | (36, 'how to make scroller scroll to bottom in jquery', '2023-02-21', '\n\nYou can use the jQuery animate() method to scroll to the bottom of an element.\n\n$(\'html, body\').animate({scrollTop:$(document).height()}, \'slow\');', '2023-02-21');
73 |
74 | --
75 | -- Indexes for dumped tables
76 | --
77 |
78 | --
79 | -- Indexes for table `chat_data`
80 | --
81 | ALTER TABLE `chat_data`
82 | ADD PRIMARY KEY (`id`);
83 |
84 | --
85 | -- AUTO_INCREMENT for dumped tables
86 | --
87 |
88 | --
89 | -- AUTO_INCREMENT for table `chat_data`
90 | --
91 | ALTER TABLE `chat_data`
92 | MODIFY `id` int(50) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=37;
93 | COMMIT;
94 |
95 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
96 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
97 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
98 |
--------------------------------------------------------------------------------
/config/db.php:
--------------------------------------------------------------------------------
1 | servername = $servername;
11 | $this->username = $username;
12 | $this->password = $password;
13 | $this->dbname = $dbname;
14 | }
15 | function connect() {
16 | $this->conn = new mysqli($this->servername, $this->username, $this->password, $this->dbname);
17 | if ($this->conn->connect_error) {
18 | die("Connection failed: " . $this->conn->connect_error);
19 | }
20 | return $this->conn;
21 | }
22 | }
23 | $servername = "localhost";
24 | $username = "root";
25 | $password = "";
26 | $dbname = "chatbot";
27 |
28 | $connection = new DatabaseConnection($servername, $username, $password, $dbname);
29 | $conn = $connection->connect();
30 |
31 | ?>
--------------------------------------------------------------------------------
/public/License.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Vikashkumar1111
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/public/Readme.md:
--------------------------------------------------------------------------------
1 | # Chat_bot API Project in PHP
2 |
3 | This project is an **ChatGpt** **API** for a chat bot implemented in PHP. The API provides endpoints for sending messages to the bot, retrieving responses, and managing conversation history.
4 |
5 | Using this project integrates of OpenAI ChatGPT API for text completion. The API provides an easy way to generate human-like text using natural language processing.
6 |
7 | ## Getting Started
8 |
9 | To get started with this project, you will need to have PHP and a web server installed on your machine. You will also need a database to store conversation history.
10 |
11 | And,you will need an OpenAI API key. You can sign up for an API key on the [OpenAI website](https://beta.openai.com/signup/).
12 |
13 | ### Installation
14 |
15 | 1. Clone the repository to your local machine.
16 |
17 | git clone https://github.com/vikashkumar1111/Chat_bot.git
18 |
19 |
20 | 2. Install dependencies using Composer.
21 |
22 | cd Chat_bot
23 |
24 | composer instal
25 |
26 |
27 |
28 |
29 | ## Usage
30 |
31 | ### Sending a message to the bot
32 |
33 | To send a message to the bot, make a POST request to the `/api/messages` endpoint with the following JSON payload:
34 |
35 | {
36 | "model": "text-davinci-003",
37 | "prompt": "Write a tagline for an ice cream shop.",
38 | "temperature": 0.4,
39 | "max_tokens": 64,
40 | "top_p": 1,
41 | "frequency_penalty": 0,
42 | "presence_penalty": 0
43 | }
44 |
45 |
46 |
47 | ### Retrieving bot responses
48 |
49 | To retrieve responses from the bot, make a GET request to the `/api/messages` endpoint with the following query parameters:
50 |
51 | - `user_id`: The ID of the user who sent the message.
52 | - `limit`: The maximum number of responses to retrieve (optional, default is 10).
53 |
54 | ### Managing conversation history
55 |
56 | The API also provides endpoints for managing conversation history:
57 |
58 | - `GET /api/conversations`: Retrieve a list of all conversations.
59 | - `GET /api/conversations/{id}`: Retrieve a specific conversation by ID.
60 |
61 |
62 |
63 | You can find a complete list of available parameters in the [OpenAI API documentation](https://beta.openai.com/docs/api-reference/completions/create).
64 |
65 |
66 | ## License
67 |
68 | This project is licensed under the MIT License - see the [LICENSE](/License.txt) file for details.
69 |
70 |
71 | I hope this helps you integrate the **ChatGPT** **API** into your project!
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/public/css/style.css:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css?family=Roboto');
2 |
3 | * {
4 | box-sizing: border-box;
5 | }
6 |
7 | body {
8 | margin: 0;
9 | padding: 0;
10 | font-family: 'Roboto', sans-serif;
11 | background-color: #f5f5f5;
12 | }
13 |
14 | .container {
15 | max-width: 600px;
16 | margin: 0 auto;
17 | padding: 20px;
18 | }
19 |
20 | .header {
21 | display: flex;
22 | align-items: center;
23 | margin-bottom: 20px;
24 | }
25 |
26 | .header img {
27 | width: 50px;
28 | height: 50px;
29 | margin-right: 10px;
30 | }
31 |
32 | .chat-box {
33 | background-color: #fff;
34 | border: 1px solid #ccc;
35 | border-radius: 10px;
36 | overflow: hidden;
37 | }
38 |
39 | .messages {
40 | max-height: 500px;
41 | overflow-y: auto;
42 | }
43 |
44 | .message {
45 | display: flex;
46 | align-items: flex-end;
47 | margin-bottom: 10px;
48 | padding: 10px;
49 | border-radius: 10px;
50 | }
51 |
52 | .message.received {
53 | flex-direction: row;
54 | }
55 |
56 | .message.sent {
57 | flex-direction: row-reverse;
58 | }
59 |
60 | .avatar {
61 | width: 40px;
62 | height: 40px;
63 | overflow: hidden;
64 | border-radius: 50%;
65 | margin-right: 10px;
66 | }
67 |
68 | .avatar img {
69 | width: 100%;
70 | height: 100%;
71 | }
72 |
73 | .text {
74 | background-color: #f2f2f2;
75 | padding: 10px;
76 | border-radius: 10px;
77 | max-width: 70%;
78 | }
79 |
80 | .time {
81 | font-size: 12px;
82 | margin-left: 10px;
83 | color: #666;
84 | }
85 |
86 | .input-box {
87 | display: flex;
88 | align-items: center;
89 | padding: 10px;
90 | background-color: #f5f5f5;
91 | border-top: 1px solid #ccc;
92 | }
93 |
94 | .message-input {
95 | flex-grow: 1;
96 | height: 40px;
97 | padding: 10px;
98 | border: none;
99 | border-radius: 20px;
100 | outline: none;
101 | font-size: 16px;
102 | }
103 |
104 | .send-button {
105 | width: 40px;
106 | height: 40px;
107 | border: none;
108 | border-radius: 50%;
109 | background-color: #25D366;
110 | color: #fff;
111 | font-size: 18px;
112 | margin-left: 10px;
113 | cursor: pointer;
114 | }
115 |
116 | .send-button:hover {
117 | background-color: #128C7E;
118 | }
119 |
120 | .dot-img {
121 | border-radius: 50%;
122 | width: 40px;
123 | height: 40px;
124 | }
125 |
126 | .hide {
127 | display: none;
128 | }
129 |
130 | .show {
131 | display: block;
132 | }
133 |
134 |
135 | /* Mobile */
136 | @media only screen and (max-width: 480px) {
137 | .container {
138 | max-width: 900px!important;
139 | margin: 0 auto;
140 | padding: 20px;
141 | }
142 | .header img {
143 | width: 90px;
144 | height: 90px;
145 | margin-right: 16px;
146 | }
147 | .messages {
148 | max-height: 1200px;
149 | }
150 | .avatar {
151 | width: 85px;
152 | height: 85px;
153 | }
154 | .text {
155 | max-width: 70%;
156 | font-size: 30px;
157 | line-height: 35px;
158 | word-wrap: break-word;
159 | }
160 | .time {
161 | font-size: 21px;
162 | margin: 0px 10px;
163 | }
164 | .message-input {
165 | font-size: 30px;
166 | height: 86px;
167 | padding: 15px;
168 | }
169 | .send-button {
170 | width: 80px;
171 | height: 80px;
172 | font-size: 40px;
173 | margin-left: 5px;
174 | }
175 | .dot-img {
176 | width: 75px;
177 | height: 75px;
178 | }
179 |
180 | }
181 |
182 | /* Tablet */
183 | @media only screen and (min-width: 481px) and (max-width: 768px) {
184 | /* CSS Rules */
185 | }
--------------------------------------------------------------------------------
/public/img/chatbot_img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vikashkumar1111/Chat_bot/5b7b8e9801c437b93eaa1d68f375d1c0b0c78374/public/img/chatbot_img.png
--------------------------------------------------------------------------------
/public/img/dots-loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vikashkumar1111/Chat_bot/5b7b8e9801c437b93eaa1d68f375d1c0b0c78374/public/img/dots-loading.gif
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |