Skip to content

davidtkeane/python-command-line-chat-gpt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-command-line-chat-gpt

ChatGPT is a Python script that uses the OpenAI API to generate responses based on user input on the command line. This script can be used to create chatbots or conversational agents for a variety of purposes.

Readme.md

Hi, guys! 👋

PowerShell

GitHub last commit GitHub issues

Languages

Python

OS

Linux Windows

Welcome to ChatGPT on the command line uses with API!

I'm Rangersmyth (internet name), and I'm currently learning Python and Bash coding.


😃

ChatGPT

ChatGPT is a Python script that uses the OpenAI API to generate responses based on user input. This script can be used to create chatbots or conversational agents for a variety of purposes.

Installation

  1. Clone the repository: git clone https://github.com/davidtkeane/python-command-line-chat-gpt.git
  2. Install the required dependencies using pip: pip install -r requirements.txt
  3. FYI - I had to manually type pip3 install openai and pip3 install dotenv also as I was getting an error even when i used pip install -r requirements.txt
  4. Add your own OpenAi API key to your .env file, but first rename test.env to .env to make this work.https://platform.openai.com/
  5. Free for a certain time, then 5 Euros a month, but I have had this for a few months now and I have only clocked up €1.87 cents so far. I use https://chat.openai.com/ for most work, but love using my terminal and console!
  6. Go run the file, see below. 🍔

Nix Users

If you use Nix, you can set up the development environment automatically:

nix-shell

This will provide Python with all required dependencies — no pip install needed.

Usage

To start a conversation with the chatbot, run the following command: python chatgpt.py

  1. When you first run the file it will create a new chatgpt-chat.txt file where all of the questions you have asked will be sent to the txt file for reference later on.

The script will prompt you for input and generate a response based on your input. To end the conversation, type "no" or "nothing".

Improvements

Here are a few suggestions for improving the script:

  • Add error handling to gracefully handle API errors or other issues.
  • Implement a caching mechanism to reduce API usage and improve response times.
  • Add more options for configuring the OpenAI API parameters, such as temperature, max_tokens, and top_p.
  • Implement a GUI or web interface for the chatbot instead of a command-line interface.

Requirements.txt

Here is the requirements.txt file that includes the necessary modules for running the script:

openai
dotenv
requests
termcolor
tqdm

Changelog

2025-07-05 — Community Contributions

  • Fixed missing imports in chatgpt.py — added sleep, colored, and tqdm imports that were causing runtime errors. (PR #1 by @Endermanbugzjfc)
  • Fixed README typo — corrected pip3 install direnv to pip3 install dotenv. (PR #1 by @Endermanbugzjfc)
  • Added Nix dev-shellshell.nix for reproducible development environment with all dependencies. (PR #2 by @Endermanbugzjfc)

Contributors

Thanks to everyone who has contributed to this project!

About

ChatGPT is a Python script that uses the OpenAI API to generate responses based on user input on the command line. This script can be used to create chatbots or conversational agents for a variety of purposes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors