项目概述
AIChat 是一个功能全面的 LLM(大语言模型)命令行工具,集成了 Shell 助手、交互式对话、RAG(检索增强生成)、AI 工具和智能代理等功能。
项目地址: https://github.com/sigoden/aichat
开发语言: Rust
许可协议: MIT License / Apache License 2.0
目标用户
开发者与工程师
数据科学家与研究人员
高级命令行用户
需要在终端环境中快速访问 LLM 的程序员,希望将 AI 能力集成到开发工作流的技术人员,以及需要自动化脚本和命令行任务的系统管理员。
产品设计理念
统一接口,多模型支持
通过统一的 CLI 接口访问 20+ 主流 LLM 提供商,支持 OpenAI、Claude、Gemini、Ollama、Groq 等。
命令行优先
专为终端环境设计,提供流畅的 CLI 体验,支持管道操作、标准输入输出,完美融入 Unix 哲学。
灵活可扩展
支持自定义角色、宏命令、函数调用,可集成外部工具和文档。
即开即用,高度可配置
零配置快速启动,提供丰富的配置选项满足高级需求。
主要使用场景
Shell 命令助手
交互式对话 (REPL)
文档处理与 RAG
AI 代理与工具
模型比较
用自然语言描述任务,AIChat 将其转换为精确的 Shell 命令:# 描述需求,获取命令建议
$ aichat find all pdf files larger than 10MB
# AIChat 会根据你的 OS 和 Shell 环境生成合适的命令
核心功能
多模型支持
支持 20+ LLM 提供商,包括 OpenAI、Claude、Gemini、Ollama、Groq、Azure-OpenAI、VertexAI、Bedrock、Github Models、Mistral、Deepseek、AI21、XAI Grok、Cohere、Perplexity、Cloudflare、OpenRouter、Ernie、Qianwen、Moonshot、ZhipuAI、MiniMax、Deepinfra、VoyageAI 以及任何兼容 OpenAI API 的提供商。
统一接口提供一致的命令行体验,无需学习不同 API。
命令行模式 (CMD)
强大的一次性命令执行:
# 基本对话
$ aichat "What is the capital of France?"
# 结合标准输入
$ cat error.log | aichat "analyze these errors"
# 多文件输入
$ aichat -f image.png -f data.txt "describe and analyze"
# 执行外部命令
$ aichat -f '`git diff`' "review these changes"
交互式 REPL
提供 Tab 自动补全、多行输入支持、历史搜索功能、自定义按键绑定以及可配置的 REPL 界面。
角色系统 (Roles)
自定义 AI 行为和专业领域:
# 在 ~/.config/aichat/roles.yaml 中定义
- name: code_reviewer
prompt: You are an expert code reviewer. Focus on security, performance, and best practices.
model: claude:claude-3-5-sonnet
temperature: 0.3
使用角色:
$ aichat --role code_reviewer -f main.rs
# 或在 REPL 中
aichat> .role code_reviewer
会话管理 (Sessions)
保持上下文连续性:
# 创建会话
$ aichat --session project_discussion
# 继续会话
$ aichat --session project_discussion "continue our discussion"
# REPL 中管理会话
aichat> .session new debug_session
aichat> .session list
aichat> .session delete old_session
宏命令 (Macros)
自动化重复性任务:
# 在配置文件中定义宏
macros:
code_review: |
.role code_reviewer
.file %1
Review this code for issues
doc_summary: |
.file %1
Create a concise summary
使用宏:
aichat> .macro code_review main.rs
RAG (检索增强生成)
集成外部文档提升回答质量:
# 索引文档
$ aichat --rag-index ./knowledge_base
# 使用 RAG 查询
$ aichat --rag "What is our company policy on remote work?"
函数调用与工具集成
连接外部工具扩展 LLM 能力。配置函数和工具可参考 https://github.com/sigoden/llm-functions。
# 使用工具
$ aichat --agent --tool web_search "find latest news about AI"
HTTP 服务器模式
部署为 API 服务:
$ aichat --serve
# 可用端点:
# - Chat Completions: http://127.0.0.1:8000/v1/chat/completions
# - Embeddings: http://127.0.0.1:8000/v1/embeddings
# - Rerank: http://127.0.0.1:8000/v1/rerank
# - Playground: http://127.0.0.1:8000/playground
# - Arena: http://127.0.0.1:8000/arena
API 调用示例:
curl -X POST -H "Content-Type: application/json" -d '{
"model":"claude:claude-3-5-sonnet-20240620",
"messages":[{"role":"user","content":"hello"}],
"stream":true
}' http://127.0.0.1:8000/v1/chat/completions
自定义主题
个性化终端显示,支持暗色和亮色主题,高亮代码块。
安装方法
Cargo (Rust)
Homebrew
Pacman (Arch)
Scoop (Windows)
Termux (Android)
预编译二进制
验证安装:
快速使用入门
配置 API 密钥
首次运行时,AIChat 会引导你配置 API 密钥:或手动配置环境变量:# OpenAI
export OPENAI_API_KEY="sk-..."
# Claude (Anthropic)
export ANTHROPIC_API_KEY="sk-ant-..."
# Gemini (Google)
export GEMINI_API_KEY="..."
# Ollama (本地运行,无需 API 密钥)
# 确保 Ollama 服务运行中
配置文件位置: ~/.config/aichat/config.yaml 基本使用
简单对话:$ aichat "Explain quantum computing in simple terms"
使用管道:$ echo "Hello, world!" | aichat "translate to French"
文件输入:$ aichat -f document.txt "summarize this document"
启动 REPL
$ aichat
# 进入交互模式
aichat> What is machine learning?
aichat> .file example.py -- explain this code
aichat> .model gpt-4
aichat> .exit
选择模型
查看可用模型:指定模型:$ aichat --model claude:claude-3-5-sonnet "your question"
# 或在 REPL 中
aichat> .model gpt-4o
使用会话
# 创建持久会话
$ aichat --session my_project
aichat> Let's discuss the architecture
aichat> .exit
# 恢复会话
$ aichat --session my_project
aichat> Continue from where we left off
实用示例
代码审查
# 审查 Git 更改
$ git diff | aichat --role code_reviewer "review these changes"
# 审查特定文件
$ aichat --role code_reviewer -f src/main.rs
Shell 助手
# 获取命令建议
$ aichat "list all running docker containers"
# 输出: docker ps
$ aichat "find files modified in last 7 days"
# 输出: find . -mtime -7
$ aichat "compress all logs into archive"
# 输出: tar -czf logs.tar.gz *.log
数据分析
# 分析 CSV 文件
$ aichat -f sales_data.csv "calculate total revenue and top 5 products"
# 分析日志
$ tail -n 1000 app.log | aichat "summarize error patterns"
文档处理
# 总结多个文档
$ aichat -f doc1.pdf -f doc2.pdf "create a combined summary"
# 处理网页内容
$ aichat -f https://example.com/article "extract main points"
# 分析代码库
$ aichat -f ./src/ "describe the project architecture"
多模态输入
# 图片描述
$ aichat -f image.jpg "describe what you see"
# 图片 + 文本
$ aichat -f diagram.png -f requirements.txt "compare the diagram with requirements"
配置指南
配置文件位置
~/.config/aichat/config.yaml
基本配置示例
# 默认模型
model: claude:claude-3-5-sonnet-20240620
# 温度参数 (0-2)
temperature: 0.7
# 流式输出
stream: true
# 保存会话
save_session: true
# 自动复制代码块
auto_copy: true
# 主题
light_theme: true # 或 false 使用暗色主题
# 按键绑定
keybindings:
accept_line: Enter
complete: Tab
配置多个提供商
clients:
- type: openai
api_key: sk-...
- type: claude
api_key: sk-ant-...
- type: ollama
api_base: http://localhost:11434
常用命令参考
命令行选项
# 基本使用
aichat [OPTIONS] [TEXT]...
# 主要选项
-m, --model <MODEL> 指定模型
-r, --role <ROLE> 使用角色
-s, --session [SESSION] 使用/创建会话
-f, --file <FILE> 附加文件
-H, --no-highlight 禁用语法高亮
-S, --no-stream 禁用流式输出
--serve 启动 HTTP 服务器
--list-models 列出所有可用模型
--list-roles 列出所有角色
REPL 命令
| 命令 | 说明 |
|---|
.help | 显示帮助 |
.info | 显示系统信息 |
.model <MODEL> | 切换模型 |
.role <ROLE> | 切换角色 |
.session [NAME] | 管理会话 |
.file <PATH> | 附加文件 |
.clear | 清除上下文 |
.copy | 复制最后的回复 |
.exit | 退出 REPL |
高级功能
环境变量
# API 密钥
OPENAI_API_KEY
ANTHROPIC_API_KEY
GEMINI_API_KEY
GROQ_API_KEY
# 配置
AICHAT_CONFIG_DIR 配置目录路径
AICHAT_ROLES_FILE 角色文件路径
AICHAT_LIGHT_THEME 使用亮色主题 (true/false)
# 代理设置
HTTPS_PROXY HTTP 代理
自定义 REPL 提示符
在配置文件中:
repl_prompt: "🤖 {model} >"
left_prompt: "{user}@{session} "
性能优化
# 限制上下文长度
max_context_length: 4096
# 并发请求数
max_concurrent_requests: 5
# 缓存设置
enable_cache: true
cache_dir: ~/.cache/aichat
相关资源
官方文档
Chat-REPL 指南 - 交互式对话环境使用指南
命令行指南 - 命令行模式完整参考
角色指南 - 自定义角色配置
宏命令指南 - 宏命令创建与使用
RAG 指南 - 检索增强生成配置
环境变量 - 环境变量参考
配置指南 - 配置文件详解
自定义主题 - 主题定制
自定义 REPL 提示符 - 提示符配置
常见问题 (FAQ) - 常见问题解答
相关项目
llm-functions - 函数调用工具库
社区与支持
GitHub Issues - 问题反馈
GitHub Discussions - 讨论交流
故障排查
API 密钥未设置
模型不可用
网络连接问题
Ollama 连接失败
错误信息:Error: Missing API key解决方案:export OPENAI_API_KEY="your-api-key"
# 或在配置文件中设置
贡献与许可
贡献指南
欢迎贡献!请访问 GitHub Repository 提交 Issue 或 Pull Request。
许可证
AIChat 采用双许可协议:MIT License 和 Apache License 2.0。您可以选择其中任一协议使用本软件。
AIChat 是一个强大、灵活的命令行 LLM 工具,具有以下优势:
统一接口 - 通过单一 CLI 访问 20+ LLM 提供商
功能全面 - Shell 助手、REPL、RAG、工具集成、代理模式
高度可定制 - 角色、宏、主题、按键绑定
开发者友好 - 完美融入 Unix 工作流,支持管道和脚本
开源免费 - MIT/Apache 双许可,活跃的社区支持
无论你是需要快速原型开发、自动化任务,还是深度研究 LLM 能力,AIChat 都是理想的命令行工具选择。