Skip to content

Go: implement provider: Xinference - #14938

Merged
JinHai-CN merged 4 commits into
infiniflow:mainfrom
tmimmanuel:go/xinference-chat
May 19, 2026
Merged

JinHai-CN merged 4 commits into
infiniflow:mainfrom
tmimmanuel:go/xinference-chat

Conversation

@tmimmanuel

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Closes #14808.

Adds a Go model driver for Xinference so self-hosted Xinference chat models can be used through the Go provider layer instead of falling through to the dummy driver. Xinference exposes an OpenAI-compatible API under /v1; the driver accepts either a root endpoint such as http://127.0.0.1:9997 or an OpenAI-compatible endpoint such as http://127.0.0.1:9997/v1 and normalizes it before calling chat or model-listing routes.

What is changed?

  • Add internal/entity/models/xinference.go implementing ModelDriver for Xinference chat.
  • Route provider name xinference in internal/entity/models/factory.go.
  • Add conf/models/xinference.json as a local provider config.
  • Add focused unit tests in internal/entity/models/xinference_test.go.

Initial method coverage:

  • ChatWithMessages: POST /v1/chat/completions.
  • ChatStreamlyWithSender: SSE streaming from /v1/chat/completions.
  • ListModels: GET /v1/models.
  • CheckConnection: lightweight ListModels probe.
  • Optional auth: send Authorization: Bearer <api_key> only when a non-empty key is configured, matching Xinference no-auth and auth-enabled deployments.
  • Balance, Embed, Rerank, ASR, TTS, and OCR return no such method for this initial chat-provider PR.

Type of change

  • New Feature (non-breaking change which adds functionality)
  • Bug Fix (non-breaking change which fixes an issue)

Tests

  • go test -vet=off -run TestXinference -count=1 ./internal/entity/models/...
  • go test -vet=off -count=1 ./internal/entity/models/...

References

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

coderabbitai Bot commented May 14, 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: df6685ee-85ac-4a1b-91fc-bdcab2507b20

📥 Commits

Reviewing files that changed from the base of the PR and between 51a3a8a and 33fa95b.

📒 Files selected for processing (1)
  • internal/entity/models/xinference.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/entity/models/xinference.go

📝 Walkthrough

Walkthrough

Adds a Xinference model provider: config and factory routing, a new XinferenceModel driver (HTTP client, base-URL normalization), synchronous and SSE streaming chat (idle-timeout), model listing and connectivity, unsupported-method stubs, and comprehensive httptest coverage.

Changes

Xinference Model Driver

Layer / File(s) Summary
Configuration and Factory Routing
conf/models/xinference.json, internal/entity/models/factory.go
Xinference provider metadata is added and the factory switch case routes "xinference" to NewXinferenceModel.
Driver core, init, helpers
internal/entity/models/xinference.go
Defines XinferenceModel, normalizes base URLs (trim + remove trailing /v1), clones/tunes HTTP transport, provides auth/header helpers and reasoning-extraction helpers used by chat implementations.
ChatWithMessages (non-stream)
internal/entity/models/xinference.go
Non-streaming chat: validates input, POSTs to /v1/chat/completions with stream:false, enforces HTTP 200, parses first choice, and returns ChatResponse with content and prioritized reasoning fields.
ChatStreamlyWithSender (SSE streaming, idle timeout)
internal/entity/models/xinference.go
Streaming chat: POSTs with stream:true, scans SSE data: lines for choices[0].delta, emits reasoning/content fragments to the sender, detects [DONE]/finish_reason, cancels on idle via background ticker, and emits terminal [DONE].
ListModels, CheckConnection, Balance & stubs
internal/entity/models/xinference.go
Implements ListModels (GET /v1/models) with model ID filtering, CheckConnection delegating to ListModels, Balance as a stub, and other capabilities returning "no such method".
Comprehensive tests (httptest)
internal/entity/models/xinference_test.go
End-to-end tests for Name(), base-URL normalization, factory routing, non-stream and stream chat behavior (auth handling, SSE events, reasoning extraction), idle-timeout cancellation, model listing, missing-base-URL errors, and unsupported-method assertions.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant XinferenceModel
  participant XinferenceAPI as /v1/chat/completions
  participant SenderCallback
  participant Ticker as IdleTimeoutTicker
  Client->>XinferenceModel: ChatStreamlyWithSender(messages, ChatConfig, sender)
  XinferenceModel->>XinferenceAPI: POST with stream:true, Authorization (optional)
  XinferenceAPI-->>XinferenceModel: SSE data: lines with JSON delta
  XinferenceModel->>SenderCallback: emit delta.reasoning_content / delta.content fragments
  Ticker->>XinferenceModel: cancel on inactivity
  XinferenceModel->>SenderCallback: emit final [DONE]
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • #14810 — PR implements Xinference driver but leaves Embed as a stub; directly related to the same capability.
  • #14736 — Feature request to add a Xinference Go driver; this PR implements that request.
  • #14814 — Related provider wiring and driver additions touching the same factory routing and provider config.

