Skip to content

Go: implement provider: Tencent Hunyuan - #15092

Merged
JinHai-CN merged 7 commits into
infiniflow:mainfrom
dripsmvcp:fix/15087-go-hunyuan-driver
May 25, 2026
Merged

JinHai-CN merged 7 commits into
infiniflow:mainfrom
dripsmvcp:fix/15087-go-hunyuan-driver

Conversation

@dripsmvcp

Copy link
Copy Markdown
Contributor

Summary

  • Adds a Hunyuan Go driver so the new API server can route Tencent Hunyuan chat instances (registered in conf/llm_factories.json:3830 as Tencent Hunyuan). Follows the same SaaS-driver shape used for Astraflow, Avian, Novita, TogetherAI, Replicate, DeepInfra, Upstage, and LongCat.

Root Cause

conf/llm_factories.json:3830 already registers the Tencent Hunyuan factory with 5 preconfigured models and the default base URL https://api.hunyuan.cloud.tencent.com/v1, but internal/entity/models/ had no hunyuan.go driver and conf/models/ had no hunyuan.json, so the Go API server fell back to the dummy driver for Hunyuan instances.

Fix

  • internal/entity/models/hunyuan.go — OpenAI-compatible driver implementing ChatWithMessages, ChatStreamlyWithSender, ListModels, and CheckConnection (delegates to ListModels). Forwards documented fields only (model, messages, stream, max_tokens, temperature, top_p, stop). SSE handling rejects malformed frames, surfaces upstream {"error": …} frames, and requires a [DONE]/finish_reason terminator.
  • conf/models/hunyuan.json — base URL + the 4 chat models from the factory entry (hunyuan-pro, hunyuan-standard, hunyuan-standard-256K, hunyuan-lite). hunyuan-vision is deliberately omitted from this initial driver; Image2Text support (factory tags include IMAGE2TEXT) lands in a follow-up issue, mirroring how Novita / TogetherAI / DeepInfra landed method-by-method.
  • internal/entity/models/factory.go — registers the hunyuan case.
  • internal/entity/models/hunyuan_test.go — 21 hermetic tests using httptest.Server (no network).

Test Plan

  • Regression tests added: internal/entity/models/hunyuan_test.go
  • All tests pass: go test ./internal/entity/models/ -run Hunyuan -count=1 -vet=off
  • Output: 21/21 PASS.

Closes #15087

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 21, 2026
@dripsmvcp

Copy link
Copy Markdown
Contributor Author

@dosu

@coderabbitai

coderabbitai Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds Tencent Hunyuan as a Go model provider: configuration and factory wiring, a HunyuanModel driver with sync chat, SSE streaming (separating reasoning/content), model listing and CheckConnection, unimplemented stubs for other capabilities, and comprehensive tests.

Changes

Tencent Hunyuan Model Driver Integration

Layer / File(s) Summary
Provider Configuration and Factory Registration
conf/models/hunyuan.json, internal/entity/models/factory.go
Provider metadata and four chat models are added; CreateModelDriver routes "hunyuan" to NewHunyuanModel.
Driver Type and HTTP Infrastructure
internal/entity/models/hunyuan.go (lines 1–75)
Introduces HunyuanModel struct, constructor, region-aware base URL resolution, and a tuned HTTP transport/client.
Instance creation and base URL helper
internal/entity/models/hunyuan.go (lines 77–92)
Implements NewInstance, Name(), and base-URL resolution helper that errors for unknown regions.
Chat (non-stream) Implementation
internal/entity/models/hunyuan.go (lines 93–213)
ChatWithMessages validates inputs, posts a chat request, enforces HTTP 200, and parses choices[0].message.content and reasoning_content.
SSE Streaming Chat
internal/entity/models/hunyuan.go (lines 214–373)
ChatStreamlyWithSender sends SSE streaming requests, scans data: frames, decodes events, forwards delta.reasoning_content and delta.content (reasoning first), surfaces upstream errors, and enforces terminal events with a final [DONE] sentinel.
Model Listing and Connection Check
internal/entity/models/hunyuan.go (lines 375–448)
ListModels fetches /v1/models and parses data[].id; CheckConnection delegates to ListModels.
Unimplemented Capabilities
internal/entity/models/hunyuan.go (lines 450–495)
Other capabilities (embed, rerank, audio, OCR/parse, tasks) return a consistent "no such method" error.
Test Suite and Validation
internal/entity/models/hunyuan_test.go
Adds HTTP and SSE test servers and tests for factory, chat (with/without reasoning), streaming edge cases, model listing, connection checks, base-URL handling, and unsupported-method responses.

Sequence Diagram

sequenceDiagram
  participant Client as Chat caller
  participant Hunyuan as Hunyuan API
  participant Sender as Sender callback
  Client->>Hunyuan: POST /v1/chat/completions (stream? true/false, model, messages)
  alt non-stream
    Hunyuan-->>Client: 200 JSON (choices[0].message.content, reasoning_content)
    Client->>Sender: send(content, reasoning_content) (final)
  else stream (SSE)
    Hunyuan-->>Client: SSE data: {delta.content}, {delta.reasoning_content}, ... , [DONE]
    Client->>Sender: send(reasoning_delta, nil) per reasoning frames
    Client->>Sender: send(nil, content_delta) per content frames
    Client->>Sender: send("[DONE]", "[DONE]") on terminal event
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • #14604: Adds a new Go model driver and updates factory routing similarly (analogous provider-driver pattern).
  • #14814: Similar factory routing and new provider driver addition, touching CreateModelDriver and conf/models/*.json.

