colab-hf-chat 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +19 -48
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,67 +1,38 @@
1
- # Colab Hugging Face Chat CLI
1
+ # colab-hf-chat
2
2
 
3
- 安装 Node.js 18 或更新版本。从下载的 npm 压缩包安装:
3
+ 在 Google Colab GPU 上运行 Hugging Face 聊天模型,通过 SSH 转发在本机使用 vLLM 的 OpenAI 兼容 API。CLI 可自动安装 Google Colab CLI、引导 Google 授权,并显示账户剩余 Compute Units(CU)。
4
4
 
5
- ```bash
6
- npm install -g ./colab-hf-chat-0.1.0.tgz
7
- colab-hf-chat
8
- ```
9
-
10
- macOS 和 Linux 直接运行。Windows 原生 Node.js 可以安装同一个 npm 包,运行时需要已经初始化的 WSL 2 Linux 发行版。Ubuntu 或 WSL 中缺少系统工具时,运行 `sudo apt install openssh-client curl`。本地 API 使用回环地址。Windows 访问 WSL 服务依赖 localhost 转发。
11
-
12
- 工具会安装 Colab CLI、引导 Google OAuth、显示剩余 CU,并询问 Hugging Face 模型 ID、GPU 和本地端口。等待 **API 已就绪** 后,在 OpenAI 兼容客户端填入显示的 Base URL 和模型 ID。如果客户端要求 API Key,填 `local`。退出前按 **Ctrl+C** 释放本次 GPU 会话。仅查询额度可运行 `colab-hf-chat usage`。
13
-
14
- ## Hugging Face 模型试跑与公网 API
5
+ ## 安装和启动
15
6
 
16
- 默认模型为量化的 DistilBERT 英文情感分类模型,使用 CPU。Colab 用于试跑和查询账户额度,Hugging Face Docker Space 托管公网推理 API。
17
-
18
- ## Colab 查询和试跑
7
+ 需要 Node.js 18+。macOS 和 Linux 使用本机 Bash、curl 和 OpenSSH。Windows 使用已初始化的 WSL 2 Linux 发行版,并需要 WSL 的 localhost 转发。
19
8
 
20
9
  ```bash
21
- uv tool install google-colab-cli
22
- ./deploy.sh usage
23
- ./deploy.sh colab
10
+ npm install -g colab-hf-chat --registry=https://registry.npmjs.org/
11
+ colab-hf-chat
24
12
  ```
25
13
 
26
- 首次查询时按终端提示使用 Google AI Pro 所在账号完成 OAuth,并把授权码填回终端。额度查询显示账户剩余 CU、每小时消耗和活跃分配数。试跑临时创建 CPU 会话,加载模型、打印样例预测并在退出时释放会话。
27
-
28
- ## 发布公网 API
14
+ 1. 首次使用时,按提示用自己的 Google 账号授权 Colab CLI。
15
+ 2. 输入公开的 Hugging Face 聊天模型 ID。默认使用 `Qwen/Qwen2.5-0.5B-Instruct`、L4 GPU 和本地端口 `8000`。
16
+ 3. 看到 **API 已就绪** 后,将 OpenAI 兼容客户端的 Base URL 设为 `http://127.0.0.1:8000/v1`,模型填你输入的模型 ID。若客户端要求 API Key,可填 `local`。
17
+ 4. 使用结束后按 **Ctrl+C** 释放 GPU 会话。
29
18
 
30
- ```bash
31
- hf auth login
32
- ./deploy.sh publish YOUR_HF_USERNAME/hf-text-api
33
- ```
19
+ 首次启动会安装 vLLM 并下载模型权重。模型需受 vLLM 支持,并能放入所选 GPU 的显存。GPU 可用性由 Colab 决定。API 监听本机回环地址。
34
20
 
