mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-26 02:13:29 +08:00
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:
62
internal/parser/parser/pdf_parser_paddleocr.go
Normal file
62
internal/parser/parser/pdf_parser_paddleocr.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user