Repository navigation
Feat: OpenAI-API-Compatible - #17276
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds 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. ChangesOpenAI-compatible provider
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
Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
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 winModels sharing an already-verified type are incorrectly marked as failed.
passedTypesis shared across the entiremodelsToVerifyloop. When model B's type was already verified successful by an earlier model A, theif passedTypes[mtLower] { continue }branch skips the redundant API call but never setsanyPassed = truefor model B — somodelVerifyResult[modelName]for B falls through toentity.ModelVerifyFail(line 1063) even though that model type is known-good. This incorrect status gets persisted to the DB viaupdateModelVerifyResults.🐛 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 winLive-fetch failures are silently swallowed.
If
FindProvider,NewInstance, orListModelsfail/return nil, the handler silently falls back to static-only results with no log line, making misconfiguration (e.g. badbase_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
📒 Files selected for processing (5)
conf/models/openai-api-compatible.jsoninternal/entity/models/factory.gointernal/entity/models/openai_api_compatible.gointernal/handler/providers.gointernal/service/model_service.go
wangq8
left a comment
There was a problem hiding this comment.
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)
InferModelTypeschecks rerank before embedding, which correctly handles models named likebge-reranker-v2that match both hint sets. Good.ttsVoiceForModelfor cosyvoice returnsmodelName + ":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/verifyProviderModelsignature change from[]stringto[]CheckConnectionModelInfois internally consistent — both call sites inproviders.goare updated, and thenilpath 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.
Summary
Go: add OpenAI‑API‑compatible model provider.