Repository navigation
Go: implement provider: PaddleOCR_Local - #15158
Conversation
📝 WalkthroughWalkthroughThis PR adds local PaddleOCR model support to the model factory system, corrects endpoint naming in Gitee embeddings, updates display names for consistency, fixes type formatting in TogetherAI configuration, extends Zhipu-AI with model and OCR endpoints, and implements a complete OCRFile method with base64-encoded payload handling and result text extraction. ChangesLocal PaddleOCR Model Support and Model Configuration Updates
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
🚥 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: 2
🤖 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 `@conf/models/zhipu-ai.json`:
- Around line 273-277: Remove the duplicate "glm-ocr" entry from the models
array: locate the second occurrence of the object whose "name" is "glm-ocr" in
the models JSON and delete that object so each model name is unique (leave the
original/first "glm-ocr" definition intact).
In `@internal/entity/models/paddleocr_local.go`:
- Around line 119-125: The current logic uses "if ... else if" so when fileURL
is present but doesn't end with ".pdf" you never check the content signature;
change to check both independently so a PDF identified by content will set
fileType even if fileURL is non-empty. Specifically, in the block using
fileType, fileURL, content and strings.HasSuffix, replace the "if ... else if"
with two independent checks: one that sets fileType=0 when fileURL
(non-nil/non-empty) ends with ".pdf" and a separate check that sets fileType=0
when len(content)>4 && string(content[:4])=="%PDF".
🪄 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: 14259826-b1bd-466c-9728-52bef332128d
📒 Files selected for processing (7)
conf/models/gitee.jsonconf/models/mineru_local.jsonconf/models/paddleocr_local.jsonconf/models/togetherai.jsonconf/models/zhipu-ai.jsoninternal/entity/models/factory.gointernal/entity/models/paddleocr_local.go
| { | ||
| "name": "glm-ocr", | ||
| "model_types": [ | ||
| "ocr" | ||
| ] |
There was a problem hiding this comment.
Remove duplicate glm-ocr model entry.
glm-ocr is already defined earlier in the same models array, so this adds a duplicate entry.
Proposed fix
- {
- "name": "glm-ocr",
- "model_types": [
- "ocr"
- ]
- }🤖 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 `@conf/models/zhipu-ai.json` around lines 273 - 277, Remove the duplicate
"glm-ocr" entry from the models array: locate the second occurrence of the
object whose "name" is "glm-ocr" in the models JSON and delete that object so
each model name is unique (leave the original/first "glm-ocr" definition
intact).
| if fileURL != nil && *fileURL != "" { | ||
| if strings.HasSuffix(strings.ToLower(*fileURL), ".pdf") { | ||
| fileType = 0 | ||
| } | ||
| } else if len(content) > 4 && string(content[:4]) == "%PDF" { | ||
| fileType = 0 | ||
| } |
There was a problem hiding this comment.
fileType inference misses PDF-by-content when fileURL is present.
With the current if ... else if, any non-empty fileURL that doesn’t end in .pdf skips signature detection, so real PDFs can be sent as image type.
Proposed fix
fileType := 1
-if fileURL != nil && *fileURL != "" {
- if strings.HasSuffix(strings.ToLower(*fileURL), ".pdf") {
- fileType = 0
- }
-} else if len(content) > 4 && string(content[:4]) == "%PDF" {
- fileType = 0
-}
+if len(content) >= 4 && string(content[:4]) == "%PDF" {
+ fileType = 0
+} else if fileURL != nil && *fileURL != "" && strings.HasSuffix(strings.ToLower(*fileURL), ".pdf") {
+ fileType = 0
+}📝 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.
| if fileURL != nil && *fileURL != "" { | |
| if strings.HasSuffix(strings.ToLower(*fileURL), ".pdf") { | |
| fileType = 0 | |
| } | |
| } else if len(content) > 4 && string(content[:4]) == "%PDF" { | |
| fileType = 0 | |
| } | |
| fileType := 1 | |
| if len(content) >= 4 && string(content[:4]) == "%PDF" { | |
| fileType = 0 | |
| } else if fileURL != nil && *fileURL != "" && strings.HasSuffix(strings.ToLower(*fileURL), ".pdf") { | |
| fileType = 0 | |
| } |
🤖 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/paddleocr_local.go` around lines 119 - 125, The
current logic uses "if ... else if" so when fileURL is present but doesn't end
with ".pdf" you never check the content signature; change to check both
independently so a PDF identified by content will set fileType even if fileURL
is non-empty. Specifically, in the block using fileType, fileURL, content and
strings.HasSuffix, replace the "if ... else if" with two independent checks: one
that sets fileType=0 when fileURL (non-nil/non-empty) ends with ".pdf" and a
separate check that sets fileType=0 when len(content)>4 &&
string(content[:4])=="%PDF".
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15158 +/- ##
=======================================
Coverage 93.12% 93.12%
=======================================
Files 10 10
Lines 713 713
Branches 116 116
=======================================
Hits 664 664
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Nice work on the PaddleOCR_Local provider — having a local OCR option that doesn't require external API calls is a big deal for document-heavy workflows where data stays on-prem. A few thoughts from our experience building OCR pipelines for legal document processing:
The CLI verification approach is solid — having a way to quickly test OCR output against known documents is invaluable for regression testing when upgrading the OCR engine version. |
What problem does this PR solve?
Go: implement provider: PaddleOCR_Local
Verified from CLI
Type of change