Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 0 additions & 73 deletions .env

This file was deleted.

5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# OpenRouter API Configuration
OPENROUTER_API_KEY=

# OpenRouter Model Configuration
OPENROUTER_MODEL=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Ignore chat session logs
chat_sessions/
.DS_Store

# Ignore user-edited config files
.env

# Common log files
*.log
Expand Down
71 changes: 71 additions & 0 deletions .models
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#####################################################
# DO NOT EDIT THIS FILE AS IT WILL BREAKE THE UPDATES
#####################################################

############### OpenRouter Modes ###############
# If you want to use a specific model, copy one of the lines below and put it in the OPENROUTER_MODEL= of your .env file.
# If not set, it will default to "OPENROUTER_MODEL=mistralai/mistral-small-3.2-24b-instruct:free"
# You can also set it to any model available on OpenRouter: https://openrouter.ai/models
# Additional free models commonly available on OpenRouter :

agentica-org/deepcoder-14b-preview:free
arliai/qwq-32b-arliai-rpr-v1:free
cognitivecomputations/dolphin-mistral-24b-venice-edition:free
cognitivecomputations/dolphin3.0-mistral-24b:free
cognitivecomputations/dolphin3.0-r1-mistral-24b:free
deepseek/deepseek-chat:free
deepseek/deepseek-chat-v3-0324:free
deepseek/deepseek-r1-0528:free
deepseek/deepseek-r1-0528-qwen3-8b:free
deepseek/deepseek-r1-distill-llama-70b:free
deepseek/deepseek-r1-distill-qwen-14b:free
deepseek/deepseek-r1:free
deepseek/deepseek-v3-base:free
featherless/qwerky-72b:free
google/gemini-2.0-flash-exp:free
google/gemini-2.5-pro-exp-03-25
google/gemma-2-9b-it:free
google/gemma-3-12b-it:free
google/gemma-3-27b-it:free
google/gemma-3-4b-it:free
google/gemma-3n-e2b-it:free
google/gemma-3n-e4b-it:free
microsoft/mai-ds-r1:free
mistralai/devstral-small-2505:free
mistralai/mistral-7b-instruct:free
mistralai/mistral-nemo:free
mistralai/mistral-small-24b-instruct-2501:free
mistralai/mistral-small-3.1-24b-instruct:free
mistralai/mistral-small-3.2-24b-instruct:free
moonshotai/kimi-dev-72b:free
moonshotai/kimi-vl-a3b-thinking:free
meta-llama/llama-3.1-405b-instruct:free
meta-llama/llama-3.2-11b-vision-instruct:free
meta-llama/llama-3.2-3b-instruct:free
meta-llama/llama-3.3-70b-instruct:free
meta-llama/llama-4-maverick:free
meta-llama/llama-4-scout:free
nousresearch/deephermes-3-llama-3-8b-preview:free
nvidia/llama-3.1-nemotron-ultra-253b-v1:free
nvidia/llama-3.3-nemotron-super-49b-v1:free
openai/gpt-oss-20b:free
openrouter/cypher-alpha:free
qwen/qwen-2.5-72b-instruct:free
qwen/qwen-2.5-coder-32b-instruct:free
qwen/qwen3-14b:free
qwen/qwen3-30b-a3b:free
qwen/qwen3-32b:free
qwen/qwen3-4b:free
qwen/qwen3-8b:free
qwen/qwen3-235b-a22b:free
qwen/qwen2.5-vl-32b-instruct:free
qwen/qwen2.5-vl-72b-instruct:free
qwen/qwq-32b:free
rekai/reka-flash-3:free
sarvamai/sarvam-m:free
shisa-ai/shisa-v2-llama3.3-70b:free
tencent/hunyuan-a13b-instruct:free
thudm/glm-4-32b:free
thudm/glm-z1-32b:free
tngtech/deepseek-r1t-chimera:free
tngtech/deepseek-r1t2-chimera:free
43 changes: 28 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ Please note that free models on openrouter.ai (those with :free in their slug) a

