Skip to content

Go: implement provider: TokenPony - #15091

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
dripsmvcp:fix/15086-go-tokenpony-driver
May 22, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
dripsmvcp:fix/15086-go-tokenpony-driver

Conversation

@dripsmvcp

Copy link
Copy Markdown
Contributor

Summary

  • Adds a TokenPony Go driver so the new API server can route TokenPony chat instances, matching the existing Python TokenPonyChat (rag/llm/chat_model.py:1210). Follows the same SaaS-driver shape used for Astraflow, Avian, Novita, TogetherAI, Replicate, DeepInfra, Upstage, and LongCat.

Root Cause

conf/llm_factories.json:282 already registers the TokenPony factory with 16 chat models and the default base URL https://ragflow.vip-api.tokenpony.cn/v1, but internal/entity/models/ had no tokenpony.go driver and conf/models/ had no tokenpony.json, so the Go API server fell back to the dummy driver for TokenPony instances.

Fix

  • internal/entity/models/tokenpony.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). Reasoning models surface reasoning_content separately from content. SSE handling rejects malformed frames, surfaces upstream {"error": …} frames, and requires a [DONE]/finish_reason terminator.
  • conf/models/tokenpony.json — base URL https://ragflow.vip-api.tokenpony.cn/v1 + the 16 chat models from the factory entry (qwen3-8b/-32b/-coder-480b/-next-80b/-235b/-vl-*, deepseek-v3-0324/-r1-0528/-v3.2-exp/-v3.1-terminus/-ocr, kimi-k2-instruct-0905, hunyuan-a13b-instruct, glm-4.6, minimax-m2).
  • internal/entity/models/factory.go — registers the tokenpony case.
  • internal/entity/models/tokenpony_test.go — 21 hermetic tests using httptest.Server (no network).

Test Plan

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

Closes #15086

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

coderabbitai Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ac9092d-314c-4b87-a194-ef88928b4342

📥 Commits

Reviewing files that changed from the base of the PR and between 504cc2f and c71a96d.

📒 Files selected for processing (1)
  • internal/entity/models/factory.go

📝 Walkthrough

Walkthrough

Adds TokenPony provider: new config and factory case, TokenPonyModel driver implementing chat (sync + SSE), ListModels/CheckConnection, unsupported-method stubs, and comprehensive unit tests.

Changes

TokenPony Provider Implementation

Layer / File(s) Summary
Configuration and Factory Wiring
conf/models/tokenpony.json, internal/entity/models/factory.go
TokenPony provider config defines base URLs and endpoints and lists supported chat models; factory adds "tokenpony" case to CreateModelDriver.
Driver Structure and Initialization
internal/entity/models/tokenpony.go (lines 17–90)
TokenPonyModel struct, NewTokenPonyModel with tuned HTTP transport, NewInstance, Name, and region base-URL selection helper.
Chat API (Non-streaming & Streaming)
internal/entity/models/tokenpony.go (lines 91–371)
ChatWithMessages validates inputs, posts OpenAI-shaped JSON, parses choices[0].message.content and optional reasoning_content; ChatStreamlyWithSender posts with stream:true, parses SSE data: frames, emits reasoning/content deltas via callback, surfaces upstream error frames, and enforces proper stream termination.
Model Listing & Connection Check
internal/entity/models/tokenpony.go (lines 373–446)
ListModels requests /v1/models and returns model IDs (skips malformed entries); CheckConnection delegates to ListModels.
Unsupported Capability Stubs
internal/entity/models/tokenpony.go (lines 448–493)
Embeddings, reranking, balance, ASR/TTS, OCR/parsing, and task APIs return consistent "no such method" errors.
Comprehensive Test Suite
internal/entity/models/tokenpony_test.go
HTTP and SSE test servers plus tests covering factory/name, chat sync/stream (happy/error paths), model listing, connection checks, region config validation, and unsupported-method responses.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • #14604 — Adds a new Go model driver and updates CreateModelDriver similarly; same code areas affected.
  • #15088 — Adds a SaaS provider driver with chat/SSE and ListModels/CheckConnection patterns, touching the same implementation surface.
  • #14814 — New ModelDriver + conf/models JSON and factory switch registration, similar integration work.

Possibly related PRs

Suggested labels

size:XL

Suggested reviewers

  • Haruko386

Poem

🐇 I slipped a TokenPony into the stack,
With tiny streams that prance and answers that tack.
Config and tests in a tidy array,
The chat now trots forward, bright as day. 🥕

