mirror of
https://github.com/PaddlePaddle/PaddleOCR.git
synced 2026-12-04 13:32:07 +08:00
* feat: add multi-language API SDK for PaddleOCR async API Add Python/Go/TypeScript SDKs that wrap the PaddleOCR async job API (submit → poll → fetch result) into simple blocking interfaces. Python SDK: - Integrated into paddleocr/_api_client/ as internal subpackage - APIClient (sync) + AsyncAPIClient (asyncio) dual interfaces - CLI subcommand: paddleocr api --model_type ocr/doc_parsing - Supports PP-OCRv5, PP-StructureV3, PaddleOCR-VL, PaddleOCR-VL-1.5 Go SDK (api_sdk/go/): - Zero dependencies (stdlib only) - Functional options pattern + context.Context cancellation - Operation object with Wait(ctx)/Poll(ctx) methods TypeScript SDK (api_sdk/typescript/): - Zero dependencies (native fetch, Node>=18) - AbortSignal cancellation support - ESM + CJS dual output All SDKs share: - Exponential backoff polling (3s initial, 1.5x, 15s max, configurable timeout) - Typed error hierarchy (Auth/API/JobFailed/Timeout/Network/FileNotFound) - URL and local file upload support - Convenience methods + manual control (submit/wait/poll) interfaces * fix: address PR review feedback - Rename PaddleOCRError to PaddleOCRAPIError across all three SDKs - Replace custom FileNotFoundError with Python builtin in Python SDK - Expand OCROptions/DocParsingOptions with all API parameters (Python/Go/TS) - CLI: use Model enum values instead of hardcoded strings - CLI: allow --model for both ocr and doc_parsing tasks - Update license header year to 2026 - Simplify TypeScript defaultPayload to empty object * fix: harden multi-language API SDK Co-authored-by: Cursor <cursoragent@cursor.com> * fix(sdk): jsonl fetch without auth, poll timeout, abort parity Co-authored-by: Cursor <cursoragent@cursor.com> * feat: harden PaddleOCR official API SDK Align Python, TypeScript, and Go SDKs around typed jobs, model-aware document parsing, request/poll timeouts, strict errors, resource saving, and integrated release docs for the PaddleOCR official API. Co-authored-by: Cursor <cursoragent@cursor.com> * feat: complete API SDK remediation and default doc parsing to PaddleOCR-VL-1.5 Consolidate SDK hardening, docs, tests, and cross-language default model behavior for document parsing. Co-authored-by: Cursor <cursoragent@cursor.com> * Fix bugs * Fix bugs and optimize sdks * Fix bugs * Fix bugs * Update skills * Fix bugs * Update docs * Fix docs * Fix doc * Fix --------- Co-authored-by: Bobholamovic <bob1998425@hotmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
104 lines
2.0 KiB
Go
104 lines
2.0 KiB
Go
// Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package paddleocr
|
|
|
|
import "fmt"
|
|
|
|
type PaddleOCRAPIError struct {
|
|
Message string
|
|
Cause error
|
|
}
|
|
|
|
func (e *PaddleOCRAPIError) Error() string {
|
|
if e.Message == "" && e.Cause != nil {
|
|
return e.Cause.Error()
|
|
}
|
|
return e.Message
|
|
}
|
|
|
|
func (e *PaddleOCRAPIError) Unwrap() error {
|
|
return e.Cause
|
|
}
|
|
|
|
type AuthError struct {
|
|
PaddleOCRAPIError
|
|
}
|
|
|
|
type InvalidRequestError struct {
|
|
PaddleOCRAPIError
|
|
}
|
|
|
|
type APIError struct {
|
|
StatusCode int
|
|
PaddleOCRAPIError
|
|
}
|
|
|
|
func (e *APIError) Error() string {
|
|
return fmt.Sprintf("HTTP %d: %s", e.StatusCode, e.Message)
|
|
}
|
|
|
|
type RateLimitError struct {
|
|
APIError
|
|
}
|
|
|
|
type ServiceUnavailableError struct {
|
|
APIError
|
|
}
|
|
|
|
type JobFailedError struct {
|
|
JobID string
|
|
ErrorMsg string
|
|
PaddleOCRAPIError
|
|
}
|
|
|
|
func (e *JobFailedError) Error() string {
|
|
return fmt.Sprintf("Job %s failed: %s", e.JobID, e.ErrorMsg)
|
|
}
|
|
|
|
type RequestTimeoutError struct {
|
|
PaddleOCRAPIError
|
|
}
|
|
|
|
type PollTimeoutError struct {
|
|
JobID string
|
|
Elapsed float64
|
|
PaddleOCRAPIError
|
|
}
|
|
|
|
func (e *PollTimeoutError) Error() string {
|
|
return fmt.Sprintf("Timed out after %.1fs waiting for job %s", e.Elapsed, e.JobID)
|
|
}
|
|
|
|
type NetworkError struct {
|
|
PaddleOCRAPIError
|
|
}
|
|
|
|
type FileNotFoundError struct {
|
|
Path string
|
|
PaddleOCRAPIError
|
|
}
|
|
|
|
func (e *FileNotFoundError) Error() string {
|
|
return fmt.Sprintf("File not found: %s", e.Path)
|
|
}
|
|
|
|
type ResponseFormatError struct {
|
|
PaddleOCRAPIError
|
|
}
|
|
|
|
type ResultParseError struct {
|
|
PaddleOCRAPIError
|
|
}
|