Ask LLM Instantly in terminal
  • PowerShell 54.8%
  • Shell 45.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-23 21:00:37 +08:00
ai.ps1 何意味 2026-07-23 21:00:37 +08:00
ai.sh 何意味 2026-07-23 21:00:37 +08:00
README.md 何意味 2026-07-23 21:00:37 +08:00

ai

一个命令行 AI 助手,在终端里快速调用 LLM。

文件

文件 适用平台 使用方式
ai.sh Linux / macOS / WSL source ai.sh 加载函数,然后 ai <提问>
ai.ps1 Windows (PowerShell) ./ai.ps1 <提问> 或设为模块导入

前置依赖

  • curl(仅 ai.sh 需要)
  • jq(仅 ai.sh 需要)
  • API 密钥(需自行填入脚本)

可选增强

  • glow — 终端内渲染 Markdown表格、代码块等
  • mermaid-ascii — 将 ```mermaid 图表块渲染为 ASCII 字符图

配置

编辑脚本,填入以下内容:

api_key="sk-你的密钥"
model="gpt-4o"              # 或其它模型名
api_base="https://api.openai.com/v1/chat/completions"

PowerShell 版本在 ai.ps1 顶部的 # --- 配置区 --- 中填写。

用法

直接提问

# Bash
ai 用 Python 写一个快速排序

# PowerShell
.\ai.ps1 用 Python 写一个快速排序

管道输入

# Bash
cat code.py | ai 何意味

# PowerShell
Get-Content code.py | .\ai.ps1 何意味

结合参数与管道

# Bash
git diff | ai 生成 commit message

# PowerShell
git diff | .\ai.ps1 生成 commit message

特性

  • Mermaid 图表渲染:当回答包含 ```mermaid 代码块时,会自动提取并渲染为 ASCII 字符图,并将原文中的图表块替换为 > **图 N 见文末** 引用标记。
  • Markdown 渲染:配合 glow 可在终端中显示格式化后的 Markdown 内容。
  • 单次对话:每次调用为独立会话,无历史记忆。