35
- 使用有目标仓库写权限的 Hugging Face Token。脚本创建公开的 CPU Basic Docker Space。重复运行会更新同名 Space 中的应用文件,请选专用于此服务的 Space。脚本等待构建完成,从 Space 获取公网域名,并无凭证调用 `/health` 和 `/predict` 验证。要重新验证已发布的 Space,可运行 `./deploy.sh verify YOUR_HF_USERNAME/hf-text-api`。访问 `/docs` 可直接试用,`/health` 确认模型已加载。
21
+ ## 调用示例
36
22
 
37
23
  ```bash
38
- curl -fsS "https://YOUR-SPACE.hf.space/predict" \
24
+ curl -fsS http://127.0.0.1:8000/v1/models
25
+ curl -fsS http://127.0.0.1:8000/v1/chat/completions \
39
26
  -H 'Content-Type: application/json' \
40
- -d '{"text":"I really loved this movie."}'
27
+ -d '{"model":"Qwen/Qwen2.5-0.5B-Instruct","messages":[{"role":"user","content":"你好"}],"max_tokens":64}'
41
28
  ```
42
29
 
43
- 此 API 公开访问。Colab 查询命令在本机执行,账号余额不会进入公开 API。CPU Basic Space 空闲后可能休眠。
44
-
45
- ## 更换模型
46
-
47
- 支持带 `tokenizer.json`、具有 `id2label` 的 `config.json` 和匹配的 ONNX 文件的单文本分类模型。ONNX 输入需兼容 `input_ids`、`attention_mask` 或 `token_type_ids`,首个输出应为分类 logits。设置 `MODEL_ID`、可选的 `MODEL_REVISION` 和 `MODEL_FILE`。Colab 从本地命令环境接收上述配置,公网 API 从 Space Settings 的 Variables 接收配置。生成、图像或语音模型需要更换推理代码和请求格式。
48
-
49
- ## Colab GPU 与 OpenAI 兼容聊天 API
30
+ ## 只查 Colab 额度
50
31
 
51
32
  ```bash
52
- ./deploy.sh usage
53
- ./gpu-chat.sh L4 Qwen/Qwen2.5-0.5B-Instruct 8000
54
- ```
55
-
56
- 脚本申请 Colab GPU,安装 vLLM,并通过 Colab CLI 的 SSH 转发把 API 接到本机。默认模型为可公开下载的 Qwen 聊天模型。看到 **API 已就绪** 后,在另一个终端验证:
57
-
58
- ```bash
59
- curl -fsS http://127.0.0.1:8000/v1/models
60
- curl -fsS http://127.0.0.1:8000/v1/chat/completions \
61
- -H 'Content-Type: application/json' \
62
- -d '{"model":"Qwen/Qwen2.5-0.5B-Instruct","messages":[{"role":"user","content":"用一句话介绍你自己"}],"max_tokens":64}'
33
+ colab-hf-chat usage
63
34
  ```
64
35
 
65
- OpenAI SDK 的 `base_url` 填 `http://127.0.0.1:8000/v1`。脚本监听本机回环地址,供当前电脑交互式测试。退出脚本会释放 GPU 会话。L4 和 SSH 能否使用取决于账号权益、CU 余额和当时的运行时供应。
36
+ 显示剩余 CU、当前每小时消耗和活跃会话数。此命令不申请 GPU。
66
37
 
67
- Colab 托管运行时限制与交互式计算无关的 Web 服务。需要公网 OpenAI 兼容接口时,在可用于对外服务的 GPU 主机上运行同款 vLLM,并用 HTTPS 和 API key 提供访问。上面的 CPU Space 示例是文本分类接口。
38
+ 本项目是独立 CLI,使用 [Google Colab CLI](https://github.com/googlecolab/google-colab-cli) 和 [vLLM](https://docs.vllm.ai/)。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "colab-hf-chat",
3
- "version": "0.1.0",
4
- "description": "Launch a Hugging Face chat model on Google Colab with a local OpenAI-compatible API",
3
+ "version": "0.1.1",
4
+ "description": "Run Hugging Face chat models on Colab GPUs with vLLM, a localhost OpenAI-compatible API, and Colab compute-unit reporting.",
5
5
  "bin": {
6
6
  "colab-hf-chat": "cli.cjs"
7
7
  },