This project is a Flask web application that provides a chat assistant interface powered by OpenAI's GPT-4o-mini model. The application allows users to interact with an AI model to generate responses in a conversation format. It also includes features such as saving conversation history, switching between different conversations, and resetting the current conversation.
- Chat with AI Assistant: Users can interact with the AI assistant powered by OpenAI’s GPT-4o-mini model.
- Conversation Management: Start new conversations, switch between existing ones, or delete conversations.
- Conversation History: All previous conversations are stored and displayed in a sidebar for easy access.
- Interactive Frontend: The chat interface supports message display with a typewriter effect and uses Markdown for formatted text.
- Flask: A lightweight WSGI web application framework in Python.
- OpenAI API: GPT-4o-mini for generating chat responses.
- HTML/CSS/JavaScript: For the frontend user interface.
- Marked.js: Used for rendering Markdown content in the chat window.
- Python 3.7+
- An OpenAI API key
-
Clone this repository:
git clone https://github.com/Peyjee-W/ChatPJ.git cd ChatPJ
-
Create a virtual environment and activate it:
python3 -m venv venv source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
If there is no
requirements.txt
file, you can install the required libraries manually by running:pip install Flask openai threading webbrowser
-
Obtain your OpenAI API key from https://github.com/popjane/free_chatgpt_api and set it in the
app.py
file:openai.api_key = "your-api-key"
If you prefer not to install Python and the dependencies, you can download the pre-built executable from the releases section:
- Download the
chatwpj.zip
from the releases section. - Extract the contents of the zip file.
- Navigate to the
chatwpj\dist
directory. - Double-click
app.exe
to run the application. - After a short moment, a browser window will automatically open pointing to
http://127.0.0.1:5000/
.
You can then interact with the assistant through the web interface.
-
Start the Flask application:
python app.py
-
The app will automatically open a browser window pointing to
http://127.0.0.1:5000/
. -
You can now interact with the assistant through the web interface.
GET /
: Loads the main chat interface.POST /chat
: Sends a user's message and returns the AI's reply.POST /reset
: Resets the current conversation.POST /switch
: Switches to a different conversation based on the conversation ID.GET /get_conversation/<conversation_id>
: Retrieves the conversation history for a given ID.
- Modify the HTML and CSS in
index.html
to change the layout or styling of the chat interface. - In
app.py
, you can adjust the assistant’s behavior by modifying the system message when a new conversation is initiated:{"role": "system", "content": "You are a helpful and friendly assistant."}
Make sure to secure your OpenAI API key. Avoid hardcoding sensitive information into the code in a production environment. Use environment variables instead.
This project is licensed under the MIT License.