Communitygithub.com

cli-anything-ollama

通过 Ollama REST API 进行本地 LLM 推理和模型管理,专为 AI 代理和高级用户设计。

cli-anything-ollama 是什么?

cli-anything-ollama 是一个命令行工具,用于通过 Ollama REST API 管理本地大语言模型(LLM)并执行推理。它支持模型管理(列出、下载、删除、复制)、文本生成、对话和嵌入计算,并提供交互式 REPL 模式。该工具适用于 AI 代理(如 Claude Code、Cursor)和高级用户,支持 `--json` 标志输出机器可读的结构化数据,便于自动化集成。它需要 Python 3.10+ 和正在运行的 Ollama 服务,并支持通过 `--host` 连接到远程 Ollama 实例。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/HKUDS/CLI-Anything/tree/main/skills/cli-anything-ollama

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

cli-anything-ollama 是做什么的?

通过 Ollama REST API 进行本地 LLM 推理和模型管理。专为 AI 代理和高级用户设计,无需图形界面即可管理模型、生成文本、进行对话和创建嵌入。

安装

此 CLI 作为 cli-anything-ollama 包的一部分安装:

pip install cli-anything-ollama

先决条件:

  • Python 3.10+
  • 必须安装并运行 Ollama(ollama serve)

使用方法

基本命令

# 显示帮助
cli-anything-ollama --help

# 启动交互式 REPL 模式
cli-anything-ollama

# 列出可用模型
cli-anything-ollama model list

# 以 JSON 格式运行(供代理使用)
cli-anything-ollama --json model list

REPL 模式

调用时不带子命令将进入交互式 REPL 会话:

cli-anything-ollama
# 交互式输入命令,具有 Tab 补全和历史记录功能

命令组

模型(Model)

模型管理命令。

命令描述
list列出本地可用的模型
show显示模型详情(参数、模板、许可证)
pull从 Ollama 库下载模型
rm从本地存储中删除模型
copy复制模型为新名称
ps列出当前加载到内存中的模型

生成(Generate)

文本生成和对话命令。

命令描述
text根据提示生成文本
chat发送对话补全请求

嵌入(Embed)

嵌入生成命令。

命令描述
text为文本生成嵌入

服务器(Server)

服务器状态和信息命令。

命令描述
status检查 Ollama 服务器是否正在运行
version显示 Ollama 服务器版本

会话(Session)

会话状态命令。

命令描述
status显示当前会话状态
history显示当前会话的对话历史

示例

列出和拉取模型

# 列出可用模型
cli-anything-ollama model list

# 拉取模型
cli-anything-ollama model pull llama3.2

# 显示模型详情
cli-anything-ollama model show llama3.2

生成文本

# 流式输出(默认)
cli-anything-ollama generate text --model llama3.2 --prompt "用一句话解释量子计算"

# 非流式输出,JSON 格式(供代理使用)
cli-anything-ollama --json generate text --model llama3.2 --prompt "你好" --no-stream

对话

# 单轮对话
cli-anything-ollama generate chat --model llama3.2 --message "user:什么是Python?"

# 多轮对话
cli-anything-ollama generate chat --model llama3.2 \
  --message "user:什么是Python?" \
  --message "user:它和JavaScript相比如何?"

# 从JSON文件进行对话
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 "你好" --input "世界"

交互式 REPL 会话

启动交互式会话以进行探索性使用。

cli-anything-ollama
# 交互式输入命令
# 使用 'help' 查看可用命令

连接到远程主机

cli-anything-ollama --host http://192.168.1.100:11434 model list

状态管理

CLI 维护轻量级的会话状态:

  • 当前主机 URL:可通过 --host 配置
  • 对话历史:在 REPL 中跟踪多轮对话
  • 上次使用的模型:在 REPL 提示符中显示

输出格式

所有命令都支持双输出模式:

  • 人类可读(默认):表格、颜色、格式化文本
  • 机器可读(--json 标志):结构化 JSON,供代理使用
# 人类可读输出
cli-anything-ollama model list

# JSON 输出供代理使用
cli-anything-ollama --json model list

针对 AI 代理

以编程方式使用此 CLI 时:

  1. 始终使用 --json 标志 以获得可解析的输出
  2. 检查返回码 - 0 表示成功,非零表示错误
  3. 解析 stderr 以在失败时获取错误信息
  4. 使用 --no-stream 进行生成/对话以获取完整响应
  5. 通过 server status 验证 Ollama 是否正在运行,然后再执行其他命令

更多信息

  • 完整文档:请参阅包中的 README.md
  • 测试覆盖:请参阅包中的 TEST.md
  • 方法:请参阅 cli-anything-plugin 中的 HARNESS.md

版本

1.0.1

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

cli-anything-adguardhome

>-

cli-anything-anygen

>-

cli-anything-audacity

>-

cli-anything-blender

>-

cli-anything-browser

Browser automation CLI using DOMShell MCP server. Maps Chrome

cli-anything-calibre

>-

cli-anything-ccswitch

CLI interface for CC Switch — manage AI coding tool configurations from the terminal

cli-anything-chromadb

>-

cli-anything-cloudanalyzer

Command-line interface for CloudAnalyzer — Agent-friendly harness for CloudAnalyzer, a QA platform for mapping, localization, and perception outputs. Supports 27 commands across 8 groups: point cloud evaluation, trajectory evaluation, ground segmentation QA, config-driven quality gates, baseline evolution, processing, visualization, and interactive REPL.

cli-anything-cloudcompare

Command-line interface for CloudCompare — Agent-friendly harness for CloudCompare, the open-source 3D point cloud and mesh processing software. Supports 41 commands across 9 groups: project management, session control, point cloud operations (subsample, filter, segment, analyze), mesh operations, distance computation (C2C, C2M), transformations (ICP, matrix), export (LAS/LAZ/PLY/PCD/OBJ/STL/E57), and interactive REPL.

cli-anything-comfyui

>-

cli-anything-dify-workflow

Wrapper for the Dify workflow DSL CLI. Create, inspect, validate, edit, and export Dify workflow files through a CLI-Anything harness.

cli-anything-drawio

>-

cli-anything-eez-studio

Use EEZ Studio from the command line: inspect and modify native .eez-project files, edit LVGL screens/widgets, manage SCPI commands, and invoke the real EEZ Studio backend for LVGL builds.

cli-anything-eth2-quickstart

>-

cli-anything-exa

>-

cli-anything-firefly-iii

Firefly III CLI - Personal finance management via CLI-Anything

cli-anything-freecad

Complete CLI harness for FreeCAD parametric 3D CAD modeler (258 commands). Covers ALL workbenches: Part (29 primitives + boolean + mirror + loft + sweep), Sketcher (26 cmds: geometry + constraints + editing), PartDesign (38 cmds: pad/pocket/groove/fillet/chamfer/patterns/hole/datum), Assembly (11 cmds), Mesh (16 cmds), TechDraw (15 cmds: views + dimensions + PDF/SVG), Draft (33 cmds: 2D shapes + arrays + transforms), FEM (12 cmds), CAM/CNC (10 cmds), Surface (6 cmds), Spreadsheet (7 cmds), Import (13 formats), Export (17 formats), Measure (12 cmds), Materials (21 presets). Headless FreeCAD export to STEP/IGES/STL/OBJ/DXF/PDF/glTF/3MF.

cli-anything-gimp

>-

cli-anything-godot

>-

相关技能