Possibly related PRs

Suggested labels

💞 feature

Suggested reviewers

  • Haruko386

"I stitched a driver, neat and fine,
Streams that drip like tea in line.
Bearer tokens if you choose to show,
Tests that race and timeouts that go,
Hop on, review — then let it glow."

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.76% 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 clearly identifies the main change: implementing a Go provider driver for Xinference model support.
Description check ✅ Passed The description follows the template, clearly states the problem solved (adds Xinference Go driver), lists all changes, explains implementation details, and specifies test commands.
Linked Issues check ✅ Passed All coding requirements from issue #14808 are met: XinferenceModel driver with ModelDriver interface implementation, URL normalization, optional Bearer auth, ChatWithMessages/ChatStreamlyWithSender implementations, ListModels, CheckConnection, and unimplemented methods returning 'no such method'.
Out of Scope Changes check ✅ Passed All changes align with the PR objectives: xinference.go driver implementation, factory.go routing, xinference.json config, and xinference_test.go tests. No unrelated 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.

@tmimmanuel

Copy link
Copy Markdown
Contributor Author

Live Xinference test result (2026-05-14 UTC)

Ran a temporary build-tagged live test against a real local Xinference server. The test file was removed afterward and is not part of this PR.

Environment:

  • Xinference 2.8.0 installed in a temporary virtualenv under /tmp
  • Server: xinference-local --host 127.0.0.1 --port 19997
  • Model: qwen2.5-instruct, size 0_5, format pytorch, engine transformers
  • Endpoint passed to the driver as root URL: http://127.0.0.1:19997 to verify /v1 normalization
  • No API key, covering the default no-auth Xinference setup

Passed live coverage:

  • Name and NewInstance
  • ListModels: returned [qwen2.5-instruct]
  • CheckConnection
  • ChatWithMessages: returned OK
  • ChatStreamlyWithSender: streamed OK and emitted final [DONE]
  • Unsupported methods returned expected no such method: Balance, Embed, Rerank, TranscribeAudio, TranscribeAudioWithSender, AudioSpeech, AudioSpeechWithSender, OCRFile

Command that passed:

XINFERENCE_BASE_URL=http://127.0.0.1:19997 go test -vet=off -tags xinference_live -run TestXinferenceLiveChatProvider -count=1 -v ./internal/entity/models

Runtime note: the first model launch used Xinference's per-model virtualenv, which installed transformers 5.8.1; Xinference returned a backend 500 before the driver could parse a completion: DynamicCache object is not subscriptable. Retrying with transformers==4.53.3 and --disable-virtual-env made the same driver test pass.

Committed regression checks also pass:

go test -vet=off -run TestXinference -count=1 ./internal/entity/models/...
go test -vet=off -count=1 ./internal/entity/models/...

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

@tmimmanuel please read xinference docs for more information

Comment thread conf/models/xinference.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.

@Haruko386 Haruko386 added the ci Continue Integration label May 19, 2026
@Haruko386 Haruko386 assigned tmimmanuel and unassigned tmimmanuel May 19, 2026
@JinHai-CN

Copy link
Copy Markdown
Member

@tmimmanuel would you please fix CI error?

@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (4c9529e) to head (33fa95b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14938   +/-   ##
=======================================
  Coverage   94.16%   94.16%           
=======================================
  Files          10       10           
  Lines         703      703           
  Branches      112      112           
=======================================
  Hits          662      662           
  Misses         25       25           
  Partials       16       16           

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

@tmimmanuel

Copy link
Copy Markdown
Contributor Author

@JinHai-CN
CI is clean.

@JinHai-CN
JinHai-CN merged commit 09a06f1 into infiniflow:main May 19, 2026
1 check passed
JinHai-CN pushed a commit that referenced this pull request May 21, 2026
### What problem does this PR solve?

Fixes #14816

The Xinference Go driver landed chat in #14938 and Embed is in review in
#14932, but `Rerank` shipped as a stub that returns `"xinference, no
such method"`. Tenants who launch a rerank model with `--model-type
rerank` on their Xinference instance cannot route it through the Go API
server. This PR fills the gap.

Xinference exposes an OpenAI-compatible REST API. The rerank endpoint is
at `POST <base>/v1/rerank` and accepts the Cohere-shaped body `{model,
query, documents, top_n}`, returning `{results: [{index,
relevance_score}]}` — the same wire shape used by the merged NVIDIA
(#14778), Aliyun (#14676), Gitee (#14656), ZhipuAI (#14608), Novita
(#15014), and LocalAI (#14813) Rerank implementations. Documented in
[Xinference rerank
docs](https://inference.readthedocs.io/en/v1.6.1/models/model_abilities/rerank.html);
the [builtin rerank model
catalog](https://inference.readthedocs.io/en/stable/models/builtin/rerank/)
lists `bge-reranker-base`, `bge-reranker-large`, `bge-reranker-v2-m3`,
and others.
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]: Add Go driver for Xinference chat provider

3 participants