## Features
- 🚀 Minimalist CLI interface — talk to AI directly from your terminal.
- 🔑 Secure API key & model config — stored in .env file, no need to enter every time.
- 🔑 Secure API key & model config — stored in .env file (create it by copiing .env.example), no need to enter every time.
- 🔄 Easy update: Run `ai.sh --update` to get the latest version.
- 📖 Built-in help: Run `ai.sh --help` for usage instructions.
- 🤖 Full session memory — ongoing conversations with proper context (stateful chat).
- 💬 Natural language queries — just type like you're talking to a buddy.
- 💾 Chat history saved — all conversations stored as timestamped .txt files inside chat_sessions/.
- 💾 Chat history saved — all conversations stored as timestamped .txt files inside `chat_sessions/`.
- 🧠 Dynamic AI name display — bot replies are labeled with the selected model (e.g. Mistral AI:).
- 👤 Personalized & interactive input — uses your system username in the prompt and supports arrow keys for editing your message like a real terminal app.
- 🧹 Clean output — only the answer, no JSON noise.
- 🆓 Uses a free model by default — no paid account required.
- 🔍 Smart package manager detection — if curl or jq is missing, the script tells you exactly how to install it (e.g. sudo pacman -S jq).
- 🧪 Works on Linux & macOS — tested on Arch-based, Debian-based and macOS (via brew).
- ✨ Zero dependencies beyond curl + jq — no Python, no Node.js, no drama.
- 🐞 Debug mode support — run with DEBUG=true to see full raw API responses on errors in the terminal.
- 🆓 Uses a free model by default — no paid account required only your API key.
- 🔍 Smart package manager detection — if curl or jq is missing, the script tells you exactly how to install it (e.g. `sudo pacman -S jq)`.
- 🧪 Works on Linux & macOS and Windows through WLS — tested on Arch-based, Debian-based and macOS (via brew).
- ✨ Zero dependencies beyond `curl` and `jq` — no Python, no Node.js, no drama.
- 🐞 Debug mode support — run with `DEBUG=true ai.sh` to see full raw API responses on errors in the terminal.
- 🧼 Session history is always clean — error messages are never saved in the logs, whether debug mode is on or off (default).

### Important Note
Expand Down Expand Up @@ -79,8 +81,9 @@ sudo apt install jq
- Generate a new API key

4. **Configure your API key and model:**
- while you are in the openrouter folder, edit the `.env` file template and add your API key:
- Copy the example environment file and edit it:
```bash
cp .env.example .env
vim .env
```
- Add your API key and optionally configure the model:
Expand All @@ -90,8 +93,21 @@ sudo apt install jq
# OpenRouter Model Configuration (optional - leave empty for default)
OPENROUTER_MODEL=
```
- See `.models` for a list of available models. Do not edit `.models` directly.

## Usage

### Update & Help

- To update the script to the latest version:
```bash
./ai.sh --update
```

- To show usage instructions:
```bash
./ai.sh --help
```
## Creating a Terminal Alias (Recommended)

For easier access, you can create an alias so you can use the script from anywhere without typing the full path:
Expand Down Expand Up @@ -192,20 +208,17 @@ $ DEBUG=true ai

### Changing the AI Model

You can change the AI model by editing the `OPENROUTER_MODEL` variable in your `.env` file. The `.env` file now includes a comprehensive list of free models - simply uncomment the one you want to use:
You can change the AI model by editing the `OPENROUTER_MODEL` variable in your `.env` file. For available models, refer to the `.models` file in the repository root. Copy the desired model slug from `.models` and set it in your `.env`:

```bash
# Leave empty or unset to use the default model
OPENROUTER_MODEL=

# Or uncomment one of the many free models listed in .env
# OPENROUTER_MODEL=qwen/qwq-32b:free
# OPENROUTER_MODEL=deepseek/deepseek-r1-0528:free
# OPENROUTER_MODEL=google/gemini-2.0-flash-exp:free
# Example:
OPENROUTER_MODEL=qwen/qwq-32b:free
```
Check your `.env` file for the complete list.

**Note:** If `OPENROUTER_MODEL` is not set or left empty, the script will use the default Mistral model. Simply uncomment one of the free models in your `.env` file to use a different model.
**Note:** If `OPENROUTER_MODEL` is not set or left empty, the script will use the default Mistral model. Do not edit `.models` directly.

### Common Issues

Expand Down
21 changes: 21 additions & 0 deletions ai.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
# Optional: Run with DEBUG=true to enable detailed error debugging, e.g.:
# DEBUG=true ./ai.sh


# Option handling with case statement
case "$1" in
-u|--update)
echo "🔄 Updating ai.sh to the latest version..."
cd "$SCRIPT_DIR" && git pull
exit $?
;;
-h|--help)
echo -e "\nOpenRouter CLI Chat Usage:\n"
echo " ./ai.sh Start interactive chat"
echo " ./ai.sh --update Update repository (git pull)"
echo " ./ai.sh -h, --help Show this help message"
echo -e "\nEnvironment setup:"
echo " cp .env.example .env # Create your .env file"
echo " Edit .env and add your OPENROUTER_API_KEY and optionally OPENROUTER_MODEL."
echo " See .models for available models."
exit 0
;;
esac

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Check if a command exists; if missing, suggest how to install its package based on detected package manager
Expand Down Expand Up @@ -47,7 +68,7 @@

# Load .env file
if [[ -f "$SCRIPT_DIR/.env" ]]; then
source "$SCRIPT_DIR/.env"

Check notice on line 71 in ai.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] ai.sh#L71 <ShellCheck.SC1091>

Not following: ./.env: openBinaryFile: does not exist (No such file or directory)
Raw output
./ai.sh:71:10: info: Not following: ./.env: openBinaryFile: does not exist (No such file or directory) (ShellCheck.SC1091)
else
echo "❌ .env file not found in $SCRIPT_DIR"
exit 1
Expand Down Expand Up @@ -80,7 +101,7 @@

while true; do
# Interactive user input
read -e -p "🧑 $USER: " USER_INPUT

Check notice on line 104 in ai.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] ai.sh#L104 <ShellCheck.SC2162>

read without -r will mangle backslashes.
Raw output
./ai.sh:104:3: info: read without -r will mangle backslashes. (ShellCheck.SC2162)

# Skip iteration if input is empty
[[ -z "$USER_INPUT" ]] && continue
Expand Down