Skip to content

Feat: OpenAI-API-Compatible - #17276

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
Lynn-Inf:fix/display-openai-compatible
Jul 23, 2026
Merged

wangq8 merged 3 commits into
infiniflow:mainfrom
Lynn-Inf:fix/display-openai-compatible

Conversation

@Lynn-Inf

Copy link
Copy Markdown
Contributor

Summary

Go: add OpenAI‑API‑compatible model provider.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 23, 2026
@Lynn-Inf
Lynn-Inf requested a review from wangq8 July 23, 2026 04:06
@Lynn-Inf Lynn-Inf added the ci Continue Integration label Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 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 Plus

Run ID: a214fd43-ceaf-4f23-86c2-68101b2befe9

📥 Commits

Reviewing files that changed from the base of the PR and between 19bdc02 and e445d41.

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

📝 Walkthrough

Walkthrough

Adds an OpenAI-API-compatible provider configuration and driver with model discovery, type inference, non-streaming TTS, and ASR support. Provider listing merges static and live models, while connection checks accept structured model metadata.

Changes

OpenAI-compatible provider

Layer / File(s) Summary
Provider driver and capabilities
conf/models/openai-api-compatible.json, internal/entity/models/factory.go, internal/entity/models/openai_api_compatible.go
Registers the provider and implements model listing, model-type inference, non-streaming TTS, and non-streaming ASR operations.
Live model listing integration
internal/handler/providers.go
Merges static and remotely fetched models by name, sorts results, and forwards structured model information during connection checks.
Structured connection verification
internal/service/model_service.go
Accepts structured model metadata and uses supplied or inferred model types during verification.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ProviderHandler
  participant OpenAIAPICompatibleModel
  participant CompatibleAPI
  ProviderHandler->>OpenAIAPICompatibleModel: ListModels(apiConfig)
  OpenAIAPICompatibleModel->>CompatibleAPI: Request provider models
  CompatibleAPI-->>OpenAIAPICompatibleModel: Return model metadata
  OpenAIAPICompatibleModel-->>ProviderHandler: Return typed model entries
Loading

Possibly related PRs

Suggested labels: 💞 feature

Poem

I’m a rabbit with models to share,
Through compatible APIs in the air.
Voices can speak, audio can flow,
Typed model lists line up in a row.
Hop, hop—the provider is there!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately points to the new OpenAI-API-compatible provider.
Description check ✅ Passed The description matches the template and clearly states the PR summary.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@Lynn-Inf Lynn-Inf changed the title Feat: OpenAI-API-Compatiable Feat: OpenAI-API-Compatible Jul 23, 2026

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/service/model_service.go (1)

1014-1065: 🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win

Models sharing an already-verified type are incorrectly marked as failed.

passedTypes is shared across the entire modelsToVerify loop. When model B's type was already verified successful by an earlier model A, the if passedTypes[mtLower] { continue } branch skips the redundant API call but never sets anyPassed = true for model B — so modelVerifyResult[modelName] for B falls through to entity.ModelVerifyFail (line 1063) even though that model type is known-good. This incorrect status gets persisted to the DB via updateModelVerifyResults.

🐛 Proposed fix
 			// If a model type we've already verified successfully, skip.
 			if passedTypes[mtLower] {
+				anyPassed = true
 				continue
 			}
