Align Go parser backends and PDF pipeline with Python (#16676)

Ports remaining Go parser wiring and PDF backends, adds tenant-aware VLM
dispatch, aligns post-processing with Python, and adds end-to-end
pipeline coverage with a generated six-page PDF.
This commit is contained in:
Zhichang Yu
2026-07-06 19:50:54 +08:00
committed by GitHub
parent 3044283442
commit 55af1d70f3
36 changed files with 4918 additions and 28 deletions

View File

@@ -0,0 +1,62 @@
package parser
import (
"fmt"
"os"
"strings"
models "ragflow/internal/entity/models"
)
func parsePDFWithPaddleOCR(filename string, data []byte, parser *PDFParser) ParseResult {
if len(data) == 0 {
return emptyPDFResult(filename)
}
baseURL := strings.TrimSpace(parser.PaddleOCRBaseURL)
if baseURL == "" {
baseURL = strings.TrimSpace(os.Getenv("PADDLEOCR_BASE_URL"))
}
if baseURL == "" {
baseURL = strings.TrimSpace(os.Getenv("PADDLEOCR_API_URL"))
}
if baseURL == "" {
return ParseResult{Err: fmt.Errorf("parser: PaddleOCR requires paddleocr_base_url or PADDLEOCR_BASE_URL")}
}
apiKey := parser.PaddleOCRAPIKey
if strings.TrimSpace(apiKey) == "" {
apiKey = strings.TrimSpace(os.Getenv("PADDLEOCR_ACCESS_TOKEN"))
}
algorithm := strings.TrimSpace(parser.PaddleOCRAlgorithm)
if algorithm == "" {
algorithm = strings.TrimSpace(os.Getenv("PADDLEOCR_ALGORITHM"))
}
if algorithm == "" {
algorithm = "PaddleOCR-VL"
}
driver := models.NewPaddleOCRLocalModel(
map[string]string{"default": baseURL},
models.URLSuffix{OCR: "layout-parsing"},
)
apiConfig := &models.APIConfig{
BaseURL: &baseURL,
}
if apiKey != "" {
apiConfig.ApiKey = &apiKey
}
resp, err := driver.OCRFile(&algorithm, data, &filename, apiConfig, &models.OCRConfig{
Algorithm: algorithm,
})
if err != nil {
return ParseResult{Err: fmt.Errorf("parser: PaddleOCR OCRFile: %w", err)}
}
if resp == nil || resp.Text == nil {
return ParseResult{Err: fmt.Errorf("parser: PaddleOCR returned empty text")}
}
pageCount := 1
if resp.Text != nil && strings.TrimSpace(*resp.Text) == "" {
pageCount = 0
}
return parseMinerUMarkdownResult(filename, *resp.Text, parser.OutputFormat, pageCount)
}