Skip to content

Go: implement provider: MinerU - #14990

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
Haruko386:main
May 19, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
Haruko386:main

Conversation

@Haruko386

Copy link
Copy Markdown
Member

What problem does this PR solve?

Implement MinerU Provider

The following functionalities are now supported:

MinerU

  • Parse file
  • Show task
  • List tasks

Verified examples from the CLI:

RAGFlow(user)> parse with 'vlm@test@mineru' file 'https://arxiv.org/pdf/2505.09358'
+--------------------------------------+
| task_id                              |
+--------------------------------------+
| 142ac8ea-d9d0-4a68-a2d1-d3af67635dc9 |
+--------------------------------------+

RAGFlow(user)> show 'test@mineru' task '142ac8ea-d9d0-4a68-a2d1-d3af67635dc9'
+--------------------------------------------+-------+
| content                                    | index |
+--------------------------------------------+-------+
| Task is running... Progress: 17 / 18 pages | 0     |
+--------------------------------------------+-------+

RAGFlow(user)> show 'test@mineru' task '142ac8ea-d9d0-4a68-a2d1-d3af67635dc9'
+--------------------------------------------------------------------------------------------+-------+
| content                                                                                    | index |
+--------------------------------------------------------------------------------------------+-------+
| https://cdn-mineru.openxlab.org.cn/pdf/2026-05-18/142ac8ea-d9d0-4a68-a2d1-d3af67635dc9.zip | 0     |
+--------------------------------------------------------------------------------------------+-------+

Type of change

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

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

coderabbitai Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR integrates a new MinerU document parsing model provider, updates model configurations for naming consistency and URL structure, implements the MinerU model driver with document submission and task polling, adds URL detection to file input handling in the CLI, and fixes region validation in Gitee model methods.

Changes

MinerU Model Provider Integration

Layer / File(s) Summary
Model Configuration Setup
conf/models/baidu.json, conf/models/xunfei.json, conf/models/mineru.json
Renames Baidu's "Name" key to "name" for consistency; restructures XunFei URL to separate base URL and path suffix; adds new MinerU provider configuration with default base URL (https://mineru.net) and doc_parse endpoint mapping, registering two model variants.
Type Contracts and Factory Routing
internal/entity/models/types.go, internal/entity/models/factory.go
ParseFileResponse now includes a TaskID field to carry task identifiers from parse API responses; factory's CreateModelDriver adds case for "mineru" provider to instantiate NewMinerUModel.
MinerU Model Driver Implementation
internal/entity/models/mineru.go
Introduces MinerUModel with region-based base URLs and configured HTTP client; implements ParseFile to validate document URL and API key, POST to MinerU endpoint, extract task ID from response, and return ParseFileResponse; implements ShowTask to poll task status via GET, check for failures, and map state transitions to result content or progress messages; provides stub methods for chat, embeddings, rerank, transcription, TTS, OCR, and other unsupported operations.
URL Detection in File Input
internal/cli/user_command.go
ParseFileUserCommand now detects http:// and https:// prefixes in the file parameter and treats them as document URLs; non-prefixed paths are read from the local filesystem.
Gitee Region Validation
internal/entity/models/gitee.go
ListModels, Balance, ListTasks, and ShowTask methods now validate that apiConfig.Region is non-nil and non-empty before using it to override the default region in URL construction, preventing empty-string region values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • infiniflow/ragflow#14336: Both PRs extend internal/entity/models/factory.go to route new model provider names in CreateModelDriver.
  • infiniflow/ragflow#14741: Both PRs modify the Baidu provider configuration key in conf/models/baidu.json.
  • infiniflow/ragflow#14892: Both PRs introduce document parsing task submission and task response types in ParseFileUserCommand and ParseFileResponse.

Suggested labels

💞 feature, size:XXL

Poem

🐰 A MinerU model hops in with grace,
URLs parse without a trace,
Tasks submit and query true,
Gitee regions now validated too,
Document parsing dreams come true!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 'Go: implement provider: MinerU' clearly and specifically describes the main change—implementing a new MinerU provider in the Go codebase.
Description check ✅ Passed The description follows the template, identifies the problem solved (implementing MinerU provider), lists supported features with checkmarks, provides verified CLI examples, and specifies applicable change types.
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.

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

@Haruko386 Haruko386 added the ci Continue Integration label May 19, 2026
@Haruko386
Haruko386 marked this pull request as draft May 19, 2026 01:46
@Haruko386
Haruko386 marked this pull request as ready for review May 19, 2026 01:46

