关于 cli-anything-ollama
cli-anything-ollama 是通过 Ollama REST API 管理模型和推理的命令行工具,面向 AI Agent 和高级用户,提供模型管理、文本与聊天生成、嵌入向量及机器可读输出。
主要功能
- 01列出、下载、复制和删除模型
- 02生成文本与聊天回复
- 03创建文本嵌入向量
- 04查看服务端和会话状态
- 05带历史记录的交互式 REPL
- 06支持 Agent 工作流的 JSON 输出
适用场景
- 01管理本地可用的 Ollama 模型
- 02根据提示词生成文本
- 03维护多轮聊天会话
- 04为输入文本生成嵌入向量
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ hkuds/ cli-anything --skill cli-anything-ollama安装后在 Claude Code 中输入/cli-anything-ollama确认已加载。
详细介绍
cli-anything-ollama
通过 Ollama REST API 进行本地大模型推理和模型管理。专为需要在无 GUI 环境下管理模型、生成文本、聊天和创建嵌入的 AI Agent 和高级用户而设计。
安装
此命令行随 cli-anything-ollama 包一起安装:
pip install cli-anything-ollama
前置要求:
- Python 3.10+
- 必须已安装并运行 Ollama(
ollama serve)
用法
基本命令
# Show help
cli-anything-ollama --help
# Start interactive REPL mode
cli-anything-ollama
# List available models
cli-anything-ollama model list
# Run with JSON output (for agent consumption)
cli-anything-ollama --json model list
REPL 模式
在不带子命令调用时,命令行会进入交互式 REPL 会话:
cli-anything-ollama
# Enter commands interactively with tab-completion and history
命令组
Model
模型管理命令。
| 命令 | 描述 |
|---|---|
list | 列出本地可用的模型 |
show | 显示模型详情(参数、模板、许可证) |
pull | 从 Ollama 库下载模型 |
rm | 从本地存储中删除模型 |
copy | 将模型复制为新名称 |
ps | 列出当前已加载到内存中的模型 |
Generate
文本生成和聊天命令。
| 命令 | 描述 |
|---|---|
text | 根据提示词生成文本 |
chat | 发送聊天补全请求 |
Embed
嵌入生成命令。
| 命令 | 描述 |
|---|---|
text | 为文本生成嵌入 |
Server
服务器状态和信息命令。
| 命令 | 描述 |
|---|---|
status | 检查 Ollama 服务器是否正在运行 |
version | 显示 Ollama 服务器版本 |
Session
会话状态命令。
| 命令 | 描述 |
|---|---|
status | 显示当前会话状态 |
history | 显示当前会话的聊天历史 |
示例
列出和拉取模型
# List available models
cli-anything-ollama model list
# Pull a model
cli-anything-ollama model pull llama3.2
# Show model details
cli-anything-ollama model show llama3.2
生成文本
# Stream text (default)
cli-anything-ollama generate text --model llama3.2 --prompt "Explain quantum computing in one sentence"
# Non-streaming with JSON output (for agents)
cli-anything-ollama --json generate text --model llama3.2 --prompt "Hello" --no-stream
聊天
# Single-turn chat
cli-anything-ollama generate chat --model llama3.2 --message "user:What is Python?"
# Multi-turn chat
cli-anything-ollama generate chat --model llama3.2 \
--message "user:What is Python?" \
--message "user:How does it compare to JavaScript?"
# Chat from JSON file
cli-anything-ollama generate chat --model llama3.2 --file messages.json
嵌入
cli-anything-ollama embed text --model nomic-embed-text --input "Hello world"
cli-anything-ollama embed text --model nomic-embed-text --input "Hello" --input "World"
交互式 REPL 会话
启动交互式会话以进行探索性使用。
cli-anything-ollama
# Enter commands interactively
# Use 'help' to see available commands
连接到远程主机
cli-anything-ollama --host http://192.168.1.100:11434 model list
状态管理
命令行维护轻量级会话状态:
- 当前主机 URL:可通过
--host配置 - 聊天历史:在 REPL 中跟踪多轮对话
- 上次使用的模型:显示在 REPL 提示符中
输出格式
所有命令都支持两种输出模式:
- 人类可读(默认):表格、颜色、格式化文本
- 机器可读(
--json标志):供 Agent 使用的结构化 JSON
# Human output
cli-anything-ollama model list
# JSON output for agents
cli-anything-ollama --json model list
面向 AI Agent
以编程方式使用此命令行时:
- 始终使用
--json标志以获得可解析的输出 - 检查返回码 - 0 表示成功,非零表示错误
- 解析 stderr 以获取失败时的错误消息
- 使用
--no-stream运行 generate/chat 以获取完整响应 - 在执行其他命令前先通过
server status验证 Ollama 正在运行
更多信息
- 完整文档:请参阅包中的 README.md
- 测试覆盖率:请参阅包中的 TEST.md
- 方法论:请参阅 cli-anything-plugin 中的 HARNESS.md
版本
1.0.1
评论
支持 Markdown