Possibly related PRs

  • infiniflow/ragflow#14809: Also extends CreateModelDriver to register a new provider constructor; analogous factory change.
  • infiniflow/ragflow#15091: Implements a similar OpenAI-compatible driver with Chat/SSE/List/CheckConnection flows.
  • infiniflow/ragflow#14940: Adds a new provider driver and updates factory routing with comparable chat and listing behavior.

Suggested labels

💞 feature

Suggested reviewers

  • Haruko386
  • tmimmanuel

Poem

🐰 I hopped into Hunyuan's stream tonight,
SSE frames and reasoning shining bright,
content and thoughts in tidy little queues,
factory wired, tests ran through—no loose screws,
a rabbit cheers: the driver’s right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'Go: implement provider: Tencent Hunyuan' directly and clearly summarizes the main objective of adding a Tencent Hunyuan provider implementation to the Go codebase.
Description check ✅ Passed The PR description covers the problem (missing driver for Tencent Hunyuan), provides a detailed fix with specific files, and includes test results, though it deviates slightly from the template structure by using custom sections.
Linked Issues check ✅ Passed The PR implementation fully satisfies #15087 requirements: HunyuanModel driver with ChatWithMessages/ChatStreamlyWithSender/ListModels/CheckConnection, conf/models/hunyuan.json with base URL and chat models, factory.go registration, and comprehensive test coverage (21 tests).
Out of Scope Changes check ✅ Passed All changes are strictly in-scope: driver implementation, configuration file, factory registration, and tests directly address the Hunyuan provider implementation objective; Image2Text support is intentionally deferred as noted in the description.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dosubot

dosubot Bot commented May 21, 2026

Copy link
Copy Markdown

This PR looks like a solid implementation that follows the established SaaS-driver pattern used by the other OpenAI-compatible providers (TogetherAI, DeepInfra, Novita, etc.) [1]. A few observations:

  1. Pattern alignment: The approach — hunyuan.go with ChatWithMessages, ChatStreamlyWithSender, ListModels, CheckConnection, plus a conf/models/hunyuan.json and factory registration — matches exactly how the other providers are structured [2] [3].

  2. Factory entry already exists: conf/llm_factories.json:3830 already declares the Tencent Hunyuan factory with the base URL and preconfigured models [4], so this PR fills in the missing Go driver that the factory expects.

  3. Scope is reasonable: Omitting hunyuan-vision (IMAGE2TEXT) for a follow-up is consistent with how other providers landed incrementally.

  4. Test coverage: 21 hermetic tests with httptest.Server is a good approach — no network dependency and covers the SSE parsing edge cases you mentioned (malformed frames, upstream error frames, [DONE] terminator).

The referenced feature request (#15087) confirms this was the expected implementation path [5]. Looks good overall — nice addition to the Go driver set.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about ragflow with Dosu Add Dosu to your team

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/entity/models/hunyuan_test.go`:
- Around line 12-44: The test helper newHunyuanServer currently only asserts
method for POST but not for other endpoints; update newHunyuanServer to accept
an expected HTTP method (or add an expectedMethod string) and assert r.Method ==
expectedMethod before handling the request (returning an error or t.Errorf on
mismatch), then update the ListModels and CheckConnection tests to call
newHunyuanServer with the appropriate expected method (e.g., "GET") so the
helper enforces the verb for non-POST calls; reference the newHunyuanServer
function and the tests invoking ListModels/CheckConnection to locate where to
add the expectedMethod parameter and assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ef08e924-f5ce-4276-81ac-9d737965fe77

📥 Commits

Reviewing files that changed from the base of the PR and between fec0b96 and e957d8a.

📒 Files selected for processing (4)
  • conf/models/hunyuan.json
  • internal/entity/models/factory.go
  • internal/entity/models/hunyuan.go
  • internal/entity/models/hunyuan_test.go

Comment thread internal/entity/models/hunyuan_test.go Resolved
Per CodeRabbit review on infiniflow#15092: newHunyuanServer asserted path,
Authorization, and body, but not the HTTP verb. A future bug that
flipped ListModels from GET to POST (or vice versa) would silently
pass the existing tests.

Add an expectedMethod parameter, assert r.Method matches up front,
and update all six call sites:
- 3 chat-completions tests pass http.MethodPost
- 3 /models tests pass http.MethodGet

All 14 TestHunyuan* tests still pass.
@dripsmvcp

Copy link
Copy Markdown
Contributor Author

Fixes Applied Successfully

Fixed 1 file based on 1 CodeRabbit feedback item.

Files modified:

  • internal/entity/models/hunyuan_test.go

Commit: d04ffd383

The latest autofix changes are on the fix/15087-go-hunyuan-driver branch.

Addressed: assert HTTP method (GET vs POST) in newHunyuanServer so the ListModels/CheckConnection tests would catch an accidental verb switch. Helper now takes expectedMethod string parameter; the 3 chat-completions sites pass http.MethodPost, the 3 /models sites pass http.MethodGet. All 14 TestHunyuan* tests still pass locally.

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @dripsmvcp, thank you for your contribution.
All tests are passed, just do a small change

Comment thread conf/models/hunyuan.json Outdated
@@ -0,0 +1,33 @@
{
"name": "Tencent Hunyuan",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just use HunYuan

@dripsmvcp

Copy link
Copy Markdown
Contributor Author

FIxed it, thanks for the review @Haruko386

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@JinHai-CN JinHai-CN added the ci Continue Integration label May 22, 2026
@codecov

codecov Bot commented May 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (e6dd397) to head (cd03d3f).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15092      +/-   ##
==========================================
- Coverage   94.53%   93.12%   -1.41%     
==========================================
  Files          10       10              
  Lines         713      713              
  Branches      116      116              
==========================================
- Hits          674      664      -10     
- Misses         25       29       +4     
- Partials       14       20       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Implement provider: Tencent Hunyuan in Go driver

3 participants