Git Product home page Git Product logo

orhanerday / chatgpt Goto Github PK

View Code? Open in Web Editor NEW
278.0 7.0 78.0 71 KB

ChatGPT AI Supported - ChatGPT clone is a simple web application powered by the OpenAI library and built with PHP. It allows users to chat with an AI language model that responds in real-time. Chat history is saved using cookies, and the project requires the use of an API key and enabled SQLite3.

PHP 31.92% Hack 11.49% JavaScript 33.58% CSS 20.69% Dockerfile 2.32%
php

chatgpt's Introduction

ChatGPT Clone

ChatGPT clone is a simple web application powered by the OpenAI library and built with PHP. It allows users to chat with an AI language model that responds in real-time. Chat history is saved using cookies, and the project requires the use of an API key and enabled SQLite3.

Prerequisites

Before running this project, you should have the following:

  • PHP 7.4 or later with SQLite3 enabled
  • Composer
  • An OpenAI API key (which should be set to the $open_ai_key variable in event-stream.php) Getting Started

Get Started

Enable sqlite3

  • Open the php.ini file. This file is usually located in the PHP installation directory.

  • Find the following line: ;extension=php_sqlite3.dll

  • Remove the semicolon at the beginning of the line to uncomment it.

  • Save the file.

  • Restart the web server.

  • Clone this repository to your local machine

git clone https://github.com/orhanerday/ChatGPT.git
  • Navigate to the project directory

cd ChatGPT
  • Install OrhanErday/OpenAI

composer require orhanerday/open-ai
  • Set your OpenAI API key as the $open_ai_key variable in event-stream.php

$open_ai_key = ""; 
  • Start the PHP built-in web server

php -S localhost:8000 -t .
  • Open your web browser and go to http://localhost:8000

  • You should now see the ChatGPT clone interface, where you can chat with the OpenAI language model.


ezgif-1-92e240a6d3

This project is a ChatGPT clone that allows users to chat with an AI language model trained by OpenAI. It's powered by the github.com/orhanerday/OpenAI php library, which provides an easy-to-use interface for communicating with the OpenAI API.

Image

Live Demo Video


ChatGPT_Clone-vimeo-800126555-hls-akfire_interconnect_quic_sep-436.mp4

Important Notice

This project was created to highlight the Stream Example feature of OpenAI GPT-3 Api Client in PHP by Orhan Erday, please don't have too high expectations about the project.

Donation

Buy Me A Coffee

Join our discord server

Discord Banner 2

Click here to join the Discord server

GPT-4

Change model at event-stream.php

