# ChatGPT - Command-Line Interface
![pypi](https://img.shields.io/pypi/v/chatgpt-cli-tool)
![license](https://img.shields.io/pypi/l/chatgpt-cli-tool)
![build](https://img.shields.io/badge/build-passing-brightgreen)
> CLI tool for interacting with ChatGPT using terminal
## Requirements
* Python >= 3.8.0
* OpenAI account and valid API key
## Installation
Tool can be installed using python3 `pip` command:
```sh
pip install chatgpt-cli-tool
```
Or you can install it directly form this project after building it:
```sh
python build.py
pip install dist/chatgpt-cli-tool-{version}.tar.gz
```
## Configuration
In order to use ChatGPT cli you will first need to register and create an API key on
the [official OpenAI website](https://platform.openai.com/account/api-keys).
Then you can configure the tool with your API key using any of the following options:
1. Create an **~/.chatgpt-cli/.env** file with variable **OPENAI_API_KEY**
2. Create an **.env** file in the working directory with variable **OPENAI_API_KEY**
3. Set it through environment variable **OPENAI_API_KEY**
4. Pass it as the first argument when executing this tool (e.g. `chatgpt-cli my_api_key [out_file]`)
All configurable environment variables for ChatGPT can be found in [.env.example](.env.example) file:
| Variable name | Description | Default value |
|---------------------|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| OPENAI_API_KEY | OpenAI API key used to send request | - |
| GPT_MODEL | GPT model used for chat completion | gpt-3.5-turbo |
| GPT_TEMPERATURE | GPT temperature value (between 0 and 2), lower values provide more focused and deterministic output | 1 |
| GPT_STREAM_RESPONSE | Enable OpenAI client to use Server Sent Events for streaming tokens from the API | true |
| GPT_SYSTEM_DESC | The description for the system on how to best tailor answers (disable with "None") | You are a very direct and straight-to-the-point assistant. |
| GPT_IMAGE_MODEL | GPT model used for generating images | dall-e-2 |
| GPT_IMAGE_SIZE | The generated image size (256x256, 512x512, 1024x1024, 1792x1024 or 1024x1792) | 1024x1024 |
| HISTORY_SIZE | Number of last messages to keep in history as a context for the next question | 3 |
| CHAT_TEXT_WIDTH | Maximum number of characters to display per line in interactive chat mode (0 - as much as possible) | 0 |
| CHAT_COLORED | Enable this to use colors in interactive chat mode | true |
| CHAT_COLOR_YOU | The color used for your inputs | green |
| CHAT_COLOR_AI | The colore of AI responses | white |
_Image model dall-e-2 requires image size less than or equal to 1024x1024, dall-e-3 requires greater than or equal to
1024x1024_
_Supported ANSI colors are: black, red, green, yellow, blue, magenta, cyan, and white_
## Running the CLI
If you installed the tool using pip, then simply start the cli using any of the following commands:
### chatgpt-cli [api_key] [file_out]
This command starts interactive ChatGPT where you can chat with AI in form of a dialog.
```sh
# with api key and conversation output file path
chatgpt-cli my_api_key ./path/to/chat.txt
# with api key only
chatgpt-cli my_api_key
# with conversation output file
chatgpt-cli chat.txt
# without any arguments, api key is used from env variable and conversation is not saved to file
chatgpt-cli
```
If file does not exist it will be created together with all parent directories. Otherwise, if the file already exists
the user is prompted with 3 options on how to handle the existing file content:
1. Continue conversation
2. Keep previous content and start new conversation
3. Delete previous content and start new conversation
### gpt-ai [api_key] [query]
This comand sends single chat completion prompt for given query or content, and prints the result on stdout.
```sh
# with api key and query argument
gpt-ai my_api_key "What is ChatGPT?"
# with query argument
gpt-ai "What is ChatGPT?"
# with api key and piped input
cat file.txt | gpt-ai my_api_key
# with query from stdin
cat question.txt | gpt-ai
# with both query as argument and piped input
cat long-story.txt | gpt-ai "sumarize this text in 5 bullet points"
# with both query as argument and input directly from file
gpt-ai "explain this code" < main.py
```
### gpt-img [api_key] [prompt] [img_out]
This comand generates image for given prompt or content, and stores the image in provided output path or if not
specified, prints the binary result on stdout. Some terminals like PowerShell might malform the binary content when
outputing to file.
```sh
# with api key, prompt and output image path
gpt-img my_api_key "Robot walking a dog" ./my-images/image.png
# without api key
gpt-img "Robot walking a dog" ./my-images/image.png
# without output image path, the binary image data will be outputed to stdout
gpt-img "Robot walking a dog" > image.png
# with both piped input and argument prompts
cat description.txt | gpt-img "with cartoon graphics" ./image.png
# with only piped input and output image file
cat description.txt | gpt-img ./image.png
# with only piped input and output image directed to file
cat description.txt | gpt-img > ./image.png
# with only input directly from file, binary image data will be outputed to stdout
gpt-img < idea.txt
```
API key argument is optional for all commands, but if provided it will override API key defined using environment
variables.
## Examples
### Interactive mode
![interactive chat](https://github.com/lmatosevic/chatgpt-cli/blob/main/resources/chatgpt-cli-interactive.png?raw=true)
### Single query mode
![single command](https://github.com/lmatosevic/chatgpt-cli/blob/main/resources/chatgpt-cli-gpt-ai.png?raw=true)
## Recommendations
### ChatGPT-Slackbot
If you are a regular Slack user, check out my other project which provides seamless ChatGPT and Slack
integration: https://github.com/lmatosevic/chatgpt-slackbot
## License
ChatGPT-Cli is [MIT licensed](LICENSE).
Raw data
{
"_id": null,
"home_page": "https://github.com/lmatosevic/chatgpt-cli",
"name": "chatgpt-cli-tool",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8.0",
"maintainer_email": null,
"keywords": "chatgpt, openai, dall-e, cli, chat",
"author": "luka",
"author_email": "lukamatosevic5@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/98/04/c19b27d4478f1375de9ccc3b28a7ebf0f94fb1e95e21067777b90cdf1b2f/chatgpt-cli-tool-1.9.0.tar.gz",
"platform": null,
"description": "# ChatGPT - Command-Line Interface\r\n\r\n![pypi](https://img.shields.io/pypi/v/chatgpt-cli-tool)\r\n![license](https://img.shields.io/pypi/l/chatgpt-cli-tool)\r\n![build](https://img.shields.io/badge/build-passing-brightgreen)\r\n\r\n> CLI tool for interacting with ChatGPT using terminal\r\n\r\n## Requirements\r\n\r\n* Python >= 3.8.0\r\n* OpenAI account and valid API key\r\n\r\n## Installation\r\n\r\nTool can be installed using python3 `pip` command:\r\n\r\n```sh\r\npip install chatgpt-cli-tool\r\n```\r\n\r\nOr you can install it directly form this project after building it:\r\n\r\n```sh\r\npython build.py\r\n\r\npip install dist/chatgpt-cli-tool-{version}.tar.gz\r\n```\r\n\r\n## Configuration\r\n\r\nIn order to use ChatGPT cli you will first need to register and create an API key on\r\nthe [official OpenAI website](https://platform.openai.com/account/api-keys).\r\n\r\nThen you can configure the tool with your API key using any of the following options:\r\n\r\n1. Create an **~/.chatgpt-cli/.env** file with variable **OPENAI_API_KEY**\r\n2. Create an **.env** file in the working directory with variable **OPENAI_API_KEY**\r\n3. Set it through environment variable **OPENAI_API_KEY**\r\n4. Pass it as the first argument when executing this tool (e.g. `chatgpt-cli my_api_key [out_file]`)\r\n\r\nAll configurable environment variables for ChatGPT can be found in [.env.example](.env.example) file:\r\n\r\n| Variable name | Description | Default value |\r\n|---------------------|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------|\r\n| OPENAI_API_KEY | OpenAI API key used to send request | - |\r\n| GPT_MODEL | GPT model used for chat completion | gpt-3.5-turbo |\r\n| GPT_TEMPERATURE | GPT temperature value (between 0 and 2), lower values provide more focused and deterministic output | 1 |\r\n| GPT_STREAM_RESPONSE | Enable OpenAI client to use Server Sent Events for streaming tokens from the API | true |\r\n| GPT_SYSTEM_DESC | The description for the system on how to best tailor answers (disable with \"None\") | You are a very direct and straight-to-the-point assistant. |\r\n| GPT_IMAGE_MODEL | GPT model used for generating images | dall-e-2 |\r\n| GPT_IMAGE_SIZE | The generated image size (256x256, 512x512, 1024x1024, 1792x1024 or 1024x1792) | 1024x1024 |\r\n| HISTORY_SIZE | Number of last messages to keep in history as a context for the next question | 3 |\r\n| CHAT_TEXT_WIDTH | Maximum number of characters to display per line in interactive chat mode (0 - as much as possible) | 0 |\r\n| CHAT_COLORED | Enable this to use colors in interactive chat mode | true |\r\n| CHAT_COLOR_YOU | The color used for your inputs | green |\r\n| CHAT_COLOR_AI | The colore of AI responses | white |\r\n\r\n_Image model dall-e-2 requires image size less than or equal to 1024x1024, dall-e-3 requires greater than or equal to\r\n1024x1024_\r\n\r\n_Supported ANSI colors are: black, red, green, yellow, blue, magenta, cyan, and white_\r\n\r\n## Running the CLI\r\n\r\nIf you installed the tool using pip, then simply start the cli using any of the following commands:\r\n\r\n### chatgpt-cli [api_key] [file_out]\r\n\r\nThis command starts interactive ChatGPT where you can chat with AI in form of a dialog.\r\n\r\n```sh\r\n# with api key and conversation output file path\r\nchatgpt-cli my_api_key ./path/to/chat.txt\r\n\r\n# with api key only\r\nchatgpt-cli my_api_key\r\n\r\n# with conversation output file\r\nchatgpt-cli chat.txt\r\n\r\n# without any arguments, api key is used from env variable and conversation is not saved to file\r\nchatgpt-cli\r\n```\r\n\r\nIf file does not exist it will be created together with all parent directories. Otherwise, if the file already exists\r\nthe user is prompted with 3 options on how to handle the existing file content:\r\n\r\n1. Continue conversation\r\n2. Keep previous content and start new conversation\r\n3. Delete previous content and start new conversation\r\n\r\n### gpt-ai [api_key] [query]\r\n\r\nThis comand sends single chat completion prompt for given query or content, and prints the result on stdout.\r\n\r\n```sh\r\n# with api key and query argument\r\ngpt-ai my_api_key \"What is ChatGPT?\"\r\n\r\n# with query argument\r\ngpt-ai \"What is ChatGPT?\"\r\n\r\n# with api key and piped input\r\ncat file.txt | gpt-ai my_api_key\r\n\r\n# with query from stdin\r\ncat question.txt | gpt-ai\r\n\r\n# with both query as argument and piped input\r\ncat long-story.txt | gpt-ai \"sumarize this text in 5 bullet points\"\r\n\r\n# with both query as argument and input directly from file\r\ngpt-ai \"explain this code\" < main.py\r\n```\r\n\r\n### gpt-img [api_key] [prompt] [img_out]\r\n\r\nThis comand generates image for given prompt or content, and stores the image in provided output path or if not\r\nspecified, prints the binary result on stdout. Some terminals like PowerShell might malform the binary content when\r\noutputing to file.\r\n\r\n```sh\r\n# with api key, prompt and output image path\r\ngpt-img my_api_key \"Robot walking a dog\" ./my-images/image.png\r\n\r\n# without api key\r\ngpt-img \"Robot walking a dog\" ./my-images/image.png\r\n\r\n# without output image path, the binary image data will be outputed to stdout\r\ngpt-img \"Robot walking a dog\" > image.png\r\n\r\n# with both piped input and argument prompts\r\ncat description.txt | gpt-img \"with cartoon graphics\" ./image.png\r\n\r\n# with only piped input and output image file\r\ncat description.txt | gpt-img ./image.png\r\n\r\n# with only piped input and output image directed to file\r\ncat description.txt | gpt-img > ./image.png\r\n\r\n# with only input directly from file, binary image data will be outputed to stdout\r\ngpt-img < idea.txt\r\n```\r\n\r\nAPI key argument is optional for all commands, but if provided it will override API key defined using environment\r\nvariables.\r\n\r\n## Examples\r\n\r\n### Interactive mode\r\n\r\n![interactive chat](https://github.com/lmatosevic/chatgpt-cli/blob/main/resources/chatgpt-cli-interactive.png?raw=true)\r\n\r\n### Single query mode\r\n\r\n![single command](https://github.com/lmatosevic/chatgpt-cli/blob/main/resources/chatgpt-cli-gpt-ai.png?raw=true)\r\n\r\n## Recommendations\r\n\r\n### ChatGPT-Slackbot\r\n\r\nIf you are a regular Slack user, check out my other project which provides seamless ChatGPT and Slack\r\nintegration: https://github.com/lmatosevic/chatgpt-slackbot\r\n\r\n## License\r\n\r\nChatGPT-Cli is [MIT licensed](LICENSE).\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Command-line interface tool for interacting with ChatGPT using terminal",
"version": "1.9.0",
"project_urls": {
"Download": "https://github.com/lmatosevic/chatgpt-cli/archive/refs/tags/1.9.0.tar.gz",
"Homepage": "https://github.com/lmatosevic/chatgpt-cli"
},
"split_keywords": [
"chatgpt",
" openai",
" dall-e",
" cli",
" chat"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "52cbe3781af152ae8e2674757cbc6e4296398fb8ffa511ed9c5b6b4e9ec1ef89",
"md5": "0bef5b948812f73157db37344a9cc7e9",
"sha256": "afe1c23647352b0297a55906d556860c499c580608a2ed86a9507909b627ecf7"
},
"downloads": -1,
"filename": "chatgpt_cli_tool-1.9.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0bef5b948812f73157db37344a9cc7e9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.0",
"size": 11376,
"upload_time": "2024-06-24T10:26:10",
"upload_time_iso_8601": "2024-06-24T10:26:10.419355Z",
"url": "https://files.pythonhosted.org/packages/52/cb/e3781af152ae8e2674757cbc6e4296398fb8ffa511ed9c5b6b4e9ec1ef89/chatgpt_cli_tool-1.9.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9804c19b27d4478f1375de9ccc3b28a7ebf0f94fb1e95e21067777b90cdf1b2f",
"md5": "66b7069dd056e6d65f701a3010402077",
"sha256": "3fad5ff8b8db5b82d06a55cf3641abe578573f00d2cabcda0d0536c32387f56c"
},
"downloads": -1,
"filename": "chatgpt-cli-tool-1.9.0.tar.gz",
"has_sig": false,
"md5_digest": "66b7069dd056e6d65f701a3010402077",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.0",
"size": 9878,
"upload_time": "2024-06-24T10:26:13",
"upload_time_iso_8601": "2024-06-24T10:26:13.797237Z",
"url": "https://files.pythonhosted.org/packages/98/04/c19b27d4478f1375de9ccc3b28a7ebf0f94fb1e95e21067777b90cdf1b2f/chatgpt-cli-tool-1.9.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-24 10:26:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lmatosevic",
"github_project": "chatgpt-cli",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "openai",
"specs": [
[
"==",
"0.27.8"
]
]
},
{
"name": "python-dotenv",
"specs": [
[
"==",
"1.0.0"
]
]
},
{
"name": "colorama",
"specs": [
[
"==",
"0.4.6"
]
]
},
{
"name": "prompt-toolkit",
"specs": [
[
"==",
"3.0.39"
]
]
}
],
"lcname": "chatgpt-cli-tool"
}