├── requirements.txt ├── README.md ├── server.py ├── LICENSE ├── templates └── index.html └── .gitignore /requirements.txt: -------------------------------------------------------------------------------- 1 | python-dotenv 2 | openai 3 | flask -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ChatGPT-Simple 2 | 3 | Build a simple locally hosted version of ChatGPT in less than 100 lines of code. Note: This is an unofficial ChatGPT repo and is not associated with OpenAI in anyway! 4 | 5 | ## Getting started 6 | 7 | To run the example code, you need to create an [OpenAI API key](https://platform.openai.com/account/api-keys) 8 | 9 | 1. Install requirments using 10 | ```bash 11 | $ pip install -r requirements.txt 12 | ``` 13 | 2. Create a .env file and paste your API key there 14 | ```.env 15 | OPENAI_API_KEY = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx 16 | ``` 17 | 3. Run the code and Enjoy 18 | ```bash 19 | $ python server.py 20 | ``` 21 | 22 | ## The best part 23 | 24 | This code was written by GPT-4 : ) 25 | -------------------------------------------------------------------------------- /server.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import openai 4 | from dotenv import load_dotenv 5 | from flask import Flask, render_template, request 6 | 7 | load_dotenv() # load env vars from .env file 8 | openai.api_key = os.getenv("OPENAI_API_KEY") 9 | 10 | app = Flask(__name__) 11 | 12 | 13 | @app.route("/") 14 | def index(): 15 | return render_template("index.html") 16 | 17 | 18 | @app.route("/get_response") 19 | def get_response(): 20 | message = request.args.get("message") 21 | completion = openai.ChatCompletion.create( 22 | # You can switch this to `gpt-4` if you have access to that model. 23 | model="gpt-3.5-turbo", 24 | messages=[{"role": "user", "content": message}], 25 | ) 26 | response = completion["choices"][0]["message"]["content"] 27 | return response 28 | 29 | 30 | if __name__ == "__main__": 31 | app.run(debug=True) 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Logan Kilpatrick 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |