Repository navigation
Go: implement provider: CometAPI - #14930
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a CometAPI provider to the Go model layer: non-streaming and SSE streaming chat, embeddings with index reordering/validation, model listing, balance/check connection, factory routing, configuration, and comprehensive tests. ChangesCometAPI Model Driver
Sequence Diagram(s)sequenceDiagram
participant Client
participant CometAPIModel
participant CometAPI
participant Sender
Client->>CometAPIModel: ChatStreamlyWithSender(model,messages,apiConfig,chatConfig,sender)
CometAPIModel->>CometAPI: POST /v1/chat (stream:true, model,messages,params)
CometAPI-->>CometAPIModel: SSE data: {"delta":{"reasoning_delta"/"content_delta"}}
CometAPIModel->>Sender: emit reasoning_delta / content_delta
CometAPI-->>CometAPIModel: [DONE] or finish_reason
CometAPIModel->>Sender: emit "[DONE]" sentinel
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
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/cometapi.go`:
- Around line 119-123: Add a local validation that returns a clear error when
modelName is empty before making any remote chat call: in
CometAPIModel.ChatWithMessages (and the analogous chat method around lines
239-250, e.g., ChatWithMessage/ChatWithHistory), check if
strings.TrimSpace(modelName) == "" and return fmt.Errorf("model name is
required") (or similar) instead of proceeding; update both function entry points
(ChatWithMessages and the other chat method reference) so empty or
all-whitespace modelName fails fast.
🪄 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: 89328436-b8a2-4a6a-8280-96750fb51957
📒 Files selected for processing (4)
conf/models/cometapi.jsoninternal/entity/models/cometapi.gointernal/entity/models/cometapi_test.gointernal/entity/models/factory.go
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
internal/entity/models/cometapi.go (1)
637-657: 💤 Low valueReceiver name inconsistency in the unsupported-capability stubs.
All other methods on
*CometAPIModeluse receiverm, butTranscribeAudio,TranscribeAudioWithSender,AudioSpeech,AudioSpeechWithSender, andOCRFileusez. This looks like a copy-paste leftover from another provider (e.g., azhipu-style driver) and breaks the consistency conventiongofmt/go vet-adjacent tooling tends to flag.♻️ Proposed fix
-func (z *CometAPIModel) TranscribeAudio(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig) (*ASRResponse, error) { - return nil, fmt.Errorf("%s, no such method", z.Name()) +func (m *CometAPIModel) TranscribeAudio(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig) (*ASRResponse, error) { + return nil, fmt.Errorf("%s, no such method", m.Name()) } -func (z *CometAPIModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) +func (m *CometAPIModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error { + return fmt.Errorf("%s, no such method", m.Name()) } -// AudioSpeech convert audio to text -func (z *CometAPIModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) { - return nil, fmt.Errorf("%s, no such method", z.Name()) +func (m *CometAPIModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, asrConfig *TTSConfig) (*TTSResponse, error) { + return nil, fmt.Errorf("%s, no such method", m.Name()) } -func (z *CometAPIModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { - return fmt.Errorf("%s, no such method", z.Name()) +func (m *CometAPIModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error { + return fmt.Errorf("%s, no such method", m.Name()) } -// OCRFile OCR file -func (z *CometAPIModel) OCRFile(modelName *string, content []byte, url *string, apiConfig *APIConfig, ocrConfig *OCRConfig) (*OCRResponse, error) { - return nil, fmt.Errorf("%s, no such method", z.Name()) +func (m *CometAPIModel) OCRFile(modelName *string, content []byte, url *string, apiConfig *APIConfig, ocrConfig *OCRConfig) (*OCRResponse, error) { + return nil, fmt.Errorf("%s, no such method", m.Name()) }🤖 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/cometapi.go` around lines 637 - 657, The stub methods TranscribeAudio, TranscribeAudioWithSender, AudioSpeech, AudioSpeechWithSender, and OCRFile on type *CometAPIModel use receiver name `z` but the rest of the type’s methods use `m`; change the receiver identifier in each of those method signatures from `z` to `m` so they match the existing convention (e.g., func (m *CometAPIModel) TranscribeAudio(...)), leaving bodies and returned errors unchanged.
🤖 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/cometapi.go`:
- Line 645: The doc comment for AudioSpeech is incorrect: it describes
audio-to-text but AudioSpeech implements text-to-speech (TTS); update the
comment on the AudioSpeech declaration to clearly state it converts text to
audio (TTS) and not speech-to-text, and if helpful contrast it with
TranscribeAudio (which is the audio-to-text stub) so readers won't confuse the
two.
- Around line 398-401: The assembled-answer logic must ignore the "[DONE]"
sentinel before concatenating; update the service-layer callback that builds
fullAnswer (the block at chat_session.go where it checks if answer != nil &&
*answer != "") to also skip when *answer == "[DONE]". Locate the concatenation
site that references fullAnswer and the callback passed to sender, and change
the condition to require *answer != "" AND *answer != "[DONE]" (or explicitly
return early when *answer == "[DONE]") so the literal sentinel is never
appended.
---
Nitpick comments:
In `@internal/entity/models/cometapi.go`:
- Around line 637-657: The stub methods TranscribeAudio,
TranscribeAudioWithSender, AudioSpeech, AudioSpeechWithSender, and OCRFile on
type *CometAPIModel use receiver name `z` but the rest of the type’s methods use
`m`; change the receiver identifier in each of those method signatures from `z`
to `m` so they match the existing convention (e.g., func (m *CometAPIModel)
TranscribeAudio(...)), leaving bodies and returned errors unchanged.
🪄 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: 0e482a4d-952f-4178-b37f-a9ad30fea7a4
📒 Files selected for processing (2)
internal/entity/models/cometapi.gointernal/entity/models/cometapi_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/entity/models/cometapi_test.go
|
Live CometAPI test result (2026-05-14 UTC) Ran a temporary build-tagged live test against CometAPI with a real API key. The live matrix covered every CometAPI driver method and every model currently configured in Passed method coverage:
Configured chat model results:
Configured embedding model results:
Local regression checks also passed:
|
d93808e to
a6bef6f
Compare
…n be alert (infiniflow#487) …e alert ### What problem does this PR solve? .doc file is not support yet, fix the regular expression ,then right message can by alert ### Type of change - [ ] Bug Fix : issule: 474
### What problem does this PR solve? ### Type of change - [x] Refactoring
…iniflow#1678) Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.4 to 1.15.6. <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/follow-redirects/follow-redirects/commit/35a517c5861d79dc8bff7db8626013d20b711b06"><code>35a517c</code></a> Release version 1.15.6 of the npm package.</li> <li><a href="https://github.com/follow-redirects/follow-redirects/commit/c4f847f85176991f95ab9c88af63b1294de8649b"><code>c4f847f</code></a> Drop Proxy-Authorization across hosts.</li> <li><a href="https://github.com/follow-redirects/follow-redirects/commit/8526b4a1b2ab3a2e4044299377df623a661caa76"><code>8526b4a</code></a> Use GitHub for disclosure.</li> <li><a href="https://github.com/follow-redirects/follow-redirects/commit/b1677ce00110ee50dc5da576751d39b281fc4944"><code>b1677ce</code></a> Release version 1.15.5 of the npm package.</li> <li><a href="https://github.com/follow-redirects/follow-redirects/commit/d8914f7982403ea096b39bd594a00ee9d3b7e224"><code>d8914f7</code></a> Preserve fragment in responseUrl.</li> <li>See full diff in <a href="https://github.com/follow-redirects/follow-redirects/compare/v1.15.4...v1.15.6">compare view</a></li> </ul> </details> <br /> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/infiniflow/ragflow/network/alerts). </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…ature' (infiniflow#4601) `graphrag/search.py`中`search`方法缺少参数`rank_feature` Co-authored-by: xubh <[email protected]> Co-authored-by: Kevin Hu <[email protected]>
### What problem does this PR solve? Use infinity 0.6.0 ### Type of change - [x] Documentation Update Signed-off-by: Jin Hai <[email protected]>
…12931) ### What problem does this PR solve? close infiniflow#12930 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Changes only delete duplicate definition in `api/db/db_models.py`
…2933) ### What problem does this PR solve? Fixed the regression issue that unable to start the server as below details, which was related to this pr infiniflow#12926 looks like. ``` Error Trace Traceback (most recent call last): File "/mnt/c/Workspace/ragflow/api/ragflow_server.py", line 33, in <module> from api.apps import app File "/mnt/c/Workspace/ragflow/api/apps/__init__.py", line 26, in <module> Traceback (most recent call last): File "/mnt/c/Workspace/ragflow/rag/svr/task_executor.py", line 34, in <module> from api.db.db_models import close_connection, APIToken File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 49, in <module> from api.db.services.knowledgebase_service import KnowledgebaseService File "/mnt/c/Workspace/ragflow/api/db/services/__init__.py", line 19, in <module> class TextFieldType(Enum): File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 53, in TextFieldType from .user_service import UserService as UserService File "/mnt/c/Workspace/ragflow/api/db/services/user_service.py", line 24, in <module> POSTGRES = "TEXT" ^^^^^^^^ File "/usr/lib/python3.12/enum.py", line 443, in __setitem__ raise TypeError('%r already defined as %r' % (key, self[key])) TypeError: 'POSTGRES' already defined as 'TEXT' from api.db.db_models import DB, UserTenant File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 49, in <module> class TextFieldType(Enum): File "/mnt/c/Workspace/ragflow/api/db/db_models.py", line 53, in TextFieldType POSTGRES = "TEXT" ^^^^^^^^ File "/usr/lib/python3.12/enum.py", line 443, in __setitem__ raise TypeError('%r already defined as %r' % (key, self[key])) TypeError: 'POSTGRES' already defined as 'TEXT' ``` ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
…finiflow#12936) ### What problem does this PR solve? Fixes a duplicate POSTGRES entry in the TextFieldType enum that triggers TypeError: 'POSTGRES' already defined as 'TEXT' on import, preventing the backend from starting and resulting in 502 errors on the frontend. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
…sets" for clarity (infiniflow#12967) ### What problem does this PR solve? Update HTTP API reference to rename "total" field to ### Type of change - [x] Bug Fix infiniflow#12963 Co-authored-by: Yun.kou <[email protected]>
…iflow#13051) ## Problem RAGFlow was using incorrect model names for Google Gemini embeddings: - `embedding-001` (missing `gemini-` prefix) - `text-embedding-004` (OpenAI model name, not Gemini) This caused API errors when users tried to use Gemini embeddings. ## Solution - Updated `conf/llm_factories.json` to use the correct model name: `gemini-embedding-001` - Removed the incorrect `text-embedding-004` entry - Added volume mount in `docker-compose.yml` to ensure config changes persist ## Testing Tested with a valid Gemini API key and confirmed embeddings now work correctly. ## Changes - Modified `conf/llm_factories.json` - Modified `docker/docker-compose.yml` --------- Co-authored-by: Ahmad Intisar <[email protected]> Co-authored-by: Kevin Hu <[email protected]>
### What problem does this PR solve? Refactor: i18n language pack for on-demand import ### Type of change - [x] Refactoring Co-authored-by: Kevin Hu <[email protected]>
…ing wrong tenant model lookup (infiniflow#13782) Summary When setting a default model for an OpenAI-API-Compatible provider, ensure_tenant_model_id_for_params called get_api_key without a model_type filter. If the same model name was registered under multiple types (e.g., both chat and embedding), it could return the wrong tenant_llm_id, leading to Model(@None) not authorized errors during chat. This applies the same type-scoped fix that PR infiniflow#13569 introduced in get_model_config_by_type_and_name — now consistently in tenant_utils.py as well. Changes - Added _KEY_TO_MODEL_TYPE mapping in tenant_utils.py - Each model key (llm_id, embd_id, etc.) now passes its correct LLMType to get_api_key Fixes infiniflow#13775
…t crash (infiniflow#13951) Fixes infiniflow#13851 ## Problem `OCR.detect()` in `deepdoc/vision/ocr.py` returns `None, None, time_dict` (a truthy 3-tuple) when the text detector fails or receives a `None` image. However, the caller in `pdf_parser.py:__ocr()` checks: ```python bxs = self.ocr.detect(np.array(img), device_id) if not bxs: # False! (None, None, time_dict) is a non-empty tuple → truthy self.boxes.append([]) return bxs = [(line[0], line[1][0]) for line in bxs] # iterates (None, None, time_dict) # line = None → None[0] → TypeError: 'NoneType' object is not subscriptable ``` This causes the `NoneType object is not subscriptable` error that appears after "OCR started" in the chunking pipeline when using PDF + General parser. ## Solution Simplified `OCR.detect()` to return `None` (falsy) instead of `None, None, time_dict` on failure. The `time_dict` was unused by the only caller of this method. The early-return guard `if not bxs:` in `pdf_parser.py` then correctly catches it. ## Testing - The method's only caller (`pdf_parser.py:__ocr`) already has a `if not bxs:` guard that handles the `None` return correctly. - No other callers of `OCR.detect()` exist in the codebase. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Modified OCR detection function return behavior to streamline output. The function now returns detection results only, without timing metadata. Error cases now return `None` instead of empty tuple values. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…ow#13838) Fixes infiniflow#13817 ### What problem does this PR solve? The "knowledge graph construction" link on line 21 of `docs/guides/dataset/run_retrieval_test.md` points to `./construct_knowledge_graph.md`, which doesn't exist. The actual file is at `./advanced/construct_knowledge_graph.md`. ### Type of change - [x] Documentation Update Signed-off-by: majiayu000 <[email protected]>
a6bef6f to
332033d
Compare
Haruko386
left a comment
There was a problem hiding this comment.
Hi @tmimmanuel, All tests are passed
Do a small change plz.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14930 +/- ##
=======================================
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. 🚀 New features to boost your workflow:
|
|
@JinHai-CN |
What problem does this PR solve?
Adds the Go model provider driver for CometAPI, which is listed as unchecked in the Go provider tracking issue #14736 and requested in #14804. Without this, the Go layer falls back to the dummy driver for the
cometapiprovider.Fixes #14804
What this PR includes
internal/entity/models/cometapi.goimplementingModelDriverfor CometAPI.conf/models/cometapi.jsonwith CometAPI base URLs and representative chat / embedding models from the public catalog.factory.go: route"cometapi"toNewCometAPIModel.internal/entity/models/cometapi_test.go.Method coverage
ChatWithMessages:POST /v1/chat/completions.ChatStreamlyWithSender: SSE streaming on the same endpoint.Embed:POST /v1/embeddings, including optionaldimensions.ListModels:GET /api/modelspublic catalog.Balance:GET https://query.cometapi.com/user/quota?key=....CheckConnection: delegates to the quota query to verify the key.Rerank, ASR, TTS, OCR: returnno such methodfor now.No ModelDriver interface change. No new dependencies.
How was this tested?