Skip to content

Instantly share code, notes, and snippets.

@santaklouse
Created February 26, 2026 20:40
Show Gist options
  • Select an option

  • Save santaklouse/9078a1ecd819eeb6bc047ef95bad81cc to your computer and use it in GitHub Desktop.

Select an option

Save santaklouse/9078a1ecd819eeb6bc047ef95bad81cc to your computer and use it in GitHub Desktop.

Install

mkdir -p ~/bin
chmod +x ~/bin/ai-bash.py
echo 'alias ai="python3 ~/bin/ai-bash.py"' >> ~/.bashrc

openai

export AI_BASH_URL="https://api.openai.com/v1/chat/completions"
export AI_BASH_MODEL="gpt-4o-mini"
export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"

local

  1. install Ollama curl -fsSL https://ollama.com/install.sh | sh
  2. ollama run qwen2.5:latest
export AI_BASH_URL="http://localhost:11434/api/chat/completions"
export AI_BASH_MODEL="qwen2.5:7b"
export OPENAI_API_KEY="local"
#!/usr/bin/env python3
"""ai-bash: спрашиваю по-русски — получаю bash"""
import sys, os, json, urllib.request
API_KEY = os.getenv("OPENAI_API_KEY", "")
API_URL = os.getenv("AI_BASH_URL",
"https://api.openai.com/v1/chat/completions")
MODEL = os.getenv("AI_BASH_MODEL", "gpt-4o-mini")
SYSTEM = (
"Ты — терминальный ассистент. Пользователь описывает задачу "
"на русском языке. Отвечай ТОЛЬКО bash-командой — одной строкой. "
"Без пояснений, без markdown, без обратных кавычек. "
"Несколько команд — через && или |. ОС: Linux."
)
def ask(question: str) -> str:
body = json.dumps({
"model": MODEL,
"temperature": 0,
"max_tokens": 200,
"messages": [
{"role": "system", "content": SYSTEM},
{"role": "user", "content": question},
],
}).encode()
req = urllib.request.Request(API_URL, data=body, headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}",
})
with urllib.request.urlopen(req) as r:
data = json.loads(r.read())
return data["choices"][0]["message"]["content"].strip()
def main():
if len(sys.argv) < 2:
print("Использование: ai 'найди файлы больше 100мб'")
sys.exit(1)
cmd = ask(" ".join(sys.argv[1:]))
print(f"\n \033[1;33m➜ {cmd}\033[0m\n")
if input("Выполнить? [y/N] ").strip().lower() in ("y", "д"):
os.system(cmd)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment