Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix(go): PaddleOCR -> PaddleOCR.local, PaddleOCR.net -> PaddleOCR (#18747)

Lynn45a47d9d456c
diff --git a/conf/models/paddleocr.json b/conf/models/paddleocr.json
index db36267a40..249b5e2c36 100644
--- a/conf/models/paddleocr.json
+++ b/conf/models/paddleocr.json
@@ -1,12 +1,12 @@
{
- "name": "PaddleOCR.Net",
+ "name": "PaddleOCR",
"url": {
"default": "https://paddleocr.aistudio-app.com/api"
},
"url_suffix": {
"ocr": "v2/ocr/jobs"
},
- "class": "paddleocr.net",
+ "class": "paddleocr",
"models": [
{
"name": "PaddleOCR-VL-1.6",
diff --git a/conf/models/paddleocr_local.json b/conf/models/paddleocr_local.json
index f1bf1a1375..6efda9a5e2 100644
--- a/conf/models/paddleocr_local.json
+++ b/conf/models/paddleocr_local.json
@@ -1,7 +1,44 @@
{
- "name": "PaddleOCR",
+ "name": "PaddleOCR.local",
"url_suffix": {
"ocr": "layout-parsing"
},
- "class": "local"
-}
\ No newline at end of file
+ "class": "local",
+ "models": [
+ {
+ "name": "PaddleOCR-VL-1.6",
+ "max_tokens": 16384,
+ "model_types": [
+ "ocr"
+ ]
+ },
+ {
+ "name": "PaddleOCR-VL-1.5",
+ "max_tokens": 16384,
+ "model_types": [
+ "ocr"
+ ]
+ },
+ {
+ "name": "PP-OCRv6",
+ "max_tokens": 16384,
+ "model_types": [
+ "ocr"
+ ]
+ },
+ {
+ "name": "PP-OCRv5",
+ "max_tokens": 16384,
+ "model_types": [
+ "ocr"
+ ]
+ },
+ {
+ "name": "PP-StructureV3",
+ "max_tokens": 16384,
+ "model_types": [
+ "ocr"
+ ]
+ }
+ ]
+}
diff --git a/internal/entity/models/factory.go b/internal/entity/models/factory.go
index 87ab9a1ef2..66ffbb8bc9 100644
--- a/internal/entity/models/factory.go
+++ b/internal/entity/models/factory.go
@@ -125,7 +125,7 @@ func (f *ModelFactory) CreateModelDriver(providerName string, baseURL map[string
return NewPPIOModel(baseURL, urlSuffix), nil
case "voyage ai":
return NewVoyageModel(baseURL, urlSuffix), nil
- case "paddleocr.net":
+ case "paddleocr":
return NewPaddleOCRModel(baseURL, urlSuffix), nil
case "xunfei spark":
return NewXunFeiModel(baseURL, urlSuffix), nil
@@ -149,7 +149,7 @@ func (f *ModelFactory) CreateModelDriver(providerName string, baseURL map[string
return NewN1NModel(baseURL, urlSuffix), nil
case "bedrock":
return NewBedrockModel(baseURL, urlSuffix), nil
- case "paddleocr":
+ case "paddleocr.local":
return NewPaddleOCRLocalModel(baseURL, urlSuffix), nil
case "orcarouter":
return NewOrcaRouterModel(baseURL, urlSuffix), nil
diff --git a/internal/entity/models/model_test.go b/internal/entity/models/model_test.go
index 8e703840b7..1e1d12e522 100644
--- a/internal/entity/models/model_test.go
+++ b/internal/entity/models/model_test.go
@@ -118,18 +118,18 @@ func TestHostedProviderConfigsLoadSharedDrivers(t *testing.T) {
t.Errorf("MinerU.Net doc_parse suffix=%q", minerU.URLSuffix.DocumentParse)
}
- paddleOCR := pm.FindProvider("PaddleOCR.Net")
+ paddleOCR := pm.FindProvider("PaddleOCR")
if paddleOCR == nil {
- t.Fatal("PaddleOCR.Net provider not found")
+ t.Fatal("PaddleOCR provider not found")
}
if _, ok := paddleOCR.ModelDriver.(*PaddleOCRModel); !ok {
- t.Fatalf("PaddleOCR.Net ModelDriver=%T, want *models.PaddleOCRModel", paddleOCR.ModelDriver)
+ t.Fatalf("PaddleOCR ModelDriver=%T, want *models.PaddleOCRModel", paddleOCR.ModelDriver)
}
- if paddleOCR.Class != "paddleocr.net" {
- t.Errorf("PaddleOCR.Net class=%q", paddleOCR.Class)
+ if paddleOCR.Class != "paddleocr" {
+ t.Errorf("PaddleOCR class=%q", paddleOCR.Class)
}
if paddleOCR.URLSuffix.OCR != "v2/ocr/jobs" {
- t.Errorf("PaddleOCR.Net OCR suffix=%q", paddleOCR.URLSuffix.OCR)
+ t.Errorf("PaddleOCR OCR suffix=%q", paddleOCR.URLSuffix.OCR)
}
}
@@ -172,15 +172,15 @@ func TestLocalOCRProviderConfigsLoadLocalDrivers(t *testing.T) {
t.Errorf("MinerU doc_parse suffix=%q", minerU.URLSuffix.DocumentParse)
}
- paddleOCR := pm.FindProvider("PaddleOCR")
+ paddleOCR := pm.FindProvider("PaddleOCR.local")
if paddleOCR == nil {
- t.Fatal("PaddleOCR provider not found")
+ t.Fatal("PaddleOCR.local provider not found")
}
if _, ok := paddleOCR.ModelDriver.(*PaddleOCRLocalModel); !ok {
- t.Fatalf("PaddleOCR ModelDriver=%T, want *models.PaddleOCRLocalModel", paddleOCR.ModelDriver)
+ t.Fatalf("PaddleOCR.local ModelDriver=%T, want *models.PaddleOCRLocalModel", paddleOCR.ModelDriver)
}
if paddleOCR.URLSuffix.OCR != "layout-parsing" {
- t.Errorf("PaddleOCR OCR suffix=%q", paddleOCR.URLSuffix.OCR)
+ t.Errorf("PaddleOCR.local OCR suffix=%q", paddleOCR.URLSuffix.OCR)
}
}
diff --git a/internal/entity/models/paddleocr.go b/internal/entity/models/paddleocr.go
index de50a2a9bb..3b53293466 100644
--- a/internal/entity/models/paddleocr.go
+++ b/internal/entity/models/paddleocr.go
@@ -53,7 +53,7 @@ func (p *PaddleOCRModel) NewInstance(baseURL map[string]string) ModelDriver {
}
func (p *PaddleOCRModel) Name() string {
- return "paddle_ocr.net"
+ return "paddleocr"
}
func (p *PaddleOCRModel) ChatWithMessages(ctx context.Context, modelName string, messages []Message, apiConfig *APIConfig, chatModelConfig *ChatConfig, modelUsage *common.ModelUsage) (*ChatResponse, error) {
@@ -237,7 +237,7 @@ func (p *PaddleOCRModel) parseOCRResultBody(rawBody []byte, fullMarkdown *string
// logErroredEntry makes an entry with a non-zero errorCode visible instead of
// silently dropping the page as empty.
func (p *PaddleOCRModel) logErroredEntry(entry paddleJsonlLine) {
- common.Warn("paddleocr.net result: entry errored",
+ common.Warn("paddleocr result: entry errored",
zap.String("log_id", entry.LogId),
zap.Int("error_code", entry.ErrorCode),
zap.String("error_msg", entry.ErrorMsg))
@@ -307,7 +307,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
}
req.Header.Set("Client-Platform", "ragflow")
- common.Info("paddleocr.net submit: sending job",
+ common.Info("paddleocr submit: sending job",
zap.String("driver", p.Name()),
zap.String("url", url),
zap.String("model", *modelName),
@@ -316,7 +316,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
resp, err := p.baseModel.httpClient.Do(req)
if err != nil {
- common.Error("paddleocr.net submit: request failed",
+ common.Error("paddleocr submit: request failed",
err,
zap.String("driver", p.Name()),
zap.String("url", url))
@@ -326,7 +326,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
if resp.StatusCode != http.StatusOK {
errBody := readErrorBody(resp.Body)
- common.Error("paddleocr.net submit: non-200",
+ common.Error("paddleocr submit: non-200",
fmt.Errorf("status %d", resp.StatusCode),
zap.String("driver", p.Name()),
zap.String("url", url),
@@ -338,7 +338,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
var submitResp paddleSubmitResponse
if err := json.Unmarshal(respBody, &submitResp); err != nil {
- common.Error("paddleocr.net submit: parse failed",
+ common.Error("paddleocr submit: parse failed",
err,
zap.String("driver", p.Name()),
zap.String("url", url))
@@ -350,7 +350,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
return nil, fmt.Errorf("failed to get jobId from response")
}
- common.Info("paddleocr.net submit: ok",
+ common.Info("paddleocr submit: ok",
zap.String("driver", p.Name()),
zap.String("url", url),
zap.String("job_id", jobId))
@@ -376,7 +376,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
pollResp, err := p.baseModel.httpClient.Do(pollReq)
if err != nil {
- common.Error("paddleocr.net poll: request failed",
+ common.Error("paddleocr poll: request failed",
err,
zap.String("job_id", jobId),
zap.Int("attempt", attempt))
@@ -386,7 +386,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
if pollResp.StatusCode != http.StatusOK {
errBody := readErrorBody(pollResp.Body)
pollResp.Body.Close()
- common.Error("paddleocr.net poll: non-200",
+ common.Error("paddleocr poll: non-200",
fmt.Errorf("status %d", pollResp.StatusCode),
zap.String("job_id", jobId),
zap.Int("attempt", attempt),
@@ -399,7 +399,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
var pollData paddlePollResponse
if err = json.Unmarshal(pollBody, &pollData); err != nil {
- common.Error("paddleocr.net poll: parse failed",
+ common.Error("paddleocr poll: parse failed",
err,
zap.String("job_id", jobId),
zap.Int("attempt", attempt))
@@ -409,14 +409,14 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
// end if 'done' or 'failed'
state := pollData.Data.State
if state == "done" {
- common.Info("paddleocr.net poll: done",
+ common.Info("paddleocr poll: done",
zap.String("job_id", jobId),
zap.Int("attempt", attempt),
zap.String("state", state))
jsonlUrl = pollData.Data.ResultUrl.JsonUrl
break
} else if state == "failed" {
- common.Error("paddleocr.net poll: failed",
+ common.Error("paddleocr poll: failed",
fmt.Errorf("job failed on server"),
zap.String("job_id", jobId),
zap.Int("attempt", attempt),
@@ -425,7 +425,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
return nil, fmt.Errorf("ocr job failed on server: %s", pollData.Data.ErrorMsg)
}
- common.Debug("paddleocr.net poll: in progress",
+ common.Debug("paddleocr poll: in progress",
zap.String("job_id", jobId),
zap.Int("attempt", attempt),
zap.String("state", state),
@@ -437,7 +437,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
select {
case <-time.After(pollInterval):
case <-ctx.Done():
- common.Error("paddleocr.net poll: context done while waiting",
+ common.Error("paddleocr poll: context done while waiting",
ctx.Err(),
zap.String("job_id", jobId),
zap.Int("attempt", attempt),
@@ -450,7 +450,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
return nil, fmt.Errorf("job done but jsonl url is empty")
}
- common.Info("paddleocr.net result: downloading",
+ common.Info("paddleocr result: downloading",
zap.String("job_id", jobId),
zap.String("jsonl_url", jsonlUrl))
@@ -461,7 +461,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
resResp, err := p.baseModel.httpClient.Do(resReq)
if err != nil {
- common.Error("paddleocr.net result: download request failed",
+ common.Error("paddleocr result: download request failed",
err,
zap.String("job_id", jobId),
zap.String("jsonl_url", jsonlUrl))
@@ -470,7 +470,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
defer resResp.Body.Close()
if resResp.StatusCode != http.StatusOK {
- common.Error("paddleocr.net result: non-200",
+ common.Error("paddleocr result: non-200",
fmt.Errorf("status %d", resResp.StatusCode),
zap.String("job_id", jobId),
zap.String("jsonl_url", jsonlUrl),
@@ -478,7 +478,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
return nil, fmt.Errorf("failed to download jsonl, status: %d", resResp.StatusCode)
}
- common.Info("paddleocr.net result: downloaded",
+ common.Info("paddleocr result: downloaded",
zap.String("job_id", jobId),
zap.String("jsonl_url", jsonlUrl))
@@ -495,7 +495,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
extractedText := strings.TrimSpace(fullMarkdown.String())
if extractedText == "" {
- common.Warn("paddleocr.net result: parsed empty text",
+ common.Warn("paddleocr result: parsed empty text",
zap.String("job_id", jobId),
zap.Bool("array_parsed", arrayParsed),
zap.Int("body_bytes", len(rawBody)),
@@ -504,10 +504,10 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
zap.Int("errored_lines", erroredLines),
zap.Int("empty_result_lines", emptyResultLines),
zap.Int("content_lines", contentLines))
- return nil, fmt.Errorf("paddleocr.net result: parsed empty text (scanned_lines=%d, skipped_lines=%d, errored_lines=%d, empty_result_lines=%d, content_lines=%d)",
+ return nil, fmt.Errorf("paddleocr result: parsed empty text (scanned_lines=%d, skipped_lines=%d, errored_lines=%d, empty_result_lines=%d, content_lines=%d)",
scannedLines, skippedLines, erroredLines, emptyResultLines, contentLines)
}
- common.Info("paddleocr.net result: parsed",
+ common.Info("paddleocr result: parsed",
zap.String("job_id", jobId),
zap.Bool("array_parsed", arrayParsed),
zap.Int("body_bytes", len(rawBody)),
@@ -523,7 +523,7 @@ func (p *PaddleOCRModel) OCRFile(ctx context.Context, modelName *string, content
if len(preview) > 200 {
preview = preview[:200]
}
- common.Debug("paddleocr.net result: text preview",
+ common.Debug("paddleocr result: text preview",
zap.String("job_id", jobId),
zap.String("text_preview", preview))
@@ -553,3 +553,32 @@ func (p *PaddleOCRModel) ListTasks(ctx context.Context, apiConfig *APIConfig) ([
func (p *PaddleOCRModel) ShowTask(ctx context.Context, taskID string, apiConfig *APIConfig) (*TaskResponse, error) {
return nil, fmt.Errorf("%s, no such method", p.Name())
}
+
+// PaddleOCRConfigFromAPIKey parses the tenant PaddleOCR api_key payload the
+// same way Python's PaddleOCROcrModel does: the api_key is a JSON object
+// carrying paddleocr_base_url / paddleocr_api_url, paddleocr_access_token and
+// paddleocr_algorithm, optionally nested under an "api_key" key. A non-JSON
+// api_key — the PaddleOCR.local plain bearer token — yields zero values and
+// the caller falls back to plain-text semantics. base_url prefers
+// paddleocr_base_url over paddleocr_api_url, mirroring Python.
+func PaddleOCRConfigFromAPIKey(apiKey string) (baseURL, accessToken, algorithm string) {
+ if strings.TrimSpace(apiKey) == "" {
+ return "", "", ""
+ }
+ var raw map[string]interface{}
+ if err := json.Unmarshal([]byte(apiKey), &raw); err != nil {
+ return "", "", ""
+ }
+ if nested, ok := raw["api_key"].(map[string]interface{}); ok {
+ raw = nested
+ }
+ get := func(key string) string {
+ value, _ := raw[key].(string)
+ return strings.TrimSpace(value)
+ }
+ baseURL = get("paddleocr_base_url")
+ if baseURL == "" {
+ baseURL = get("paddleocr_api_url")
+ }
+ return baseURL, get("paddleocr_access_token"), get("paddleocr_algorithm")
+}
diff --git a/internal/entity/models/paddleocr_local.go b/internal/entity/models/paddleocr_local.go
index fb7719c879..cf8f0f3286 100644
--- a/internal/entity/models/paddleocr_local.go
+++ b/internal/entity/models/paddleocr_local.go
@@ -50,7 +50,7 @@ func (p *PaddleOCRLocalModel) NewInstance(baseURL map[string]string) ModelDriver
}
func (p *PaddleOCRLocalModel) Name() string {
- return "paddleocr"
+ return "paddleocr.local"
}
func (p *PaddleOCRLocalModel) ChatWithMessages(ctx context.Context, modelName string, messages []Message, apiConfig *APIConfig, chatModelConfig *ChatConfig, modelUsage *common.ModelUsage) (*ChatResponse, error) {
@@ -232,7 +232,30 @@ func (p *PaddleOCRLocalModel) ParseFile(ctx context.Context, modelName *string,
}
func (p *PaddleOCRLocalModel) ListModels(ctx context.Context, apiConfig *APIConfig) ([]ListModelResponse, error) {
- return nil, fmt.Errorf("%s no such method", p.Name())
+ provider := GetProviderManager().FindProvider(p.Name())
+ if provider == nil {
+ return nil, fmt.Errorf("provider '%s' not found", p.Name())
+ }
+
+ var modelList []ListModelResponse
+ for _, model := range provider.Models {
+ modelList = append(modelList, ListModelResponse{
+ Name: model.Name,
+ ContentLength: model.ContentLength,
+ MaxOutput: model.MaxOutput,
+ ModelTypes: model.ModelTypes,
+ Thinking: model.Thinking,
+ MaxDimension: model.MaxDimension,
+ MaxBatchSize: model.MaxBatchSize,
+ Dimensions: model.Dimensions,
+ })
+ }
+
+ if len(modelList) == 0 {
+ return nil, fmt.Errorf("no models found for provider '%s'", p.Name())
+ }
+
+ return modelList, nil
}
func (p *PaddleOCRLocalModel) Balance(ctx context.Context, apiConfig *APIConfig) (map[string]interface{}, error) {
diff --git a/internal/entity/models/paddleocr_test.go b/internal/entity/models/paddleocr_test.go
index a36212b158..a9c5bf38ee 100644
--- a/internal/entity/models/paddleocr_test.go
+++ b/internal/entity/models/paddleocr_test.go
@@ -1,12 +1,117 @@
package models
import (
+ "context"
"strings"
"testing"
)
+// TestPaddleOCRLocalListModels verifies that the local PaddleOCR driver lists
+// the default models shipped in conf/models/paddleocr_local.json, so that the
+// "add model by selection" flow can pick them up.
+func TestPaddleOCRLocalListModels(t *testing.T) {
+ dir, restore := setupProviderTestDir(t, "paddleocr_local.json")
+ defer restore()
+
+ if err := InitProviderManager(dir); err != nil {
+ t.Fatalf("InitProviderManager: %v", err)
+ }
+
+ driver := NewPaddleOCRLocalModel(map[string]string{"default": "http://127.0.0.1:9000"}, URLSuffix{OCR: "layout-parsing"})
+ models, err := driver.ListModels(context.Background(), &APIConfig{})
+ if err != nil {
+ t.Fatalf("ListModels: %v", err)
+ }
+
+ want := []string{"PaddleOCR-VL-1.6", "PaddleOCR-VL-1.5", "PP-OCRv6", "PP-OCRv5", "PP-StructureV3"}
+ if len(models) != len(want) {
+ t.Fatalf("len(models) = %d, want %d", len(models), len(want))
+ }
+ for i, name := range want {
+ if models[i].Name != name {
+ t.Errorf("models[%d].Name = %q, want %q", i, models[i].Name, name)
+ }
+ if len(models[i].ModelTypes) != 1 || models[i].ModelTypes[0] != "ocr" {
+ t.Errorf("models[%d].ModelTypes = %v, want [ocr]", i, models[i].ModelTypes)
+ }
+ }
+}
+
+// TestPaddleOCRConfigFromAPIKey pins the api_key JSON contract shared with
+// Python's PaddleOCROcrModel: the cloud provider stores
+// paddleocr_base_url / paddleocr_api_url, paddleocr_access_token and
+// paddleocr_algorithm in the api_key payload, while a plain-text api_key
+// (PaddleOCR.local bearer token) yields zero values.
+func TestPaddleOCRConfigFromAPIKey(t *testing.T) {
+ cases := []struct {
+ name string
+ apiKey string
+ wantURL string
+ wantToken string
+ wantAlgo string
+ }{
+ {
+ name: "empty",
+ apiKey: "",
+ wantURL: "",
+ wantToken: "",
+ wantAlgo: "",
+ },
+ {
+ name: "plain token (PaddleOCR.local)",
+ apiKey: "tok-123",
+ wantURL: "",
+ wantToken: "",
+ wantAlgo: "",
+ },
+ {
+ name: "api_url payload",
+ apiKey: `{"paddleocr_api_url":"http://ocr.test/api","paddleocr_access_token":"tok-456","paddleocr_algorithm":"PaddleOCR-VL"}`,
+ wantURL: "http://ocr.test/api",
+ wantToken: "tok-456",
+ wantAlgo: "PaddleOCR-VL",
+ },
+ {
+ name: "base_url wins over api_url",
+ apiKey: `{"paddleocr_base_url":"http://base.test","paddleocr_api_url":"http://api.test","paddleocr_access_token":"tok-789"}`,
+ wantURL: "http://base.test",
+ wantToken: "tok-789",
+ wantAlgo: "",
+ },
+ {
+ name: "nested api_key key",
+ apiKey: `{"api_key":{"paddleocr_api_url":"http://nested.test","paddleocr_access_token":"tok-nested"}}`,
+ wantURL: "http://nested.test",
+ wantToken: "tok-nested",
+ wantAlgo: "",
+ },
+ {
+ name: "unrelated json ignored",
+ apiKey: `{"openai_api_key":"sk-xxx"}`,
+ wantURL: "",
+ wantToken: "",
+ wantAlgo: "",
+ },
+ }
+
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ url, token, algo := PaddleOCRConfigFromAPIKey(tc.apiKey)
+ if url != tc.wantURL {
+ t.Errorf("baseURL = %q, want %q", url, tc.wantURL)
+ }
+ if token != tc.wantToken {
+ t.Errorf("accessToken = %q, want %q", token, tc.wantToken)
+ }
+ if algo != tc.wantAlgo {
+ t.Errorf("algorithm = %q, want %q", algo, tc.wantAlgo)
+ }
+ })
+ }
+}
+
// sampleArrayResult mirrors the actual response shape observed from the
-// paddle_ocr.net online service: a JSON array of page objects where each
+// PaddleOCR online service: a JSON array of page objects where each
// element carries result.layoutParsingResults[].markdown.text plus
// logId/errorCode/errorMsg at the top level.
const sampleArrayResult = `[
diff --git a/internal/ingestion/component/dispatch_model.go b/internal/ingestion/component/dispatch_model.go
index f0789f656a..cc0a291b5c 100644
--- a/internal/ingestion/component/dispatch_model.go
+++ b/internal/ingestion/component/dispatch_model.go
@@ -87,8 +87,8 @@ func defaultResolveTenantOCRModelByProvider(ctx context.Context, db *gorm.DB, te
providerDAO := dao.NewTenantModelProviderDAO()
provider, err := providerDAO.GetByTenantIDAndProviderName(ctx, db, tenantID, providerName)
if err != nil {
- // Some OCR providers are registered under sibling names: the local
- // "PaddleOCR" provider and the cloud "PaddleOCR.Net" provider expose
+ // Some OCR providers are registered under sibling names: the cloud
+ // "PaddleOCR" provider and the local "PaddleOCR.local" provider expose
// the same OCR capability. Tolerate the alternate spelling before
// giving up so a tenant configured with either name resolves.
for _, alias := range paddleOCRProviderAliases() {
@@ -126,11 +126,11 @@ func defaultResolveTenantOCRModelByProvider(ctx context.Context, db *gorm.DB, te
}
// paddleOCRProviderAliases returns the registered provider names that expose
-// PaddleOCR OCR models: the local "PaddleOCR" provider and the cloud
-// "PaddleOCR.Net" provider. Both carry OCR-typed models and route through the
-// PaddleOCR PDF dispatch regardless of which spelling a tenant configured.
+// PaddleOCR OCR models: the cloud "PaddleOCR" provider and the local
+// "PaddleOCR.local" provider. Both carry OCR-typed models and route through
+// the PaddleOCR PDF dispatch regardless of which spelling a tenant configured.
func paddleOCRProviderAliases() []string {
- return []string{"PaddleOCR", "PaddleOCR.Net"}
+ return []string{"PaddleOCR", "PaddleOCR.local"}
}
func tenantModelIDByType(tenant *entity.Tenant, modelType entity.ModelType) string {
diff --git a/internal/ingestion/component/parser_dispatch_test.go b/internal/ingestion/component/parser_dispatch_test.go
index 900431aa77..6575b183b2 100644
--- a/internal/ingestion/component/parser_dispatch_test.go
+++ b/internal/ingestion/component/parser_dispatch_test.go
@@ -779,6 +779,71 @@ func TestDispatch_PDFPaddleOCRMarkdown_UsesTenantModel(t *testing.T) {
}
}
+// TestDispatch_PDFPaddleOCRMarkdown_UsesAPIKeyPayload pins the cloud
+// PaddleOCR configuration contract: the tenant api_key is a JSON payload
+// (paddleocr_api_url / paddleocr_access_token / paddleocr_algorithm) and the
+// instance base_url field stays empty, mirroring Python's PaddleOCROcrModel.
+// Dispatch must unwrap that payload into a concrete base url, bearer token and
+// algorithm before handing the driver its API config.
+func TestDispatch_PDFPaddleOCRMarkdown_UsesAPIKeyPayload(t *testing.T) {
+ withSSRFBypass(t)
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodPost || r.URL.Path != "/api/layout-parsing" {
+ http.NotFound(w, r)
+ return
+ }
+ if got, want := r.Header.Get("Authorization"), "Bearer tok-123"; got != want {
+ t.Errorf("Authorization = %q, want %q (must unwrap api_key payload)", got, want)
+ return
+ }
+ var body map[string]any
+ if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
+ t.Errorf("decode body: %v", err)
+ return
+ }
+ if got, want := body["algorithm"], "PaddleOCR-VL"; got != want {
+ t.Errorf("algorithm = %v, want %v (must unwrap api_key payload)", got, want)
+ return
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"errorCode":0,"result":{"layoutParsingResults":[{"markdown":{"text":"# Unwrapped Title\n\nUnwrapped body.\n"}}]}}`))
+ }))
+ defer server.Close()
+
+ origResolver := resolveTenantOCRModelByProvider
+ defer func() { resolveTenantOCRModelByProvider = origResolver }()
+ apiKey := fmt.Sprintf(
+ `{"paddleocr_api_url":%q,"paddleocr_access_token":"tok-123","paddleocr_algorithm":"PaddleOCR-VL"}`,
+ server.URL+"/api")
+ emptyBaseURL := ""
+ resolveTenantOCRModelByProvider = func(ctx context.Context, db *gorm.DB, tenantID string, providerName string) (models.ModelDriver, string, *models.APIConfig, int, error) {
+ if got, want := providerName, "PaddleOCR"; got != want {
+ t.Fatalf("providerName = %q, want %q", got, want)
+ }
+ return &paddleocrTestDriver{}, "PaddleOCR-VL", &models.APIConfig{ApiKey: &apiKey, BaseURL: &emptyBaseURL}, 0, nil
+ }
+
+ param := schema.ParserParam{}.Defaults()
+ setups := defaultSetups()
+ setups["pdf"]["parse_method"] = "PaddleOCR"
+ setups["pdf"]["output_format"] = "markdown"
+ c := &ParserComponent{Param: param, Setups: setups}
+
+ out, err := c.Invoke(t.Context(), nil, map[string]any{
+ "binary": []byte("%PDF-1.4"),
+ "file_type": "pdf",
+ "name": "sample.pdf",
+ "tenant_id": "test-tenant",
+ })
+ if err != nil {
+ t.Fatalf("Invoke: %v", err)
+ }
+ md, ok := out["markdown"].(string)
+ if !ok || !strings.Contains(md, "Unwrapped Title") {
+ t.Fatalf("markdown payload = %#v, want Unwrapped Title content", out["markdown"])
+ }
+}
+
func TestDispatch_PDFPaddleOCR_NoTenantModel_HardErrors(t *testing.T) {
withSSRFBypass(t)
origResolver := resolveTenantOCRModelByProvider
@@ -811,7 +876,7 @@ func TestDispatch_PDFPaddleOCR_NoTenantModel_HardErrors(t *testing.T) {
// resolved first (mirroring Python's get_composite_model_name_by_id before
// normalize_layout_recognizer). Previously the UUID fell through to the
// image2text VLM path and failed with "cannot be used as image2text model"
-// for OCR-typed models such as the cloud "PaddleOCR.Net" provider's.
+// for OCR-typed models such as the cloud "PaddleOCR" provider's.
func TestDispatch_PDFPaddleOCR_BareModelUUID_UsesExactModel(t *testing.T) {
withSSRFBypass(t)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
diff --git a/internal/ingestion/component/pdf_vision_dispatch.go b/internal/ingestion/component/pdf_vision_dispatch.go
index 9dcf78fb28..43f5d074e2 100644
--- a/internal/ingestion/component/pdf_vision_dispatch.go
+++ b/internal/ingestion/component/pdf_vision_dispatch.go
@@ -216,17 +216,18 @@ func dispatchMinerUPDF(
// resolvePaddleOCRModelForDispatch resolves the OCR model used by the
// PaddleOCR PDF dispatch. modelID is the raw layout_recognizer value: a bare
// tenant model UUID (no "@") selects that exact model regardless of provider
-// spelling ("PaddleOCR" or "PaddleOCR.Net"); a composite name or empty value
+// spelling ("PaddleOCR" or "PaddleOCR.local"); a composite name or empty value
// falls back to the tenant's first PaddleOCR OCR model, mirroring Python's
// by_paddleocr which uses get_first_provider_model_name(tenant, "PaddleOCR").
//
-// Known limitation: composite names such as "some-model@[email protected]"
-// (an explicit cloud selection) are not recognized here. Any value containing
+// Known limitation: composite names such as "some-model@[email protected]"
+// (an explicit local selection) are not recognized here. Any value containing
// "@" falls through to resolveTenantOCRModelByProvider("PaddleOCR"), which
// returns the tenant's first active PaddleOCR OCR model — potentially the
-// local one — when both the local and the cloud (".Net") providers are
-// configured. The Python path behaves the same way; if exact cloud selection
-// is required, pass the model's tenant-model UUID instead.
+// local one — when both the local ("PaddleOCR.local") and the cloud
+// ("PaddleOCR") providers are configured. The Python path behaves the same
+// way; if exact selection is required, pass the model's tenant-model UUID
+// instead.
var resolvePaddleOCRModelForDispatch = defaultResolvePaddleOCRModelForDispatch
func defaultResolvePaddleOCRModelForDispatch(ctx context.Context, db *gorm.DB, tenantID, modelID string) (modelModule.ModelDriver, string, *modelModule.APIConfig, error) {
@@ -240,8 +241,8 @@ func defaultResolvePaddleOCRModelForDispatch(ctx context.Context, db *gorm.DB, t
// dispatchPaddleOCRPdf submits a PDF to the tenant's PaddleOCR OCR model and
// returns parsed sections. The resolved driver runs the protocol it knows:
-// the cloud "PaddleOCR.Net" driver submits a job and polls the
-// v2/ocr/jobs endpoint, the local "PaddleOCR" driver POSTs synchronously to
+// the cloud "PaddleOCR" driver submits a job and polls the v2/ocr/jobs
+// endpoint, the local "PaddleOCR.local" driver POSTs synchronously to
// layout-parsing — both mirror the Python paddleocr_parser paths.
func dispatchPaddleOCRPdf(
ctx context.Context,
@@ -261,10 +262,24 @@ func dispatchPaddleOCRPdf(
"parser: PaddleOCR requires a PaddleOCR OCR model; found %q. Please add a PaddleOCR OCR model to your tenant", driver.Name())
}
+ // Align with Python's PaddleOCROcrModel: the tenant api_key for the cloud
+ // PaddleOCR provider is a JSON payload carrying paddleocr_base_url /
+ // paddleocr_api_url, paddleocr_access_token and paddleocr_algorithm, while
+ // the instance base_url field stays empty. PaddleOCR.local keeps a
+ // plain-text bearer token in api_key and its base url in the instance
+ // extra, so a non-JSON api_key passes through untouched.
+ keyBaseURL, keyAccessToken, keyAlgorithm := "", "", ""
+ if apiConfig.ApiKey != nil {
+ keyBaseURL, keyAccessToken, keyAlgorithm = modelModule.PaddleOCRConfigFromAPIKey(*apiConfig.ApiKey)
+ }
+
baseURL := ""
if apiConfig.BaseURL != nil {
baseURL = *apiConfig.BaseURL
}
+ if baseURL == "" {
+ baseURL = keyBaseURL
+ }
if baseURL == "" {
baseURL = strings.TrimSpace(common.GetEnv(common.EnvPaddleOCRBaseUrl))
}
@@ -280,7 +295,13 @@ func dispatchPaddleOCRPdf(
if apiConfig.ApiKey != nil {
apiKey = *apiConfig.ApiKey
}
+ if keyAccessToken != "" {
+ apiKey = keyAccessToken
+ }
algorithm := strings.TrimSpace(getStringOr(setup, "paddleocr_algorithm", ""))
+ if algorithm == "" {
+ algorithm = keyAlgorithm
+ }
if algorithm == "" {
algorithm = strings.TrimSpace(common.GetEnv(common.EnvPaddleOCRAlgorithm))
}
@@ -726,10 +747,10 @@ func isMinerUDriver(driver modelModule.ModelDriver) bool {
}
// isPaddleOCRDriver reports whether the model driver is a PaddleOCR variant
-// (remote paddle_ocr.net or local paddleocr).
+// (cloud "paddleocr" or local "paddleocr.local").
func isPaddleOCRDriver(driver modelModule.ModelDriver) bool {
switch strings.ToLower(driver.Name()) {
- case "paddleocr", "paddle_ocr.net":
+ case "paddleocr", "paddleocr.local":
return true
}
return false
@@ -737,8 +758,8 @@ func isPaddleOCRDriver(driver modelModule.ModelDriver) bool {
// isPaddleOCRLayoutModelID reports whether layout — a bare tenant model UUID
// with no "model@instance@provider" composite hint — resolves to an active
-// OCR model driven by a PaddleOCR provider (local "PaddleOCR" or cloud
-// "PaddleOCR.Net"). The web UI stores the tenant model UUID directly in
+// OCR model driven by a PaddleOCR provider (cloud "PaddleOCR" or local
+// "PaddleOCR.local"). The web UI stores the tenant model UUID directly in
// layout_recognizer, so the raw value carries no provider spelling; this
// mirrors Python's get_composite_model_name_by_id resolution of the same
// UUID before the PaddleOCR path is chosen.
diff --git a/internal/parser/parser/paddleocr.go b/internal/parser/parser/paddleocr.go
index 633019a225..6ae50fe1f8 100644
--- a/internal/parser/parser/paddleocr.go
+++ b/internal/parser/parser/paddleocr.go
@@ -20,8 +20,8 @@
// - Poll with exponential backoff until "done" or "failed"
// - Fetch result JSONL and extract text
//
-// For image parsing, only parse_image() semantics are needed;
-// parse_pdf() is handled by the PDF vision dispatch path.
+// Both image (parse_image) and PDF (parse_pdf) parsing go through the same
+// Job API; the file extension selects the service-side file type.
package parser
@@ -72,14 +72,23 @@ type PaddleOCRClient struct {
// PADDLEOCR_ACCESS_TOKEN – bearer token
// PADDLEOCR_ALGORITHM – algorithm name (default PaddleOCR-VL)
func NewPaddleOCRClientFromEnv() *PaddleOCRClient {
- baseURL := common.GetEnv(common.EnvPaddleOCRBaseUrl)
- if baseURL == "" {
+ return newPaddleOCRClient(
+ common.GetEnv(common.EnvPaddleOCRBaseUrl),
+ common.GetEnv(common.EnvPaddleOCRAccessToken),
+ common.GetEnv(common.EnvPaddleOCRAlgorithm),
+ )
+}
+
+// newPaddleOCRClient builds a client, falling back to the default base URL and
+// algorithm when the given values are empty.
+func newPaddleOCRClient(baseURL, accessToken, algorithm string) *PaddleOCRClient {
+ if strings.TrimSpace(baseURL) == "" {
baseURL = defaultPaddleOCRBaseURL
}
return &PaddleOCRClient{
- BaseURL: strings.TrimRight(baseURL, "/"),
- AccessToken: common.GetEnv(common.EnvPaddleOCRAccessToken),
- Algorithm: firstNonEmpty(common.GetEnv(common.EnvPaddleOCRAlgorithm), defaultPaddleOCRAlgo),
+ BaseURL: strings.TrimRight(strings.TrimSpace(baseURL), "/"),
+ AccessToken: strings.TrimSpace(accessToken),
+ Algorithm: firstNonEmpty(strings.TrimSpace(algorithm), defaultPaddleOCRAlgo),
Timeout: defaultPaddleOCRTimeout,
httpClient: &http.Client{
Timeout: 30 * time.Second, // per-request timeout; polling uses deadline
@@ -95,31 +104,50 @@ func (c *PaddleOCRClient) Enabled() bool {
// ParseImage submits the image to PaddleOCR and returns extracted text.
// Mirrors Python's PaddleOCRParser.parse_image().
func (c *PaddleOCRClient) ParseImage(binary []byte, filename string) (string, error) {
+ raw, err := c.submitAndFetch(binary, filename)
+ if err != nil {
+ return "", err
+ }
+ return c.extractImageText(raw), nil
+}
+
+// ParsePDF submits the PDF to PaddleOCR and returns extracted markdown text.
+// Mirrors Python's PaddleOCRParser.parse_pdf(): the file is uploaded through
+// the same async Job API under a ".pdf" name so the service applies PDF
+// parsing, then the JSONL results are flattened exactly like parse_image
+// (layout blocks with a fallback to rec_texts).
+func (c *PaddleOCRClient) ParsePDF(binary []byte, filename string) (string, error) {
+ pdfName := strings.TrimSpace(filename)
+ if !strings.HasSuffix(strings.ToLower(pdfName), ".pdf") {
+ pdfName = "document.pdf" // Python always submits the PDF as document.pdf
+ }
+ raw, err := c.submitAndFetch(binary, pdfName)
+ if err != nil {
+ return "", err
+ }
+ return c.extractImageText(raw), nil
+}
+
+// submitAndFetch runs the async Job API round trip: submit, poll, fetch.
+func (c *PaddleOCRClient) submitAndFetch(binary []byte, filename string) ([]map[string]any, error) {
deadline := time.Now().Add(c.Timeout)
- // Step 1: Submit job
jobID, err := c.submitJob(binary, filename, deadline)
if err != nil {
- return "", fmt.Errorf("paddleocr submit: %w", err)
+ return nil, fmt.Errorf("paddleocr submit: %w", err)
}
-
- // Step 2: Poll until done
resultData, err := c.pollJob(jobID, deadline)
if err != nil {
- return "", fmt.Errorf("paddleocr poll: %w", err)
+ return nil, fmt.Errorf("paddleocr poll: %w", err)
}
-
- // Step 3: Fetch result JSONL
raw, err := c.fetchResult(resultData, deadline)
if err != nil {
- return "", fmt.Errorf("paddleocr fetch: %w", err)
+ return nil, fmt.Errorf("paddleocr fetch: %w", err)
}
-
- // Step 4: Parse result
- return c.extractImageText(raw), nil
+ return raw, nil
}
-// submitJob POSTs the image file to /api/v2/ocr/jobs and returns the job ID.
+// submitJob POSTs the file to /api/v2/ocr/jobs and returns the job ID.
func (c *PaddleOCRClient) submitJob(binary []byte, filename string, deadline time.Time) (string, error) {
var buf bytes.Buffer
w := multipart.NewWriter(&buf)
diff --git a/internal/parser/parser/pdf_parser_paddleocr.go b/internal/parser/parser/pdf_parser_paddleocr.go
index 9bff90d468..4088a8aced 100644
--- a/internal/parser/parser/pdf_parser_paddleocr.go
+++ b/internal/parser/parser/pdf_parser_paddleocr.go
@@ -5,8 +5,6 @@ import (
"fmt"
"ragflow/internal/common"
"strings"
-
- models "ragflow/internal/entity/models"
)
func parsePDFWithPaddleOCR(ctx context.Context, filename string, data []byte, parser *PDFParser) ParseResult {
@@ -23,8 +21,8 @@ func parsePDFWithPaddleOCR(ctx context.Context, filename string, data []byte, pa
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(parser.PaddleOCRAPIKey)
+ if apiKey == "" {
apiKey = strings.TrimSpace(common.GetEnv(common.EnvPaddleOCRAccessToken))
}
algorithm := strings.TrimSpace(parser.PaddleOCRAlgorithm)
@@ -35,29 +33,17 @@ func parsePDFWithPaddleOCR(ctx context.Context, filename string, data []byte, pa
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(ctx, &algorithm, data, &filename, apiConfig, &models.OCRConfig{
- Algorithm: algorithm,
- }, nil)
+ // The async Job API, exactly like Python's PaddleOCRParser.parse_pdf():
+ // submit {base}/api/v2/ocr/jobs, poll until done, download the JSONL
+ // results. No synchronous local driver is involved here.
+ client := newPaddleOCRClient(baseURL, apiKey, algorithm)
+ text, err := client.ParsePDF(data, filename)
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")}
+ return ParseResult{Err: fmt.Errorf("parser: PaddleOCR ParsePDF: %w", err)}
}
pageCount := 1
- if resp.Text != nil && strings.TrimSpace(*resp.Text) == "" {
+ if strings.TrimSpace(text) == "" {
pageCount = 0
}
- return parseMinerUMarkdownResult(ctx, filename, *resp.Text, parser.OutputFormat, pageCount)
+ return parseMinerUMarkdownResult(ctx, filename, text, parser.OutputFormat, pageCount)
}
diff --git a/internal/parser/parser/pdf_parser_paddleocr_test.go b/internal/parser/parser/pdf_parser_paddleocr_test.go
index bb42b4ac3d..2bdfee283c 100644
--- a/internal/parser/parser/pdf_parser_paddleocr_test.go
+++ b/internal/parser/parser/pdf_parser_paddleocr_test.go
@@ -1,8 +1,8 @@
package parser
import (
- "encoding/base64"
- "encoding/json"
+ "fmt"
+ "io"
"net/http"
"net/http/httptest"
"strings"
@@ -10,49 +10,69 @@ import (
"testing"
)
-func TestPDFParser_ParseWithResult_PaddleOCRMarkdownIntegration(t *testing.T) {
- withSSRFBypass(t)
- var called atomic.Bool
-
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- if r.Method != http.MethodPost || r.URL.Path != "/layout-parsing" {
+// paddleOCRJobServer stubs the async PaddleOCR Job API
+// (submit → poll → fetch JSONL), mirroring Python's PaddleOCRParser.
+// wantToken is the expected Authorization bearer token; empty skips the check.
+func paddleOCRJobServer(t *testing.T, called *atomic.Bool, wantToken string) *httptest.Server {
+ t.Helper()
+ return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ switch {
+ case r.Method == http.MethodPost && r.URL.Path == "/api/v2/ocr/jobs":
+ if wantToken != "" {
+ if got, want := r.Header.Get("Authorization"), "Bearer "+wantToken; got != want {
+ t.Errorf("Authorization = %q, want %q", got, want)
+ return
+ }
+ }
+ if err := r.ParseMultipartForm(32 << 20); err != nil {
+ t.Errorf("ParseMultipartForm: %v", err)
+ return
+ }
+ f, _, err := r.FormFile("file")
+ if err != nil {
+ t.Errorf("FormFile: %v", err)
+ return
+ }
+ raw, readErr := io.ReadAll(f)
+ f.Close()
+ if readErr != nil {
+ t.Errorf("ReadAll: %v", readErr)
+ return
+ }
+ if got := string(raw); !strings.HasPrefix(got, "%PDF") {
+ t.Errorf("uploaded file = %q, want PDF bytes", got)
+ return
+ }
+ if got, want := r.FormValue("model"), "PaddleOCR-VL"; got != want {
+ t.Errorf("model = %q, want %q", got, want)
+ return
+ }
+ if got := r.FormValue("optionalPayload"); !strings.Contains(got, "formatBlockContent") {
+ t.Errorf("optionalPayload = %q, want formatBlockContent", got)
+ return
+ }
+ if called != nil {
+ called.Store(true)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"data":{"jobId":"job-1"}}`))
+ case r.Method == http.MethodGet && r.URL.Path == "/api/v2/ocr/jobs/job-1":
+ w.Header().Set("Content-Type", "application/json")
+ resultURL := "http://" + r.Host + "/result"
+ _, _ = fmt.Fprintf(w, `{"data":{"state":"done","resultJsonUrl":%q}}`, resultURL)
+ case r.Method == http.MethodGet && r.URL.Path == "/result":
+ w.Header().Set("Content-Type", "application/jsonl")
+ _, _ = w.Write([]byte(`{"result":{"layoutParsingResults":[{"prunedResult":{"parsing_res_list":[{"block_content":"# Paddle Title\n\nBody paragraph.\n"}]}}]}}`))
+ default:
http.NotFound(w, r)
- return
- }
- called.Store(true)
- if got, want := r.Header.Get("Authorization"), "Bearer paddle-secret"; got != want {
- t.Errorf("Authorization = %q, want %q", got, want)
- return
- }
- var body struct {
- File string `json:"file"`
- FileType int `json:"fileType"`
- Algorithm string `json:"algorithm"`
- }
- if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
- t.Errorf("Decode: %v", err)
- return
- }
- if got, want := body.FileType, 0; got != want {
- t.Errorf("fileType = %d, want %d for PDF", got, want)
- return
- }
- if got, want := body.Algorithm, "PaddleOCR-VL"; got != want {
- t.Errorf("algorithm = %q, want %q", got, want)
- return
- }
- raw, err := base64.StdEncoding.DecodeString(body.File)
- if err != nil {
- t.Errorf("DecodeString: %v", err)
- return
}
- if got := string(raw); !strings.HasPrefix(got, "%PDF") {
- t.Errorf("uploaded file = %q, want PDF bytes", got)
- return
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"errorCode":0,"result":{"layoutParsingResults":[{"markdown":{"text":"# Paddle Title\n\nBody paragraph.\n"}}]}}`))
}))
+}
+
+func TestPDFParser_ParseWithResult_PaddleOCRMarkdownIntegration(t *testing.T) {
+ withSSRFBypass(t)
+ var called atomic.Bool
+ server := paddleOCRJobServer(t, &called, "paddle-secret")
defer server.Close()
pdf := NewPDFParser()
@@ -84,14 +104,7 @@ func TestPDFParser_ParseWithResult_PaddleOCRMarkdownIntegration(t *testing.T) {
func TestPDFParser_ParseWithResult_PaddleOCRJSONIntegration(t *testing.T) {
withSSRFBypass(t)
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- if r.Method != http.MethodPost || r.URL.Path != "/layout-parsing" {
- http.NotFound(w, r)
- return
- }
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"errorCode":0,"result":{"layoutParsingResults":[{"markdown":{"text":"# Paddle Title\n\nBody paragraph.\n"}}]}}`))
- }))
+ server := paddleOCRJobServer(t, nil, "")
defer server.Close()
pdf := NewPDFParser()
diff --git a/internal/service/model_service.go b/internal/service/model_service.go
index f59b029c81..fcba5fc0af 100644
--- a/internal/service/model_service.go
+++ b/internal/service/model_service.go
@@ -1007,6 +1007,20 @@ func (m *ModelProviderService) CheckConnection(ctx context.Context, providerName
BaseURL: &baseURL,
}
+ // The cloud PaddleOCR provider carries its config inside the api_key JSON
+ // payload (paddleocr_api_url / paddleocr_access_token / paddleocr_algorithm),
+ // mirroring Python's PaddleOCROcrModel. Unwrap the access token and base url
+ // so the OCR driver authenticates with a plain bearer token. Non-JSON
+ // api_keys (e.g. PaddleOCR.local) pass through untouched.
+ if keyBaseURL, keyAccessToken, _ := modelModule.PaddleOCRConfigFromAPIKey(apiKey); keyAccessToken != "" {
+ apiKey = keyAccessToken
+ if baseURL == "" {
+ baseURL = keyBaseURL
+ }
+ apiConfig.ApiKey = &apiKey
+ apiConfig.BaseURL = &baseURL
+ }
+
// Mirror Python verify_api_key: verify each model by making a real
// lightweight API request. Returns per-model verify results.
modelVerifyResult, verifyErr := verifyProviderModel(ctx, driver, providerInfo.Models, apiConfig, modelInfo)
diff --git a/web/src/components/floating-chat-widget-markdown.tsx b/web/src/components/floating-chat-widget-markdown.tsx
index 07d2878df8..7e1afc3957 100644
--- a/web/src/components/floating-chat-widget-markdown.tsx
+++ b/web/src/components/floating-chat-widget-markdown.tsx
@@ -314,7 +314,13 @@ const FloatingChatWidgetMarkdown = ({
);
});
},
- [getPopoverContent, getReferenceInfo, handleDocumentButtonClick, loading, t],
+ [
+ getPopoverContent,
+ getReferenceInfo,
+ handleDocumentButtonClick,
+ loading,
+ t,
+ ],
);
const dir = getDirAttribute(content.replace(citationMarkerReg, ''));
diff --git a/web/src/components/svg-icon.tsx b/web/src/components/svg-icon.tsx
index 4d4a9e305d..aa1f416a19 100644
--- a/web/src/components/svg-icon.tsx
+++ b/web/src/components/svg-icon.tsx
@@ -88,7 +88,7 @@ const svgIcons = [
LLMFactory.MinerU,
LLMFactory.MinerUNet,
LLMFactory.PaddleOCR,
- LLMFactory.PaddleOCRNet,
+ LLMFactory.PaddleOCRLocal,
LLMFactory.N1n,
// LLMFactory.DeerAPI,
LLMFactory.Avian,
diff --git a/web/src/constants/llm.ts b/web/src/constants/llm.ts
index f09acc217f..7bc636c812 100644
--- a/web/src/constants/llm.ts
+++ b/web/src/constants/llm.ts
@@ -85,7 +85,7 @@ export enum LLMFactory {
MinerU = 'MinerU',
MinerUNet = 'MinerU.Net',
PaddleOCR = 'PaddleOCR',
- PaddleOCRNet = 'PaddleOCR.Net',
+ PaddleOCRLocal = 'PaddleOCR.local',
OpenDataLoader = 'OpenDataLoader',
SoMark = 'SoMark',
N1n = 'n1n',
@@ -174,7 +174,7 @@ export const IconMap = {
[LLMFactory.MinerU]: 'mineru',
[LLMFactory.MinerUNet]: 'mineru',
[LLMFactory.PaddleOCR]: 'paddleocr',
- [LLMFactory.PaddleOCRNet]: 'paddleocr',
+ [LLMFactory.PaddleOCRLocal]: 'paddleocr',
[LLMFactory.N1n]: 'n1n',
[LLMFactory.Avian]: 'avian',
[LLMFactory.RAGcon]: 'ragcon',
@@ -303,7 +303,7 @@ export const APIMapUrl = {
[LLMFactory.JiekouAI]: 'https://jiekou.ai',
[LLMFactory.MinerU]: 'https://mineru.net',
[LLMFactory.MinerUNet]: 'https://mineru.net',
- [LLMFactory.PaddleOCRNet]: 'https://www.paddleocr.ai/latest/',
+ [LLMFactory.PaddleOCRLocal]: 'https://www.paddleocr.ai/latest/',
[LLMFactory.RAGcon]: 'https://connect.ragcon.com',
[LLMFactory.FunASR]: 'https://github.com/modelscope/FunASR',
};
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 99a443038b..8e8656835a 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -2718,7 +2718,8 @@ Best for: Documents with flowing, contextually connected content — such as boo
youComSearchDescription:
"A web search component powered by You.com's own index. Each result carries extracted passages from the page rather than a single snippet. Works without an API Key by default (keyless free tier); add a key to lift rate limits.",
youComFreshness: 'Freshness',
- youComFreshnessTip: 'Restrict results by how recently they were published.',
+ youComFreshnessTip:
+ 'Restrict results by how recently they were published.',
youComFreshnessAny: 'Any time',
youComFreshnessDay: 'Past day',
youComFreshnessWeek: 'Past week',
diff --git a/web/src/pages/next-search/search-view.tsx b/web/src/pages/next-search/search-view.tsx
index 171dcfa905..83483e3004 100644
--- a/web/src/pages/next-search/search-view.tsx
+++ b/web/src/pages/next-search/search-view.tsx
@@ -231,7 +231,9 @@ export default function SearchingView({
</div>
<div className="w-44">
<TopSelect
- max={searchData.search_config.rerank_candidates_count ?? 100}
+ max={
+ searchData.search_config.rerank_candidates_count ?? 100
+ }
value={pageSize}
onChange={handleTopChange}
></TopSelect>
diff --git a/web/src/pages/user-setting/setting-model/instance-card/hooks.tsx b/web/src/pages/user-setting/setting-model/instance-card/hooks.tsx
index 6db130e201..24d4f734da 100644
--- a/web/src/pages/user-setting/setting-model/instance-card/hooks.tsx
+++ b/web/src/pages/user-setting/setting-model/instance-card/hooks.tsx
@@ -352,10 +352,9 @@ export function useVerifyProvider(
verifyArgs = {
api_key: transformed.apiKey,
base_url: transformed.baseUrl,
- model_info:
- transformed.modelInfo?.length
- ? transformed.modelInfo
- : (selectedModels ?? values.model_info),
+ model_info: transformed.modelInfo?.length
+ ? transformed.modelInfo
+ : (selectedModels ?? values.model_info),
region: transformed.region,
};
} else {
diff --git a/web/src/pages/user-setting/setting-model/provider-schema/field-config/provider-config-map.ts b/web/src/pages/user-setting/setting-model/provider-schema/field-config/provider-config-map.ts
index af3ef028f9..a09cd4c3cd 100644
--- a/web/src/pages/user-setting/setting-model/provider-schema/field-config/provider-config-map.ts
+++ b/web/src/pages/user-setting/setting-model/provider-schema/field-config/provider-config-map.ts
@@ -572,6 +572,55 @@ export const ProviderConfigMap: Record<string, ProviderConfig> = {
},
},
+ // ============ PaddleOCR.local ============
+ [LLMFactory.PaddleOCRLocal]: {
+ llmFactory: LLMFactory.PaddleOCRLocal,
+ title: 'PaddleOCR.local',
+ fields: [
+ {
+ name: 'instance_name',
+ label: 'instanceName',
+ type: FormFieldType.Text,
+ required: true,
+ placeholder: 'instanceNameMessage',
+ tooltip: 'instanceNameTip',
+ validation: { message: 'instanceNameMessage' },
+ },
+ {
+ name: 'paddleocr_api_url',
+ label: 'paddleocrApiUrl',
+ type: 'inputSelect',
+ required: true,
+ placeholder: 'paddleocrApiUrlPlaceholder',
+ validation: { message: 'paddleocrApiUrlMessage' },
+ },
+ {
+ name: 'paddleocr_access_token',
+ label: 'paddleocrAccessToken',
+ type: FormFieldType.Password,
+ required: false,
+ placeholder: 'paddleocrAccessTokenPlaceholder',
+ validation: { message: 'paddleocrAccessTokenMessage' },
+ },
+ ],
+ verifyTransform: (values) => ({
+ apiKey: values.paddleocr_access_token ?? '',
+ baseUrl: values.paddleocr_api_url,
+ modelInfo: [],
+ }),
+ submitTransform: (values) => ({
+ instance_name: values.instance_name,
+ llm_factory: LLMFactory.PaddleOCRLocal,
+ api_key: values.paddleocr_access_token ?? '',
+ base_url: values.paddleocr_api_url,
+ model_info: [],
+ }),
+ echoTransform: (instance) => ({
+ paddleocr_api_url: instance.base_url ?? '',
+ paddleocr_access_token: instance.api_key ?? '',
+ }),
+ },
+
// ============ MinerU ============
[LLMFactory.MinerU]: {
llmFactory: LLMFactory.MinerU,
diff --git a/web/src/pages/user-setting/setting-model/provider-schema/field-config/utils.ts b/web/src/pages/user-setting/setting-model/provider-schema/field-config/utils.ts
index ca06265d56..6f6bb63430 100644
--- a/web/src/pages/user-setting/setting-model/provider-schema/field-config/utils.ts
+++ b/web/src/pages/user-setting/setting-model/provider-schema/field-config/utils.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { IModelInfo } from "@/interfaces/request/llm";
+import { IModelInfo } from '@/interfaces/request/llm';
/**
* Capitalize the first letter of a string
@@ -35,8 +35,8 @@ export function applyChatToVision(
: modelType
? [modelType]
: [];
- if (arr.includes("chat") && vision) {
- return [...arr, "vision"];
+ if (arr.includes('chat') && vision) {
+ return [...arr, 'vision'];
}
return arr;
}
@@ -56,16 +56,16 @@ export function parseApiKeyAsObject(
raw: unknown,
): Record<string, any> | undefined {
let obj: any = raw;
- if (typeof raw === "string") {
+ if (typeof raw === 'string') {
const trimmed = raw.trim();
- if (!trimmed.startsWith("{")) return undefined;
+ if (!trimmed.startsWith('{')) return undefined;
try {
obj = JSON.parse(trimmed);
} catch {
return undefined;
}
}
- return obj && typeof obj === "object" ? obj : undefined;
+ return obj && typeof obj === 'object' ? obj : undefined;
}
/**
diff --git a/web/src/pages/user-setting/setting-model/provider-schema/hooks/use-provider-fields.tsx b/web/src/pages/user-setting/setting-model/provider-schema/hooks/use-provider-fields.tsx
index 49b2188db9..edb786cba0 100644
--- a/web/src/pages/user-setting/setting-model/provider-schema/hooks/use-provider-fields.tsx
+++ b/web/src/pages/user-setting/setting-model/provider-schema/hooks/use-provider-fields.tsx
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-import { FormFieldConfig, FormFieldType } from "@/components/dynamic-form";
-import { Input } from "@/components/ui/input";
-import { InputSelect } from "@/components/ui/input-select";
-import { useTranslate } from "@/hooks/common-hooks";
-import { useMemo } from "react";
-import { ControllerRenderProps, FieldValues } from "react-hook-form";
-import { LIST_MODEL_FIELD_NAMES, LIST_MODEL_PROVIDERS } from "../constants";
-import { FACTORIES_WITH_BASE_URL, getProviderConfig } from "../field-config";
-import type { FieldConfig, SelectOption } from "../types";
+import { FormFieldConfig, FormFieldType } from '@/components/dynamic-form';
+import { Input } from '@/components/ui/input';
+import { InputSelect } from '@/components/ui/input-select';
+import { useTranslate } from '@/hooks/common-hooks';
+import { useMemo } from 'react';
+import { ControllerRenderProps, FieldValues } from 'react-hook-form';
+import { LIST_MODEL_FIELD_NAMES, LIST_MODEL_PROVIDERS } from '../constants';
+import { FACTORIES_WITH_BASE_URL, getProviderConfig } from '../field-config';
+import type { FieldConfig, SelectOption } from '../types';
interface UseProviderFieldsParams {
llmFactory: string;
@@ -45,15 +45,15 @@ const resolveText = (
t: (key: string) => string,
): string | undefined => {
if (!val) return undefined;
- const key = typeof val === "function" ? val(factory) : val;
+ const key = typeof val === 'function' ? val(factory) : val;
return t(key);
};
/** Set value by nested path (supports paths like 'model_info.model_type'). */
-const FORBIDDEN_KEYS = new Set(["__proto__", "constructor", "prototype"]);
+const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
const setNestedValue = (obj: any, path: string, value: any) => {
- const keys = path.split(".");
+ const keys = path.split('.');
let current = obj;
for (let i = 0; i < keys.length - 1; i++) {
const key = keys[i];
@@ -95,7 +95,7 @@ export const useProviderFields = ({
baseUrlOptions,
hideWhenInstanceExists,
}: UseProviderFieldsParams) => {
- const { t } = useTranslate("setting");
+ const { t } = useTranslate('setting');
const config = useMemo(() => getProviderConfig(llmFactory), [llmFactory]);
@@ -110,44 +110,44 @@ export const useProviderFields = ({
// Resolve the shouldRender string token to an actual predicate.
const resolveShouldRender = useMemo(() => {
- return (sr: FieldConfig["shouldRender"]) => {
+ return (sr: FieldConfig['shouldRender']) => {
if (!sr) return undefined;
- if (typeof sr === "function") return sr;
+ if (typeof sr === 'function') return sr;
switch (sr) {
- case "hideWhenInstanceExists":
+ case 'hideWhenInstanceExists':
return hideWhenInstanceExists;
- case "modelTypeIncludesChat":
+ case 'modelTypeIncludesChat':
return (values: any) => {
const mt = values?.model_type;
- if (Array.isArray(mt)) return mt.includes("chat");
- return mt === "chat";
+ if (Array.isArray(mt)) return mt.includes('chat');
+ return mt === 'chat';
};
- case "modelTypeSupportsToolCall":
+ case 'modelTypeSupportsToolCall':
return (values: any) => {
const mt = values?.model_type;
if (Array.isArray(mt)) {
return (
- mt.includes("chat") ||
- mt.includes("vision") ||
- mt.includes("image2text")
+ mt.includes('chat') ||
+ mt.includes('vision') ||
+ mt.includes('image2text')
);
}
- return mt === "chat" || mt === "vision" || mt === "image2text";
+ return mt === 'chat' || mt === 'vision' || mt === 'image2text';
};
- case "modelTypeIncludesTtsAndNotExists":
+ case 'modelTypeIncludesTtsAndNotExists':
return (values: any) => {
if (!hideWhenInstanceExists(values)) return false;
const mt = values?.model_type;
- if (Array.isArray(mt)) return mt.includes("tts");
- return mt === "tts";
+ if (Array.isArray(mt)) return mt.includes('tts');
+ return mt === 'tts';
};
- case "showBaseUrl":
+ case 'showBaseUrl':
return () =>
FACTORIES_WITH_BASE_URL.some((x) => x === llmFactory) ||
- llmFactory?.toLowerCase() === "Anthropic".toLowerCase();
- case "showGroupId":
- return () => llmFactory?.toLowerCase() === "Minimax".toLowerCase();
+ llmFactory?.toLowerCase() === 'Anthropic'.toLowerCase();
+ case 'showGroupId':
+ return () => llmFactory?.toLowerCase() === 'Minimax'.toLowerCase();
default:
return undefined;
}
@@ -162,7 +162,7 @@ export const useProviderFields = ({
const baseUrlRegionMaps = useMemo(() => {
const maps: Record<string, Map<string, string>> = {};
config.fields.forEach((field) => {
- if (field.type !== "inputSelect") return;
+ if (field.type !== 'inputSelect') return;
const options =
field.options && field.options.length > 0
? field.options
@@ -201,7 +201,7 @@ export const useProviderFields = ({
: undefined,
}
: undefined;
- const baseField: Omit<FormFieldConfig, "type"> = {
+ const baseField: Omit<FormFieldConfig, 'type'> = {
name: field.name,
label: t(field.label),
required: field.required,
@@ -221,17 +221,17 @@ export const useProviderFields = ({
// are rendered as disabled.
disabled: !!viewMode && !LIST_MODEL_FIELD_NAMES.has(field.name),
dependencies:
- field.shouldRender === "modelTypeIncludesChat" ||
- field.shouldRender === "modelTypeSupportsToolCall" ||
- field.shouldRender === "modelTypeIncludesTtsAndNotExists"
- ? ["model_type"]
- : ["model_type", "instance_name"].includes(field.name)
- ? ["model_type", "instance_name"]
+ field.shouldRender === 'modelTypeIncludesChat' ||
+ field.shouldRender === 'modelTypeSupportsToolCall' ||
+ field.shouldRender === 'modelTypeIncludesTtsAndNotExists'
+ ? ['model_type']
+ : ['model_type', 'instance_name'].includes(field.name)
+ ? ['model_type', 'instance_name']
: undefined,
};
// inputSelect type: use the InputSelect component, options come from baseUrlOptions
- if (field.type === "inputSelect") {
+ if (field.type === 'inputSelect') {
const inputSelectOptions: SelectOption[] =
field.options && field.options.length > 0
? field.options
@@ -244,7 +244,7 @@ export const useProviderFields = ({
return inputSelectOptions.length > 0 ? (
<InputSelect
{...fieldProps}
- value={(fieldProps.value ?? "") as string}
+ value={(fieldProps.value ?? '') as string}
onChange={(value) => fieldProps.onChange(value)}
options={inputSelectOptions as any}
placeholder={placeholderText}
@@ -291,11 +291,11 @@ export const useProviderFields = ({
// original key in the URL object is 'default' (e.g.
// `availableProviders.url.default`). If no such option exists,
// leave the field empty so the user picks one explicitly.
- if (f.type === "inputSelect") {
+ if (f.type === 'inputSelect') {
const urlMap = baseUrlRegionMaps[f.name];
if (urlMap) {
for (const [url, regionKey] of urlMap.entries()) {
- if (regionKey === "default") {
+ if (regionKey === 'default') {
setNestedValue(result, f.name, url);
return;
}
@@ -304,9 +304,9 @@ export const useProviderFields = ({
}
});
// For configurations without a default model_type, assign an empty array (multi-select field)
- const mtField = config.fields.find((f) => f.name === "model_type");
+ const mtField = config.fields.find((f) => f.name === 'model_type');
if (mtField && mtField.defaultValue === undefined) {
- setNestedValue(result, "model_type", []);
+ setNestedValue(result, 'model_type', []);
}
return result;
}, [editMode, viewMode, initialValues, config.fields, baseUrlRegionMaps]);