....
$chat = $open_ai->chat([
    'model' => 'gpt-4',

....

Using Docker


Method I

Clone this repository to your local machine

git clone https://github.com/orhanerday/ChatGPT.git

Navigate to the project directory

cd ChatGPT

Build the image

docker build -t chatgpt .

Run the app

docker run -p 8000:8000 -e OPENAI_API_KEY=sk-o7hL4nCDcjw chatgpt

Open your web browser and go

http://localhost:8000


Method II

Or you can use docker hub without cloning or building;

Pull the image from Docker Hub

docker pull orhan55555/chatgpt

Run the app

docker run -p 8000:8000 -e OPENAI_API_KEY=sk-o7hL4nCDcjw orhan55555/chatgpt

Open your web browser and go

http://localhost:8000


Chat History

This project saves chat history using cookies by default. If you want to change this to use authentication instead, you can modify the code in index.php to save chat history in a database or other storage mechanism.

Credits

This project is powered by the github.com/orhanerday/OpenAI php library, which provides an easy-to-use interface for communicating with the OpenAI API.

chatgpt's People

Contributors

orhan-cmd avatar orhanerday avatar pj8912 avatar taochangle avatar thomasleveil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

chatgpt's Issues

Every time after the question is submitted, the same question and answer will appear when the webpage is refreshed{Sorry, an error occurred, can you ask your question again?}

Every time I submit a new question, as long as I don’t refresh the page or reopen the page, everything will be fine, otherwise the same question and answer will be repeated => Sorry, an error occurred, can you ask your question again?
Where am I going wrong, is it my cause?

#########################################
[root@ip-172-31-30-218 ~]# sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668

[root@ip-172-31-30-218 ~]# php --version
PHP 8.1.14 (cli) (built: Jan 9 2023 18:48:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.14, Copyright (c) Zend Technologies
with Zend OPcache v8.1.14, Copyright (c), by Zend Technologies`
#########################################

before_refresh:
before_refresh

after_refresh:
after_refresh

how to change model

i want to change to davinci but it not working only gpt-3.5-turbo is working

Unauthenticated Insecure direct object reference

On Line 8 of Api.php You are doing the following
$user_id = $_POST['user_id']; -> here there is no authentication check to the api.php endpoint to see if the user is logged in meaning You are suffering from 2 issues here lets start with the first problem you should authenticate the user before allowing them to make changes. But that does not stop the problem just restricts to your user base for anyone using this

The core problem here is by accepting the user id from the user and not session variables in the php only that the user does not control, You are allowing any user to just change or delete another users data or chat history

Personas?

According to ChatGPT, you should be able to add personas, like this:

$opts = [
    'prompt' => $prompt,
    'temperature' => 0.5,
    "max_tokens" => 2048,
	'persona' => [
		'name' => 'Zumm',
		'emotions' => [
			'friendly',
			'helpful',
			'witty'
		],
		'voice' => 'gravelly'
	],
    "frequency_penalty" => 0,
    "presence_penalty" => 0.6,
    "stream" => true,
    "top_p" => 1,
    "stop" => [" Human:", " AI:"]
];

But when I do that, I stop getting responses. Any ideas why?

Any way to make this a website chatbot?

Bro this is terrific. By any chance, is it possible to use this chat as a chatbot that appears at the bottom of a website, customer service style? Do you have a hint as of how it might be able to implement it? Thanks anyway, your work is spectacular.

gettign this error

This model's maximum context length is 4097 tokens. However, your messages resulted in 192871 tokens. Please reduce the length of the messages.

EventSource Issue

only the first word of ai response is received and then eventSource stops receiving responses in several servers.

Chunk

Hello,
I don't want "object":"chat.completion.chunk"
How I can get it on one line?

Suggestions

Hey guys, I've just checked out the repository and I'm really pleased with it. It's great. Just a couple of suggestions from me;

  • The chat window isn't auto-scrolling on new messages...so manual scrolling is necessary.
  • The code assumes that the codebase sits within the root of our web server. In my case, I needed to update some files in order to make the application work.
  • Would be nice to add an input field on startup that checks for the presence of an API key and only then load up the chat interface.
    It would be nice to form the code blocks generated by Open AI too.

I don't know if you guys accept PRs but I can certainly provide the code to cover said points in one if you accept those.

All in all, great work on this! Thank you guys.
Martin.

What is the best prompt-text for the conversation?

I came here from the openai-api project, which is awesome. I decided to use this as the "Hello World" of the api, and got it working. However, the results are quite lackluster using this project, as evidenced below:

image

ChatGPT gives vibrant answers to all the questions.

This issue exists making the chat history meaningless.

After sqlite3 writes about 20K data (~1.8k token), the event will return an error, the database cannot be updated, and the chat will not have any reply.

But when I manually delete a piece of data with more content, it works again until it "fills up" again.

Like some sort of throttling is being triggered, this issue exists making the chat history meaningless. Can you fix it?🤔

error

Help me with davinci

I'm trying to use davinci model, so I replaced model in $opts in event-stream.php:
$opts = [
'model' => 'davinci',
...
];

but now I get "Invalid URL (POST /v1/chat/completions)"

Could you point me in the right direction?

What I intend to do? I'd like to train a model with custom questions/answer and then use it in the chat. And I read that fine-tuning is available only for these models: davinci, curie, babbage, and ada

Thanks

program doesn't work properly

After I run the program, I get an error:

Warning: SQLite3::prepare(): Unable to prepare statement: 1, no such table: chat_history in /home/php/app/api.php on line 12

Fatal error: Uncaught Error: Call to a member function bindValue() on bool in /home/php/app/api.php:13 Stack trace: #0 {main} thrown in /home/php/app/api.php on line 13

Uncaught Exception: SSL certificate problem:

unable to get local issuer certificate in C:\Users\TECHQUE\Desktop\ChatGPT\vendor\orhanerday\open-ai\src\OpenAi.php:962
Stack trace:
#0 C:\Users\TECHQUE\Desktop\ChatGPT\vendor\orhanerday\open-ai\src\OpenAi.php(229): Orhanerday\OpenAi\OpenAi->sendRequest()
#1 C:\Users\TECHQUE\Desktop\ChatGPT\event-stream.php(51): Orhanerday\OpenAi\OpenAi->chat()
#2 {main}
thrown in C:\Users\TECHQUE\Desktop\ChatGPT\vendor\orhanerday\open-ai\src\OpenAi.php on line 962

The data returned is confusing when use stream

when i Log::info $data like this

$this->openAi->chat([
                'model' => 'gpt-3.5-turbo-16k',
                'messages' => $temp,
                'temperature' => 1.0,
                'max_tokens' => 3000,
                'frequency_penalty' => 0,
                'presence_penalty' => 0,
                'stream' => true
            ], function ($curl_info, $data) use ($gptArticle) {
                Log::info($data);

Sometimes it is correct:

[2023-10-12 10:05:02] local.INFO: data: {"id":"chatcmpl-88fLfcuOH33GOKQ49iq2vXAuzCHZQ","object":"chat.completion.chunk","created":1697076259,"model":"gpt-3.5-turbo-16k-0613","choices":[{"index":0,"delta":{"content":" air"},"finish_reason":null}]}


[2023-10-12 10:05:02] local.INFO: data: {"id":"chatcmpl-88fLfcuOH33GOKQ49iq2vXAuzCHZQ","object":"chat.completion.chunk","created":1697076259,"model":"gpt-3.5-turbo-16k-0613","choices":[{"index":0,"delta":{"content":" compressor"},"finish_reason":null}]}


[2023-10-12 10:05:02] local.INFO: data: {"id":"chatcmpl-88fLfcuOH33GOKQ49iq2vXAuzCHZQ","object":"chat.completion.chunk","created":1697076259,"model":"gpt-3.5-turbo-16k-0613","choices":[{"index":0,"delta":{"content":" guarantees"},"finish_reason":null}]}


[2023-10-12 10:05:02] local.INFO: data: {"id":"chatcmpl-88fLfcuOH33GOKQ49iq2vXAuzCHZQ","object":"chat.completion.chunk","created":1697076259,"model":"gpt-3.5-turbo-16k-0613","choices":[{"index":0,"delta":{"content":" the"},"finish_reason":null}]}


[2023-10-12 10:05:02] local.INFO: data: {"id":"chatcmpl-88fLfcuOH33GOKQ49iq2vXAuzCHZQ","object":"chat.completion.chunk","created":1697076259,"model":"gpt-3.5-turbo-16k-0613","choices":[{"index":0,"delta":{"content":" highest"},"finish_reason":null}]}


[2023-10-12 10:05:02] local.INFO: data: {"id":"chatcmpl-88fLfcuOH33GOKQ49iq2vXAuzCHZQ","object":"chat.completion.chunk","created":1697076259,"model":"gpt-3.5-turbo-16k-0613","choices":[{"index":0,"delta":{"content":" standard"},"finish_reason":null}]}


Sometimes it is trouble:

[2023-10-12 09:45:10] local.INFO: data: {"id":"chatcmpl-88f382uaVhRbGxjRK8xW2MsNW4832","object":"chat.completion.chunk","created":1697075110,"model":"gpt-3.5-turbo-16k-0613","c  
[2023-10-12 09:45:11] local.INFO: hoices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-88f382uaVhRbGxjRK8xW2MsNW4832","object":"chat.completion.chunk","created":1697075110,"model":"gpt-3.5-turbo
[2023-10-12 09:45:11] local.INFO: -16k-0613","choices":[{"index":0,"delta":{"content":"#"},"finish_reason":null}]}

data: {"id":"chatcmpl-88f382uaVhRbGxjRK8xW2MsNW4832","object":"chat.completion.chunk","created":1697075110,"model":"gpt-3.5-turbo-16k
[2023-10-12 09:45:11] local.INFO: -0613","choices":[{"index":0,"delta":{"content":" The"},"finish_reason":null}]}

data: {"id":"chatcmpl-88f382uaVhRbGxjRK8xW2MsNW4832","object":"chat.completion.chunk","created":1697075110,"model":"gpt-3.5-turbo-16  
[2023-10-12 09:45:11] local.INFO: k-0613","choices":[{"index":0,"delta":{"content":" Power"},"finish_reason":null}]}

data: {"id":"chatcmpl-88f382uaVhRbGxjRK8xW2MsNW4832","object":"chat.completion.chunk","created":1697075110,"model":"gpt-3.5-turbo-16k-061
[2023-10-12 09:45:11] local.INFO: 3","choices":[{"index":0,"delta":{"content":"house"},"finish_reason":null}]}

data: {"id":"chatcmpl-88f382uaVhRbGxjRK8xW2MsNW4832","object":"chat.completion.chunk","created":1697075110,"model":"gpt-3.5-turbo-16k  
[2023-10-12 09:45:11] local.INFO: -0613","choices":[{"index":0,"delta":{"content":" of"},"finish_reason":null}]}

data: {"id":"chatcmpl-88f382uaVhRbGxjRK8xW2MsNW4832","object":"chat.completion.chunk","created":1697075110,"model":"gpt-3.5-turbo-16k
[2023-10-12 09:45:11] local.INFO: -0613","choices":[{"index":0,"delta":{"content":" Efficiency"},"finish_reason":null}]}

data: {"id":"chatcmpl-88f382uaVhRbGxjRK8xW2MsNW4832","object":"chat.completion.chunk","created":1697075110,"model":"gpt-3.5-  
[2023-10-12 09:45:11] local.INFO: turbo-16k-0613","choices":[{"index":0,"delta":{"content":":"},"finish_reason":null}]}

data: {"id":"chatcmpl-88f382uaVhRbGxjRK8xW2MsNW4832","object":"chat.completion.chunk","created":1697075110,"model":"gpt-3.5-turbo
[2023-10-12 09:45:11] local.INFO: -16k-0613","choices":[{"index":0,"delta":{"content":" Un"},"finish_reason":null}]}

Very confused

Removing text-typing animation?

Hello,

I was looking for an alternative (with same algorithm (OpenAI API), as the ChatGPT main live chat website are literally freezing, not able to provide the rest of answer, as "typing effect" they use or i don't know, make the answer not complete. As i see, this app using the same effect, is there a way to just remove the effect ? As it look to be a huge problem for so many peoples (if not all) using chatgpt API, having answer from bot which was cropped for unknown reason (typing animation i guess as i tried another app which was not real time (so, no typing animation), and never ever had uncompleted answer.

Is there a way to remove typing effect from chatgpt bot ?

thanks

Docker = GPT3 or 4?

Hi

Thanks for this nice streaming feature ;-)

Does the docker use GPT3 or 4 and how do we switch please?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.