This project is a simple command-line chatbot application built using OpenAI's API, specifically using the chatgpt.py script. The chatbot is designed to handle natural language conversations, providing useful, contextually relevant responses to user inputs.
- Interactive command-line interface.
- Powered by OpenAI's
gpt-3.5-turbomodel by default. - Easy setup using an environment file for your API key.
- Easily customizable to use other OpenAI chat models.
- Python 3.x
- An API key from OpenAI.
Follow these steps to get the chatbot running on your local machine.
Clone this repository to your local machine. If you don't have a repository URL, you can just download the files.
# Example of cloning a repository
git clone <repository-url>
cd openai-chatbotThe script requires the openai and python-dotenv libraries. It's recommended to use a virtual environment. You can install them using the requirements.txt file.
# Install the required packages
pip install -r requirements.txtThe application loads your OpenAI API key from a .env file for security.
-
In the project's root directory (the same directory as
chatgpt.py), create a file named.env. -
Add the following line to the
.envfile, replacingyour-openai-api-keywith your actual secret key:OPENAI_API_KEY='your-openai-api-key'
To run the chatbot, execute the chatgpt.py script from your terminal:
python chatgptYou can now start a conversation in your terminal. To end the session, type exit and press Enter.
By default, the chatbot uses the gpt-3.5-turbo model. You can easily switch to another model available to your account (e.g., gpt-4, gpt-4-turbo) by editing the chatgpt.py file.
Locate the chatbot function and change the value of the model parameter in the client.chat.completions.create call.