AI-powered shell command generator using LLM models
Project description
Shai - AI 驱动的 Shell 命令生成器
中文版
📖 项目简介
Shai 是一个 Shell 命令生成工具,利用大型语言模型(LLM)根据自然语言描述自动生成相应的 Shell 命令,提供安全的风险评估和交互式确认机制。
✨ 核心特性
- 🤖 智能命令生成 - 基于自然语言描述生成准确的 Shell 命令
- 🔒 安全评估 - 自动评估命令风险等级(安全/警告/危险)
- ⚙️ 灵活配置 - 支持多样模型配置
- 🎨 交互式界面 - 彩色输出和加载动画,提升用户体验
🚀 快速开始
安装方法
uv tool install shai-python
基本使用
命令行模式:
shai 列出当前目录下的所有 Python 文件
交互式模式:
shai
>> 查找大于 10MB 的文件
配置编辑:
shai config
⚙️ 配置说明
首次运行配置
首次运行时会自动创建配置文件,你需要配置 API 密钥:
配置文件位置
- 配置文件:
~/.config/shai/config.yaml
配置示例
# ~/.config/shai/config.yaml
# 调用模型
default_model: "deepseek" # Point to ID in models
# 提供商配置
providers:
deepseek:
api_key: "${DEEPSEEK_API_KEY}" # refer to environment variable
#base_url: "https://api.deepseek.com" # 使用缺省
智普:
api_key: "sk-..." # 建议使用环境变量,比如 ${GLM_API_KEY}
base_url: "https://open.bigmodel.cn/api/paas/v4"
火山方舟:
api_key: "${VOLCANO_API_KEY}"
base_url: "https://ark.cn-beijing.volces.com/api/v3"
openai:
api_key: "${OPENAI_API_KEY}"
google:
api_key: "${GOOGLE_API_KEY}"
anthropic:
api_key: "${ANTHROPIC_API_KEY}"
xai:
api_key: "${XAI_API_KEY}"
openrouter:
api_key: "${OPENROUTER_API_KEY}"
# 模型配置
models:
- id: "deepseek-chat"
provider: "deepseek"
alias: "deepseek"
- id: "glm-4.7-flash"
provider: "智普"
- id: "doubao-seed-1-6-flash-250828"
provider: "火山方舟"
alias: "doubao-flash"
🔧 功能详解
命令生成流程
- 输入描述 - 用户输入自然语言任务描述
- AI 分析 - 模型分析任务并生成合适的命令
- 风险评估 - 自动评估命令的风险等级
- 用户确认 - 根据风险等级提示用户确认执行
- 命令执行 - 用户确认后执行生成的命令
风险等级
- 🟢 安全 (Safe) - 无害命令,可直接执行
- 🟡 警告 (Caution) - 可能有副作用,需要确认
- 🔴 危险 (Danger) - 高风险命令,需要明确确认
🐛 故障排除
常见问题
Q: API 密钥配置错误
A: 运行 shai config 重新配置,或设置环境变量
Q: 命令执行失败 A: 检查网络连接和 API 配额,确认配置正确
Q: 权限错误 A: 配置文件会自动创建在当前用户目录,无需特殊权限
📄 许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
安全提示: 使用 AI 生成的命令时请谨慎,特别是涉及系统修改或数据删除的操作。建议在非生产环境中先测试命令效果。
English Version
📖 Project Introduction
Shai uses large language models (LLMs) to generate shell command based on natural language descriptions. It provides safety risk assessment, interactive confirmation mechanisms.
✨ Core Features
- 🤖 Intelligent Command Generation - Generate accurate shell commands from natural language descriptions
- 🔒 Safety Assessment - Automatic risk level evaluation (Safe/Caution/Danger)
- ⚙️ Flexible Configuration - Various models configuration
- 🎨 Interactive Interface - Colored output and loading animations for better user experience
🚀 Quick Start
Installation
uv tool install shai-python
Basic Usage
Command Line Mode:
shai list all Python files in current directory
Interactive Mode:
shai
>> find files larger than 10MB
Configuration Editing:
shai config
⚙️ Configuration
First Run Setup
Configuration file is automatically created on first run:
Configuration File Location
- Config File:
~/.config/shai/config.yaml
Configuration Example
# ~/.config/shai/config.yaml
# Default settings
default_model: "deepseek" # Point to ID or alias in models
# Providers
providers:
deepseek:
api_key: "${DEEPSEEK_API_KEY}" # refer to environment variable
#base_url: "https://api.deepseek.com" # use default base_url
openai:
api_key: "sk..." # recommended NOT to use plain text API KEY.
google:
api_key: "${GOOGLE_API_KEY}"
anthropic:
api_key: "${ANTHROPIC_API_KEY}"
xai:
api_key: "${XAI_API_KEY}"
openrouter:
api_key: "${OPENROUTER_API_KEY}"
# Models
models:
- id: "deepseek-chat"
provider: "deepseek"
alias: "deepseek"
🔧 Features
Command Generation Process
- Input Description - User provides natural language task description
- AI Analysis - Model analyzes task and generates appropriate command
- Risk Assessment - Automatic risk level evaluation
- User Confirmation - Prompt user based on risk level
- Command Execution - Execute generated command after confirmation
Risk Levels
- 🟢 Safe - Harmless commands, can be executed directly
- 🟡 Caution - Commands with potential side effects, require confirmation
- 🔴 Danger - High-risk commands, require explicit confirmation
🐛 Troubleshooting
Common Issues
Q: API Key Configuration Error
A: Run shai config to reconfigure, or set environment variables
Q: Command Execution Failed A: Check network connection and API quota, verify configuration
Q: Module Not Found Error
A: Ensure installing shai-python package, not shai
Q: Permission Error A: Configuration files are created in user directory, no special permissions needed
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
Security Notice: Use AI-generated commands with caution, especially those involving system modifications or data deletion. Test command effects in non-production environments first.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shai_python-0.1.7.tar.gz.
File metadata
- Download URL: shai_python-0.1.7.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28d86efa36a30fe948cef609926862babbf0b16c928296f2e2f12147d0dce225
|
|
| MD5 |
e78669bbd08c13973c0d3f0652499dfd
|
|
| BLAKE2b-256 |
893b0a8084404e2a58b03135347f19f3c6b8498502034165c8ba02dacb71ee74
|
File details
Details for the file shai_python-0.1.7-py3-none-any.whl.
File metadata
- Download URL: shai_python-0.1.7-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15046199420101c45421d3c2f38eec9acbbb6292f86686950a62d41bd611b54f
|
|
| MD5 |
0bc45a56607917dfc9fa46f39108a644
|
|
| BLAKE2b-256 |
f9e8a6d16439a10f13d39160c387d57926fd837422d5ae77fd3dcaee52250112
|