# PR #41084 完整报告

- 仓库：`vllm-project/vllm`
- 标题：[Examples][last/6] Resettle examples.
- 合并时间：2026-05-08 10:42
- 原文链接：http://prhub.com.cn/vllm-project/vllm/pull/41084

---

# 执行摘要

- 一句话：按使用场景重新组织 examples 目录
- 推荐动作：此 PR 属于纯组织性变更，值得阅读以理解示例分类思路。关注焦点：新目录结构是否合理、路径引用更新是否彻底。建议合入后清理外部文档链接。

# 功能与动机

参考 issue #29362 的 RFC 提议，通过按使用场景组织示例来提高可发现性，使用户无需在多个文件夹间搜索特定用例。

# 实现拆解

### 步骤
1. **创建新目录结构**：按照 basic、deployment、applications、features、speech_to_text 等场景建立一级子目录。
2. **移动与重命名文件**：将原有 offline_inference 下的脚本移入 deployment 和 basic；将 online_serving 下的聊天机器人相关脚本移入 applications/chatbot，RAG 示例移入 applications/rag；将 others 下的 tensorizer 示例移入 features。
3. **删除无主文件**：删除了 examples/online_serving/utils.py（含 get_first_model 函数），因为其逻辑已被内联或不再需要。
4. **更新文档引用**：在 docs/ 目录下多处修复了指向示例脚本的路径，并修正了 retrieval_augmented_generation.md 中重复 `examples/` 的 typo。
5. **调整 CI 脚本**：在 .buildkite/scripts/hardware_ci/run-tpu-v1-test.sh 中移除了对已删除 offline_inference 测试的引用。
6. **源码内路径修正**：在 vllm/model_executor/model_loader/tensorizer.py 等文件中更新了指向示例脚本的注释路径。

关键文件：
- `examples/online_serving/utils.py`（模块 服务工具；类别 source；类型 deletion；符号 get_first_model）: 核心删除文件，移除了 get_first_model 函数
- `examples/features/tensorize_vllm_model.py`（模块 序列化特性；类别 source；类型 rename-or-move）: 从 examples/others 迁入，更新了文档内的命令行路径
- `examples/applications/chatbot/gradio_openai_chatbot_webserver.py`（模块 聊天应用；类别 source；类型 rename-or-move）: 从 online_serving 迁入 applicatons/chatbot，体现了新分类
- `examples/deployment/async_llm_streaming.py`（模块 部署脚本；类别 source；类型 rename-or-move）: 从 offline_inference 迁入 deployment，展示部署场景分类
- `vllm/model_executor/model_loader/tensorizer.py`（模块 模型加载；类别 source；类型 data-contract）: 修改注释中的示例路径以匹配新目录
- `docs/deployment/frameworks/retrieval_augmented_generation.md`（模块 文档；类别 docs；类型 documentation）: 修复了链接路径，体现文档配套更新

关键符号：get_first_model

## 关键源码片段

### `examples/online_serving/utils.py`

核心删除文件，移除了 get_first_model 函数

```python
# SPDX-License-Identifier: Apache-2.0
# 该文件被完全删除，因为 get_first_model 函数不再被使用
from openai import APIConnectionError, OpenAI
from openai.pagination import SyncPage
from openai.types.model import Model


def get_first_model(client: OpenAI) -> str:
    """
    从 vLLM 服务器获取第一个模型 ID。
    删除原因：目录重组后该辅助函数不再被任何示例引用，
    各示例改为直接使用 client.models.list() 内联。
    """
    try:
        models: SyncPage[Model] = client.models.list()
    except APIConnectionError as e:
        raise RuntimeError(
            "Failed to get the list of models from the vLLM server at "
            f"{client.base_url} with API key {client.api_key}. Check\n"
            "1. the server is running\n"
            "2. the server URL is correct\n"
            "3. the API key is correct"
        ) from e
    if len(models.data) == 0:
        raise RuntimeError(f"No models found on the vLLM server at {client.base_url}")
    return models.data[0].id

```

# 评论区精华

- gemini-code-assist[bot] 指出 docs/deployment/frameworks/retrieval_augmented_generation.md 中链接出现重复 `examples/examples/` 拼写错误，建议修正。
- noooop 发现 .buildkite/scripts/hardware_ci/run-tpu-v1-test.sh 中移除的测试文件路径不存在，注释说明 " 文件未找到 "。
- DarkLight1337 批准并留言 "LGTM if tests pass"。

- 文档链接路径重复 (documentation): noooop 接受并修复（后续提交已处理）。
- TPU 测试脚本中移除不存在的文件 (question): 该行被正确移除（未再出现错误）。

# 风险与影响

- 风险：主要风险在于用户或自动化脚本仍引用旧路径，导致 404。虽然 PR 已更新所有已知引用，但仍可能遗漏外部文档、博客或私有配置。此外，删除 utils.py 的 get_first_model 可能影响内部依赖（但该函数仅在 examples 内部使用，未在 vllm 核心代码中引用）。
- 影响：用户侧：所有示例脚本的路径发生变化，用户需更新运行命令。但长期改善可发现性。系统侧：CI 脚本移除了一行导致失败的测试。团队侧：目录结构更清晰，易于维护。影响程度：中（60+ 文件变动，但无功能逻辑变化）。
- 风险标记：文档链接遗漏 , 外部引用断裂 , CI 脚本路径硬编码

# 关联脉络

- PR #41082 [Docs] Reorganize examples docs.: 前序 PR，同属 examples 重组系列，更新了 docs 路径。