A simple command-line interface (CLI) for OpenAI's ChatGPT powered by Deno.
- Send prompts to ChatGPT and receive responses.
- Maintain conversation history.
- Clear conversation history.
- Show conversation history.
- Colored output.
- Deno: A secure runtime for JavaScript and TypeScript. Please follow the installation guide on their official website.
- Clone the repository:
git clone https://github.com/Fulviuus/chatgpt-cli
cd chatgpt-cli
- Create a
.env
file in the root directory of the project with the following content:
OPENAI_API_KEY=your_openai_api_key
MODEL_VERSION=model_version
Replace your_openai_api_key
with your actual OpenAI API key and
model_version
with the desired GPT model version (e.g., gpt-4
or
gpt-3.5-turbo
).
Navigate to the project directory and run the script with the desired options:
deno run --allow-env --allow-read --allow-write --allow-net cligpt.ts [options] [prompt]
-c
,--clear-history
: Clear conversation history.-l
,--list-history
: List conversation history.-h
,--help
: Show help information.
- Send a prompt to ChatGPT:
deno run --allow-env --allow-read --allow-write --allow-net cligpt.ts "What is the capital of France?"
- Show conversation history:
deno run --allow-env --allow-read --allow-write cligpt.ts -s
- Clear conversation history:
deno run --allow-env --allow-read --allow-write cligpt.ts -c
You can set up an alias to run the ChatGPT CLI script more easily. Add the
following lines to your shell configuration file (.bashrc
for Bash or .zshrc
for Zsh), replacing /path/to/cligpt.ts
with the actual path to the cligpt.ts
file in your project directory, and your_openai_api_key
and model_version
with your actual OpenAI API key and desired GPT model version, respectively:
Add the following line to your ~/.bashrc
:
alias cligpt='OPENAI_API_KEY=your_openai_api_key MODEL_VERSION=model_version deno run --allow-env --allow-read --allow-write --allow-net /path/to/cligpt.ts'
Then, run source ~/.bashrc
to apply the changes.
Add the following line to your ~/.zshrc
:
alias cligpt='OPENAI_API_KEY=your_openai_api_key MODEL_VERSION=model_version deno run --allow-env --allow-read --allow-write --allow-net /path/to/cligpt.ts'
Then, run source ~/.zshrc
to apply the changes.
After setting up the alias, you can use the cligpt
command followed by options
and prompts, e.g., cligpt -s
or cligpt "What is the capital of France?"
.
This project is licensed under the MIT License.