Skip to content

refactor: move the Hugging Face files to the upstream layout - #304

Merged
eric8810 merged 14 commits into
masterfrom
refactor/move-the-hugging-face-files-to-the-upstream-layout
Oct 27, 2026
Merged

eric8810 merged 14 commits into
masterfrom
refactor/move-the-hugging-face-files-to-the-upstream-layout

Conversation

@cunninghamcard-bit

@cunninghamcard-bit cunninghamcard-bit commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

把 Hugging Face 的源文件按 @ai-sdk/huggingface@2.0.62 一个文件对一个文件拆开(RFC-0046 §4.2),老的 tests/huggingface_responses_test.rs 并进厂商测试目录 src/huggingface/tests/(RFC-0046 §5 的新布局)。只搬不改:函数体不变,测试数量、模块路径和函数名前后一致。叠在测试 PR #303 上。

已经测试分支 36b3e4ec 合上 master b69137eb,冲突按 master 的改动搬到新位置解决(老测试程序里一处错误模式改成结构体变体,搬到 src/huggingface/tests/responses/responses_language_model.rs);测试数前后仍相等(Hugging Face 57 个,测试分支 lib 22 个加老测试程序 35 个,名字多重集相同)。

一、体系现状(概览,测试 PR #303 头 7f0f7328)

aimux_providers::create_huggingface                   src/huggingface.rs:106
 └ HuggingFaceProvider::language_model → responses    src/huggingface.rs:199 → :177
   └ HuggingFaceResponsesModel::do_generate           src/huggingface/responses.rs:199
     └ build_request_body_with_warnings               src/huggingface/responses.rs:622
       ├ convert_to_huggingface_responses_messages    src/huggingface/responses.rs:768
       └ prepare_responses_tools                      src/huggingface/responses.rs:922
     └ post_json_to_api(huggingface_failed_response_handler)   src/huggingface/responses.rs:48
     └ convert_usage / map_finish_reason              src/huggingface/responses.rs:1170 / :1151
   └ do_stream → HuggingFaceResponsesStream           src/huggingface/responses.rs:252

上游同一条路:createHuggingFace(huggingface-provider.ts)→ HuggingFaceResponsesLanguageModel.doGenerate(responses/huggingface-responses-language-model.ts)→ convertToHuggingFaceResponsesMessages、prepareResponsesTools、convertHuggingFaceResponsesUsage、mapHuggingFaceResponsesFinishReason 各在自己的文件。aimux 把 5 个上游文件放在一个 1,219 行的 responses.rs 里,工厂和 index.ts 在 huggingface.rs。

测试:#303 的新用例在 src/huggingface/tests/,老的 wiremock 用例还在 tests/huggingface_responses_test.rs(一个独立测试程序,35 个用例,含修复 PR #305–#307 加的 2 个)。

二、本 PR 改动(细节)

aimux_providers::create_huggingface                   src/huggingface/provider.rs:83      ← huggingface-provider.ts
 └ HuggingFaceProvider::language_model → responses    src/huggingface/provider.rs:176 → :154
   └ HuggingFaceResponsesModel::do_generate           src/huggingface/responses/responses_language_model.rs:167
     └ build_request_body_with_warnings               src/huggingface/responses/responses_language_model.rs:586
       ├ convert_to_huggingface_responses_messages    src/huggingface/responses/convert_to_responses_messages.rs:28
       └ prepare_responses_tools                      src/huggingface/responses/responses_prepare_tools.rs:14
     └ post_json_to_api(huggingface_failed_response_handler)   src/huggingface/error.rs:7
     └ convert_usage / map_finish_reason              src/huggingface/responses/convert_responses_usage.rs:11
                                                       src/huggingface/responses/map_responses_finish_reason.rs:6
   └ do_stream → HuggingFaceResponsesStream           src/huggingface/responses/responses_language_model.rs:220
现在 搬到 上游
huggingface.rs 模块文档、导出 huggingface/mod.rs(只有模块声明和 pub use) index.ts
huggingface.rs 设置、工厂、默认实例 huggingface/provider.rs huggingface-provider.ts(HuggingFaceConfig 由这里组装)
responses.rs 错误处理器 huggingface/error.rs huggingface-error.ts
responses.rs 模型、流、请求体、响应解析 responses/responses_language_model.rs responses/huggingface-responses-language-model.ts
responses.rs 消息转换、媒体类型 responses/convert_to_responses_messages.rs convert-to-huggingface-responses-messages.ts
responses.rs 工具准备 responses/responses_prepare_tools.rs huggingface-responses-prepare-tools.ts
responses.rs 用量、finish reason responses/convert_responses_usage.rs、responses/map_responses_finish_reason.rs 同名两个文件
options.rs responses/responses_language_model_options.rs huggingface-responses-language-model-options.ts
  • 公开路径不变:huggingface::responses::{HuggingFaceResponsesModel, build_request_body_with_warnings, convert_to_huggingface_responses_messages, prepare_responses_tools, RequestBodyResult} 由 responses/mod.rs 再导出。
  • 跨文件调用的三个私有函数改成 pub(super)(convert_usage、map_finish_reason、huggingface_failed_response_handler),模型里 super::options:: 改成引用 responses_language_model_options as options,函数体不动。
  • 测试:tests/huggingface_responses_test.rs 按 describe 并进 src/huggingface/tests/responses/responses_language_model.rs,它的 wiremock 帮手放到同目录 support.rs(pub(super));aimux_providers:: 改成 crate::。修复 PR 新加的 2 个用例跟着并进同一文件的原位置。
  • layout.toml 的 rust 字段改到新路径;check_provider_boundaries.sh 规则 8 允许 *_language_model_options.rs 写命名空间键,去掉已不存在的 huggingface.rs。

验证

  • cargo test -p aimux-providers --lib 加原 --test huggingface_responses_test:前后都是 192 个测试,模块路径(去掉文件前缀后)和函数名完全相同;Hugging Face 的 58 个全过。
  • cargo +1.99 clippy -p aimux-providers --lib --tests -- -D warnings、cargo doc -D warnings、cargo fmt --check、scripts/check_provider_boundaries.sh 通过。

Type of change

  • Refactor (no behavior change)

Checklist

  • Tests pass locally
  • Commit messages follow Conventional Commits

共享进程状态:测试原来各自是单独的测试程序,现在并进 lib 的同一个测试程序。本家的测试不改环境变量,不用全局计数器和固定临时路径,搬进来不受别家影响(RFC-0046 §5)。

https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW


Generated by Claude Code

…yout

One Rust file per @ai-sdk/huggingface source file (RFC-0046 §4.2):
huggingface.rs becomes huggingface/mod.rs (index.ts, module list only)
with the factory in provider.rs and the error handler in error.rs;
responses.rs splits into responses/ with responses_language_model.rs,
convert_to_responses_messages.rs, responses_prepare_tools.rs,
convert_responses_usage.rs and map_responses_finish_reason.rs, and
options.rs becomes responses/responses_language_model_options.rs.

tests/huggingface_responses_test.rs joins
src/huggingface/tests/responses/responses_language_model.rs by describe
block, its wiremock helpers in tests/responses/support.rs (RFC-0046 §5).
Move only: the test count and the test paths and names are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
The test branch now stacks on the fix PRs #305-#307, which add two
aimux-own tests at the end of tests/huggingface_responses_test.rs. That
file is already merged into
src/huggingface/tests/responses/responses_language_model.rs, so the two
tests land there at the same places.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
@cunninghamcard-bit
cunninghamcard-bit marked this pull request as ready for review October 24, 2026 11:25

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hugging Face layout refactor:42/42 production functions 与 57/57 tests 归一化后一致,公开 re-export 保留。Approve。

claude added 10 commits October 25, 2026 08:51
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…ace-tests' into refactor/move-the-hugging-face-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…ace-tests' into refactor/move-the-hugging-face-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…ace-tests' into refactor/move-the-hugging-face-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…ace-tests' into refactor/move-the-hugging-face-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…ace-tests' into refactor/move-the-hugging-face-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…ace-tests' into refactor/move-the-hugging-face-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…ace-tests' into refactor/move-the-hugging-face-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…ace-tests' into refactor/move-the-hugging-face-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
…ace-tests' into refactor/move-the-hugging-face-files-to-the-upstream-layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0116HPMoqaLfFr1TyqDq1hrW
@eric8810
eric8810 changed the base branch from test/port-the-upstream-hugging-face-tests to master October 27, 2026 14:10
@eric8810
eric8810 merged commit bd9bb0f into master Oct 27, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants