Interact with OpenAI's ChatGPT directly from your command line! This lightweight CLI tool allows you to send messages to ChatGPT and receive formatted responses, making it perfect for quick queries, scripting, and integrating AI into your workflow.
- Easy to Use: Simple command-line interface.
- Customizable: Choose models, output formats, and system prompts.
- Formatted Output: Supports Markdown and plain text formatting with rich display in the terminal.
- Flexible Input: Send messages via arguments or standard input.
- Lightweight Dependency: Minimal external libraries required.
- Installation
- Setup
- Usage
- Examples
- Creating a Batch File on Windows
- Contribution
- License
- Acknowledgements
- Disclaimer
-
Clone the Repository
git clone https://github.com/cabbagec2hlbGwK/AskGpt-cli cd AskGpt-cli
-
Create a Virtual Environment (Optional but Recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\\Scripts\\activate.bat
-
Install Dependencies
pip install -r requirements.txt
The tool requires an OpenAI API key to function. Set your API key as an environment variable:
-
On Unix/Linux/macOS
export OPENAI_API_KEY='your-api-key-here'
-
On Windows Command Prompt
set OPENAI_API_KEY=your-api-key-here
-
On Windows PowerShell
$env:OPENAI_API_KEY="your-api-key-here"
Replace 'your-api-key-here'
with your actual OpenAI API key.
python ask.py [options] [message]
m MODEL
,-model MODEL
: Specify the model to use (default:gpt-3.5-turbo
).-format FORMAT
: Output format (markdown
orplain
, default:markdown
).-system SYSTEM_MESSAGE
: Set a custom system prompt (default:"You are a helpful assistant."
).h
,-help
: Show help message and exit.
-
As Command-Line Arguments:
python ask.py "Your message here"
-
From Standard Input:
echo "Your message here" | python ask.py
python ask.py "What is the capital of Japan?"
Output:
----------------------------------------------------------------------------------------------------
**The capital of Japan is Tokyo.**
python ask.py -m gpt-4 "Explain the theory of relativity in simple terms."
python ask.py --system "You are a pirate speaking assistant." "Tell me a joke."
Output:
----------------------------------------------------------------------------------------------------
Arrr! Why do pirates take so long to learn the alphabet? Because they can spend years at C!
python ask.py --format plain "List three benefits of exercise."
Output:
----------------------------------------------------------------------------------------------------
1. Improves physical health by strengthening the cardiovascular system and muscles.
2. Enhances mental health by reducing stress, anxiety, and depression.
3. Boosts energy levels and promotes better sleep.
cat prompt.txt | python ask.py
To make the tool even more accessible on Windows, you can create a batch file that allows you to run the script from any directory without typing the full path every time.
-
Open Notepad or any text editor.
-
Paste the following content, replacing the path to your script:
@python "C:\\path\\to\\your\\ask.py" %*
Replace
"C:\\path\\to\\your\\ask.py"
with the actual path to yourask.py
script. -
Save the File:
- File Name: Choose a name like
askai.bat
(ensure it has a.bat
extension). - Save Location: Save the batch file in a directory that's included in your system's
PATH
environment variable, such asC:\\Windows\\
or your user directory.
- File Name: Choose a name like
-
Add to PATH (If Necessary):
- If you prefer to save it in a custom directory, you need to add that directory to your system's
PATH
environment variable. - How to Add to PATH:
- Press
Win + X
and selectSystem
. - Click on
Advanced system settings
. - Click on
Environment Variables
. - Under
System variables
, find and selectPath
, then clickEdit
. - Click
New
and add the path to the directory containing your batch file. - Click
OK
to close all dialogs.
- Press
- If you prefer to save it in a custom directory, you need to add that directory to your system's
-
Usage:
Now you can use the
askai
command from any command prompt window.askai "How does photosynthesis work?"
-
Examples:
Asking a Question:
askai "Explain Newton's laws of motion."
Using Options:
askai --format plain --system "You are a motivational coach." "Give me some advice."
- Convenience: Run the command from any directory without specifying the full path.
- Quick Access: Shorten the command to a simple word like
askai
. - Script Integration: Easily use the tool within other scripts or batch files.
Contributions are welcome! Please open an issue or submit a pull request with your improvements.
- OpenAI for providing powerful AI models.
- Rich Library for amazing terminal formatting.
This tool uses the OpenAI API, which may incur costs depending on your usage. Please monitor your API usage and understand the pricing details on the OpenAI Pricing page.
Enjoy seamless AI conversations right from your terminal! If you find this tool helpful, give it a star ⭐ on GitHub.