@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/entity/models/gitee.go (1)

988-991: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Apply the same empty-string validation for consistency.

The CheckConnection method currently only checks if apiConfig.Region is non-nil, but doesn't validate against empty strings. This is now inconsistent with the four methods fixed in this PR (ListModels, Balance, ListTasks, ShowTask) and six other methods in this file that already perform both checks.

🔧 Apply consistent validation
 var region = "default"
-if apiConfig.Region != nil {
+if apiConfig.Region != nil && *apiConfig.Region != "" {
     region = *apiConfig.Region
 }
🤖 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/gitee.go` around lines 988 - 991, The CheckConnection
method currently sets region if apiConfig.Region is non-nil but doesn't guard
against empty strings; update the region extraction in CheckConnection to only
use apiConfig.Region when apiConfig.Region != nil && *apiConfig.Region != ""
(otherwise keep "default"), mirroring the validation already applied in
ListModels, Balance, ListTasks, and ShowTask; locate the logic around the region
variable and apiConfig.Region in the CheckConnection function and apply the same
non-nil AND non-empty check so behavior is consistent across methods.
🤖 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/mineru.go`:
- Around line 120-126: When building MinerU URLs, guard against apiConfig.Region
values that are non-empty but not present in the m.BaseURL map: check if
apiConfig.Region is nil or empty or if *apiConfig.Region is not a key in
m.BaseURL and fallback to the "default" region before using m.BaseURL[region];
update the URL construction sites (e.g., where apiURL is built using
m.BaseURL[region] and m.URLSuffix.DocumentParse and the analogous block used by
ShowTask and ParseFile) to perform this key-existence check so you never index
m.BaseURL with an unknown key.
- Around line 168-174: ParseFile currently treats any non-error code as success
even when taskResp.Data.TaskID is empty; update ParseFile to validate
taskResp.Data.TaskID (from the taskResp variable) after the code check and
return an error (e.g., fmt.Errorf with a clear message) if it's empty instead of
returning a ParseFileResponse with an empty TaskID so downstream "show task"
flows don't fail. Ensure the check happens before constructing and returning the
ParseFileResponse.

---

Outside diff comments:
In `@internal/entity/models/gitee.go`:
- Around line 988-991: The CheckConnection method currently sets region if
apiConfig.Region is non-nil but doesn't guard against empty strings; update the
region extraction in CheckConnection to only use apiConfig.Region when
apiConfig.Region != nil && *apiConfig.Region != "" (otherwise keep "default"),
mirroring the validation already applied in ListModels, Balance, ListTasks, and
ShowTask; locate the logic around the region variable and apiConfig.Region in
the CheckConnection function and apply the same non-nil AND non-empty check so
behavior is consistent across methods.
🪄 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: 0a913b6c-c882-48a1-878b-b468efad3151

📥 Commits

Reviewing files that changed from the base of the PR and between 41a9fc0 and 7300140.

📒 Files selected for processing (8)
  • conf/models/baidu.json
  • conf/models/mineru.json
  • conf/models/xunfei.json
  • internal/cli/user_command.go
  • internal/entity/models/factory.go
  • internal/entity/models/gitee.go
  • internal/entity/models/mineru.go
  • internal/entity/models/types.go

Comment on lines +120 to +126
var region = "default"
if apiConfig.Region != nil && *apiConfig.Region != "" {
region = *apiConfig.Region
}

apiURL := fmt.Sprintf("%s/api/%s", m.BaseURL[region], m.URLSuffix.DocumentParse)

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Handle unknown region keys before building MinerU URLs.

If apiConfig.Region is non-empty but not present in m.BaseURL, URL construction uses an empty base and request creation fails with an invalid URL in both ParseFile and ShowTask.

🔧 Proposed fix
+func (m *MinerUModel) resolveBaseURL(apiConfig *APIConfig) (string, error) {
+	region := "default"
+	if apiConfig != nil && apiConfig.Region != nil && *apiConfig.Region != "" {
+		region = *apiConfig.Region
+	}
+	if base, ok := m.BaseURL[region]; ok && base != "" {
+		return base, nil
+	}
+	if base, ok := m.BaseURL["default"]; ok && base != "" {
+		return base, nil
+	}
+	return "", fmt.Errorf("invalid MinerU region: %s", region)
+}
+
 func (m *MinerUModel) ParseFile(modelName *string, content []byte, documentURL *string, apiConfig *APIConfig, parseFileConfig *ParseFileConfig) (*ParseFileResponse, error) {
@@
-	var region = "default"
-	if apiConfig.Region != nil && *apiConfig.Region != "" {
-		region = *apiConfig.Region
-	}
-
-	apiURL := fmt.Sprintf("%s/api/%s", m.BaseURL[region], m.URLSuffix.DocumentParse)
+	baseURL, err := m.resolveBaseURL(apiConfig)
+	if err != nil {
+		return nil, err
+	}
+	apiURL := fmt.Sprintf("%s/api/%s", baseURL, m.URLSuffix.DocumentParse)
@@
 func (m *MinerUModel) ShowTask(taskID string, apiConfig *APIConfig) (*TaskResponse, error) {
@@
-	var region = "default"
-	if apiConfig.Region != nil && *apiConfig.Region != "" {
-		region = *apiConfig.Region
-	}
-
-	// URL: https://mineru.net/api/v4/extract/task/{task_id}
-	apiURL := fmt.Sprintf("%s/api/%s/%s", m.BaseURL[region], m.URLSuffix.DocumentParse, taskID)
+	baseURL, err := m.resolveBaseURL(apiConfig)
+	if err != nil {
+		return nil, err
+	}
+	// URL: https://mineru.net/api/v4/extract/task/{task_id}
+	apiURL := fmt.Sprintf("%s/api/%s/%s", baseURL, m.URLSuffix.DocumentParse, taskID)

Also applies to: 201-207

🤖 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/mineru.go` around lines 120 - 126, When building
MinerU URLs, guard against apiConfig.Region values that are non-empty but not
present in the m.BaseURL map: check if apiConfig.Region is nil or empty or if
*apiConfig.Region is not a key in m.BaseURL and fallback to the "default" region
before using m.BaseURL[region]; update the URL construction sites (e.g., where
apiURL is built using m.BaseURL[region] and m.URLSuffix.DocumentParse and the
analogous block used by ShowTask and ParseFile) to perform this key-existence
check so you never index m.BaseURL with an unknown key.

Comment on lines +168 to +174
if taskResp.Code != 0 {
return nil, fmt.Errorf("MinerU task creation failed (code %d): %s", taskResp.Code, taskResp.Msg)
}

return &ParseFileResponse{
TaskID: taskResp.Data.TaskID,
}, nil

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Reject empty task_id in parse success responses.

ParseFile currently returns success even when task_id is empty, which will fail follow-up show task flows.

🔧 Proposed fix
 	if taskResp.Code != 0 {
 		return nil, fmt.Errorf("MinerU task creation failed (code %d): %s", taskResp.Code, taskResp.Msg)
 	}
+	if taskResp.Data.TaskID == "" {
+		return nil, fmt.Errorf("MinerU task creation succeeded but task_id is empty")
+	}
 
 	return &ParseFileResponse{
 		TaskID: taskResp.Data.TaskID,
 	}, nil
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if taskResp.Code != 0 {
return nil, fmt.Errorf("MinerU task creation failed (code %d): %s", taskResp.Code, taskResp.Msg)
}
return &ParseFileResponse{
TaskID: taskResp.Data.TaskID,
}, nil
if taskResp.Code != 0 {
return nil, fmt.Errorf("MinerU task creation failed (code %d): %s", taskResp.Code, taskResp.Msg)
}
if taskResp.Data.TaskID == "" {
return nil, fmt.Errorf("MinerU task creation succeeded but task_id is empty")
}
return &ParseFileResponse{
TaskID: taskResp.Data.TaskID,
}, 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/mineru.go` around lines 168 - 174, ParseFile currently
treats any non-error code as success even when taskResp.Data.TaskID is empty;
update ParseFile to validate taskResp.Data.TaskID (from the taskResp variable)
after the code check and return an error (e.g., fmt.Errorf with a clear message)
if it's empty instead of returning a ParseFileResponse with an empty TaskID so
downstream "show task" flows don't fail. Ensure the check happens before
constructing and returning the ParseFileResponse.

@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 (41a9fc0) to head (7300140).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14990      +/-   ##
==========================================
- Coverage   95.59%   94.16%   -1.43%     
==========================================
  Files          10       10              
  Lines         703      703              
  Branches      112      112              
==========================================
- Hits          672      662      -10     
- Misses         21       25       +4     
- Partials       10       16       +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 db9e782 into infiniflow:main May 19, 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.

2 participants