🚥 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 title accurately reflects the main change: implementing a TokenPony provider in Go, which is the primary objective of the PR.
Description check ✅ Passed The PR description provides comprehensive context including summary, root cause, fix details, and test plan, but does not follow the provided template structure with Type of change checkboxes.
Linked Issues check ✅ Passed All requirements from issue #15086 are met: TokenPonyModel driver with ChatWithMessages/ChatStreamlyWithSender, ListModels, CheckConnection, conf/models/tokenpony.json with 16 models, factory registration, and 21 passing tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the TokenPony provider as specified in issue #15086; no extraneous modifications detected.

✏️ 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.

@dripsmvcp

Copy link
Copy Markdown
Contributor Author

@dosu

@dosubot

dosubot Bot commented May 21, 2026

Copy link
Copy Markdown

This PR looks well-structured and follows the established pattern for OpenAI-compatible SaaS drivers in RAGFlow. A few observations:

Alignment with existing patterns: The implementation matches the approach used by the 6+ existing Go drivers (Novita, DeepInfra, Upstage, TogetherAI, Replicate, LongCat) in internal/entity/models/ [1]. The factory registration via a case "tokenpony": in the switch statement in factory.go is consistent with how other providers are wired up [2].

Factory config confirmed: The TokenPony entry at conf/llm_factories.json:282 with base URL https://ragflow.vip-api.tokenpony.cn/v1 and 16 chat models is already present [3], so this PR correctly fills the gap between the factory declaration and the missing driver.

Test coverage: 21 hermetic tests using httptest.Server is solid — no network dependency and good coverage of SSE parsing edge cases (malformed frames, upstream error frames, [DONE] termination).

One note: The PR description mentions "Astraflow" and "Avian" as reference drivers, but those don't appear to be merged into the main branch yet — only Novita, DeepInfra, Upstage, TogetherAI, Replicate, and LongCat are currently present [1]. This doesn't affect the PR itself, just a heads-up that those references may point to other in-flight PRs.

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about ragflow Share Dosu with 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.

🧹 Nitpick comments (1)
internal/entity/models/tokenpony_test.go (1)

160-160: 💤 Low value

Optional: Consider nil for absent reasoning content.

The test expects ReasonContent to be a non-nil pointer to an empty string when reasoning is absent, rather than nil. While this works, the more idiomatic Go pattern is to use nil pointers to indicate absence. This would simplify client code by avoiding dereferences when checking for empty content.

Example of idiomatic pattern:

if resp.ReasonContent != nil && *resp.ReasonContent != "" {
    // use reasoning
}

vs current pattern requiring:

if resp.ReasonContent != nil && *resp.ReasonContent != "" {
    // this check is always needed even though ReasonContent is never nil
}
🤖 Prompt for 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.

In `@internal/entity/models/tokenpony_test.go` at line 160, The test currently
asserts that resp.ReasonContent is a non-nil pointer to an empty string; change
it to the idiomatic nil-for-absent pattern by ensuring the fixture or
constructor that builds resp leaves ReasonContent as nil when no reasoning
exists and update the assertion to check resp.ReasonContent == nil (or use if
resp.ReasonContent != nil && *resp.ReasonContent != "" where appropriate).
Locate usages of ReasonContent in tokenpony_test.go and the helper that
constructs the response (the resp variable) and set ReasonContent = nil for
absent reasoning, then replace the existing non-nil/empty-string check with a
nil check.
🤖 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.

Nitpick comments:
In `@internal/entity/models/tokenpony_test.go`:
- Line 160: The test currently asserts that resp.ReasonContent is a non-nil
pointer to an empty string; change it to the idiomatic nil-for-absent pattern by
ensuring the fixture or constructor that builds resp leaves ReasonContent as nil
when no reasoning exists and update the assertion to check resp.ReasonContent ==
nil (or use if resp.ReasonContent != nil && *resp.ReasonContent != "" where
appropriate). Locate usages of ReasonContent in tokenpony_test.go and the helper
that constructs the response (the resp variable) and set ReasonContent = nil for
absent reasoning, then replace the existing non-nil/empty-string check with a
nil check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ee1f6630-c37f-4643-80a1-2d524aa62fba

📥 Commits

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

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

@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
please fix the wrong url

Comment thread conf/models/tokenpony.json Resolved

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

@dripsmvcp LGTM
Thank you for your contribution

@Haruko386 Haruko386 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 (57ddd79) to head (c71a96d).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15091      +/-   ##
==========================================
- 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.

@JinHai-CN
JinHai-CN merged commit ed04893 into infiniflow:main May 22, 2026
1 check passed
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: TokenPony in Go driver

4 participants