JSPM

glm4v-cli

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q32300F
  • License MIT

GLM-4V 视觉模型 CLI 工具 - 支持本地图片分析

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (glm4v-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    GLM-4V CLI

    GLM-4V 视觉模型命令行工具 - 支持本地图片分析

    功能特性

    • 本地图片分析(支持 jpg/png/gif/webp/bmp)
    • 配置文件管理 API 地址和 Key
    • 自定义提示词
    • JSON 格式输出
    • 自动 base64 编码
    • 跨平台支持(Windows/macOS/Linux)

    安装

    全局安装(推荐)

    npm install -g glm4v-cli

    本地安装

    # 克隆或下载项目
    cd glm4v-cli
    
    # 安装依赖
    npm install
    
    # 链接到全局(可选)
    npm link

    系统要求

    • Node.js: >= 18.0.0
    • 操作系统: Windows 10/11, macOS, Linux

    快速开始

    1. 初始化配置

    glm4v init

    2. 设置 API Key

    glm4v config --api-key your-api-key-here

    3. 分析图片

    # macOS/Linux
    glm4v analyze /path/to/image.jpg
    
    # Windows
    glm4v analyze C:\Users\YourName\Pictures\image.jpg
    # 或
    glm4v analyze "C:\Users\YourName\Pictures\image.jpg"

    命令详解

    init - 初始化配置

    创建配置文件:

    • Windows: %APPDATA%\glm4v\config.json
    • macOS/Linux: ~/.config/glm4v/config.json
    glm4v init

    config - 管理配置

    # 显示当前配置
    glm4v config --show
    
    # 设置 API Key
    glm4v config --api-key sk-xxxxxxxx
    
    # 设置自定义 API 地址
    glm4v config --api-url https://api.example.com/v1
    
    # 同时设置多个配置
    glm4v config --api-url https://api.example.com/v1 --api-key sk-xxxxxxxx

    analyze - 分析图片

    # 基本用法
    glm4v analyze ./photo.jpg
    
    # 自定义提示词
    glm4v analyze ./photo.jpg -p "这张图片里有什么文字?"
    
    # 使用不同模型
    glm4v analyze ./photo.jpg -m glm-4v-flash
    
    # 限制输出长度
    glm4v analyze ./photo.jpg -t 500
    
    # JSON 格式输出
    glm4v analyze ./photo.jpg --json
    
    # 组合选项
    glm4v analyze ./photo.png -p "描述图片风格" -t 800 --json

    跨平台使用示例

    Windows

    # PowerShell
    glm4v analyze C:\Users\pan\Downloads\image.png
    glm4v analyze "C:\Users\pan\Downloads\image.png" -p "描述这个图片"
    
    # CMD
    glm4v analyze C:\Users\pan\Downloads\image.png

    macOS

    glm4v analyze ~/Downloads/image.png
    glm4v analyze /Users/pan/Downloads/image.png -p "这张图片里有什么?"

    Linux

    glm4v analyze ~/Pictures/image.jpg
    glm4v analyze /home/user/pictures/image.jpg --json

    配置说明

    配置文件位置:

    系统 路径
    Windows %APPDATA%\glm4v\config.json
    macOS ~/.config/glm4v/config.json
    Linux ~/.config/glm4v/config.json

    配置内容:

    {
      "apiUrl": "https://ai.bytenote.net/v1",
      "apiKey": "your-api-key-here"
    }

    使用示例

    # 示例 1: 分析图标
    $ glm4v analyze ./icon.png
    📷 正在分析图片...
       文件: /Users/pan/Downloads/icon.png
       大小: 12.70 KB
       类型: image/png
       模型: glm-4v
    
    ✅ 分析完成
    
    🤖 GLM-4V 回答:
    这是一张应用图标,显示一个剪贴板图案...
    
    📊 Token 使用:
       - Prompt: 1674
       - Completion: 92
       - Total: 1766
    
    # 示例 2: JSON 输出
    $ glm4v analyze ./chart.png -p "分析这个图表的数据趋势" --json
    {
      "content": "该图表显示了...",
      "usage": {
        "prompt_tokens": 2156,
        "completion_tokens": 156,
        "total_tokens": 2312
      }
    }

    支持的图片格式

    • .jpg / .jpeg
    • .png
    • .gif
    • .webp
    • .bmp

    限制

    • 单张图片最大 10MB
    • 支持的图片格式见上表
    • Node.js 版本 >= 18.0.0

    常见问题

    Windows 上路径问题

    如果路径包含空格,请使用引号包裹:

    glm4v analyze "C:\Users\My Name\Pictures\my image.png"

    配置文件找不到

    运行 glm4v init 创建配置文件,然后使用 glm4v config --show 查看配置路径。

    权限问题(Linux/macOS)

    如果全局安装后找不到命令,可能需要添加 npm 全局目录到 PATH:

    # 查看 npm 全局目录
    npm config get prefix
    
    # 添加到 PATH(根据 shell 选择)
    # Bash
    echo 'export PATH="$PATH:$(npm config get prefix)/bin"' >> ~/.bashrc
    
    # Zsh
    echo 'export PATH="$PATH:$(npm config get prefix)/bin"' >> ~/.zshrc

    License

    MIT