🤖 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/service/model_service.go` around lines 1014 - 1065, Update the
modelsToVerify loop so encountering a type already marked in passedTypes also
sets anyPassed = true before skipping further checks. Preserve the existing skip
behavior and ensure models sharing a previously verified type receive
entity.ModelVerifySuccess.
🧹 Nitpick comments (1)
internal/handler/providers.go (1)

163-185: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Live-fetch failures are silently swallowed.

If FindProvider, NewInstance, or ListModels fail/return nil, the handler silently falls back to static-only results with no log line, making misconfiguration (e.g. bad base_url) hard to diagnose from server logs.

🤖 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/handler/providers.go` around lines 163 - 185, Add diagnostic logging
throughout the live-model fetch flow around FindProvider,
ModelDriver.NewInstance, and driver.ListModels: log when the provider or driver
is missing, and include the returned error when ListModels fails. Preserve the
existing static fallback and successful remoteModels population, while ensuring
each nil or error path emits a clear server log entry.
🤖 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/factory.go`:
- Around line 58-59: Update OpenAIAPICompatibleModel.AudioSpeech to match the
ModelDriver interface by adding the required context.Context parameter, and
adjust its implementation and callers accordingly. Keep the
openai-api-compatible factory case returning NewOpenAIAPICompatibleModel
unchanged.

In `@internal/handler/providers.go`:
- Line 174: Update OpenAIAPICompatibleModel methods ListModels, AudioSpeech,
AudioSpeechWithSender, TranscribeAudio, and TranscribeAudioWithSender to accept
ctx context.Context first; forward it to VllmModel.ListModels and use
context.WithTimeout(ctx, nonStreamCallTimeout) instead of context.Background().
Update the providers.go driver.ListModels call to pass c.Request.Context(),
preserving factory.go unchanged.

---

Outside diff comments:
In `@internal/service/model_service.go`:
- Around line 1014-1065: Update the modelsToVerify loop so encountering a type
already marked in passedTypes also sets anyPassed = true before skipping further
checks. Preserve the existing skip behavior and ensure models sharing a
previously verified type receive entity.ModelVerifySuccess.

---

Nitpick comments:
In `@internal/handler/providers.go`:
- Around line 163-185: Add diagnostic logging throughout the live-model fetch
flow around FindProvider, ModelDriver.NewInstance, and driver.ListModels: log
when the provider or driver is missing, and include the returned error when
ListModels fails. Preserve the existing static fallback and successful
remoteModels population, while ensuring each nil or error path emits a clear
server log entry.
🪄 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 Plus

Run ID: ce00f210-90a0-42a8-ad7f-81a341114ae6

📥 Commits

Reviewing files that changed from the base of the PR and between 7b29fc1 and 19bdc02.

📒 Files selected for processing (5)
  • conf/models/openai-api-compatible.json
  • internal/entity/models/factory.go
  • internal/entity/models/openai_api_compatible.go
  • internal/handler/providers.go
  • internal/service/model_service.go

Comment thread internal/entity/models/factory.go Resolved
Comment thread internal/handler/providers.go Resolved

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review: Feat: OpenAI-API-Compatible

Overall solid implementation — clean use of struct embedding to reuse VllmModel; type inference heuristics and ListModels merging are well-structured. A few items to address:

🔴 API key in query params (internal/handler/providers.go:158)

apiKey := c.Query("api_key")

API keys passed as query parameters are logged in access logs, proxy logs, and browser history. This is a security concern for any proxy or logging middleware between the client and RAGFlow. Consider requiring the key through a POST body field or an Authorization-type header instead.

🟡 Silent live-fetch failures (internal/handler/providers.go:172)

if liveModels, err := driver.ListModels(apiConfig); err == nil {

When the live API call fails (bad key, unreachable URL, timeout), the error is silently swallowed. The user sees only static models with no indication their credentials were rejected or the endpoint is unreachable. At minimum, log the error; ideally surface it as a warning in the response metadata so the UI can show it.

🟡 Missing streaming stubs (openai_api_compatible.go)

AudioSpeechWithSender and TranscribeAudioWithSender both return fmt.Errorf(...not implemented...). The doc comments say this is intentional, but if a caller tries the streaming path for connection verification it will get a hard error. Consider a TODO with a tracking issue or a feature-gate check higher in the call chain.

🟢 Structural notes (no action needed)

  • InferModelTypes checks rerank before embedding, which correctly handles models named like bge-reranker-v2 that match both hint sets. Good.
  • ttsVoiceForModel for cosyvoice returns modelName + ":anna" — this is an unusual compound format. If this is the expected convention for CosyVoice on SiliconFlow, a comment confirming would help future readers.
  • The CheckConnection / verifyProviderModel signature change from []string to []CheckConnectionModelInfo is internally consistent — both call sites in providers.go are updated, and the nil path at L343 works with both signatures.
  • PR size is reasonable (450 additions, 30 deletions), single concern, no unrelated changes.

Suggestion (non-blocking)

The ListModels handler change is the most impactful part — it introduces the concept of live model fetching in the API layer. A unit test for the merge/sort logic would be valuable since the dedup (remote overwrites static by name) and alphabetical sort are easy to regression-test.

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.

2 participants