refactor: 项目更名 WeKnora → Academy
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名) - 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块) - docreader proto 描述符采用等长替换,保持序列化字节布局有效 - Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像 - 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
This commit is contained in:
1 parent
9097ee699d
commit
9058149576
3136 files changed
+18018
-18004
No files matched your search
+59
-59
@@ -11,25 +11,25 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"academy/internal/logger"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/models/utils"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
secutils "github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/models/utils"
|
||||
"academy/internal/types"
|
||||
secutils "academy/internal/utils"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
weKnoraCloudReaderBaseURL = "https://weknora.weixin.qq.com/api/v1/doc"
|
||||
// defaultWeKnoraCloudPollTimeout bounds how long one async task is polled;
|
||||
// WEKNORA_WEKNORACLOUD_TIMEOUT overrides it. It must stay below
|
||||
// WEKNORA_DOCREADER_CALL_TIMEOUT (default 30m) or the hardcoded value, not
|
||||
academyCloudReaderBaseURL = "https://weknora.weixin.qq.com/api/v1/doc"
|
||||
// defaultAcademyCloudPollTimeout bounds how long one async task is polled;
|
||||
// ACADEMY_ACADEMYCLOUD_TIMEOUT overrides it. It must stay below
|
||||
// ACADEMY_DOCREADER_CALL_TIMEOUT (default 30m) or the hardcoded value, not
|
||||
// the configured one, is what fails a slow parse.
|
||||
defaultWeKnoraCloudPollTimeout = 20 * time.Minute
|
||||
defaultAcademyCloudPollTimeout = 20 * time.Minute
|
||||
)
|
||||
|
||||
// WeKnoraCloudSignedDocumentReader implements the docreader HTTP protocol with WeKnoraCloud signing.
|
||||
type WeKnoraCloudSignedDocumentReader struct {
|
||||
// AcademyCloudSignedDocumentReader implements the docreader HTTP protocol with AcademyCloud signing.
|
||||
type AcademyCloudSignedDocumentReader struct {
|
||||
appID string
|
||||
apiKey string
|
||||
client *http.Client
|
||||
@@ -38,42 +38,42 @@ type WeKnoraCloudSignedDocumentReader struct {
|
||||
pollTimeout time.Duration
|
||||
}
|
||||
|
||||
func NewWeKnoraCloudSignedDocumentReader(appID, apiKey string) (*WeKnoraCloudSignedDocumentReader, error) {
|
||||
func NewAcademyCloudSignedDocumentReader(appID, apiKey string) (*AcademyCloudSignedDocumentReader, error) {
|
||||
if appID == "" {
|
||||
return nil, fmt.Errorf("WeKnoraCloud appID is required")
|
||||
return nil, fmt.Errorf("AcademyCloud appID is required")
|
||||
}
|
||||
if apiKey == "" {
|
||||
return nil, fmt.Errorf("WeKnoraCloud apiKey is required")
|
||||
return nil, fmt.Errorf("AcademyCloud apiKey is required")
|
||||
}
|
||||
clientCfg := secutils.DefaultSSRFSafeHTTPClientConfig()
|
||||
clientCfg.Timeout = 500 * time.Minute
|
||||
return &WeKnoraCloudSignedDocumentReader{
|
||||
return &AcademyCloudSignedDocumentReader{
|
||||
appID: appID,
|
||||
apiKey: apiKey,
|
||||
initialPollInterval: 500 * time.Millisecond,
|
||||
maxPollInterval: 10 * time.Second,
|
||||
pollTimeout: requestTimeoutFromEnv("WEKNORA_WEKNORACLOUD_TIMEOUT", defaultWeKnoraCloudPollTimeout),
|
||||
pollTimeout: requestTimeoutFromEnv("ACADEMY_ACADEMYCLOUD_TIMEOUT", defaultAcademyCloudPollTimeout),
|
||||
client: secutils.NewSSRFSafeHTTPClient(clientCfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *WeKnoraCloudSignedDocumentReader) Reconnect(addr string) error {
|
||||
func (p *AcademyCloudSignedDocumentReader) Reconnect(addr string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *WeKnoraCloudSignedDocumentReader) IsConnected() bool { return true }
|
||||
func (p *AcademyCloudSignedDocumentReader) IsConnected() bool { return true }
|
||||
|
||||
func (p *WeKnoraCloudSignedDocumentReader) ListEngines(ctx context.Context, overrides map[string]string) ([]types.ParserEngineInfo, error) {
|
||||
func (p *AcademyCloudSignedDocumentReader) ListEngines(ctx context.Context, overrides map[string]string) ([]types.ParserEngineInfo, error) {
|
||||
return []types.ParserEngineInfo{{
|
||||
Name: WeKnoraCloudEngineName,
|
||||
Description: "WeKnoraCloud signed docreader",
|
||||
Name: AcademyCloudEngineName,
|
||||
Description: "AcademyCloud signed docreader",
|
||||
FileTypes: []string{"docx", "doc", "pdf", "md", "markdown", "xlsx", "xls", "pptx", "ppt"},
|
||||
Available: true,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (p *WeKnoraCloudSignedDocumentReader) Read(ctx context.Context, req *types.ReadRequest) (*types.ReadResult, error) {
|
||||
logger.Infof(ctx, "[WeKnoraCloud] read start file=%q type=%q engine=%q hasURL=%v contentLen=%d requestID=%q",
|
||||
func (p *AcademyCloudSignedDocumentReader) Read(ctx context.Context, req *types.ReadRequest) (*types.ReadResult, error) {
|
||||
logger.Infof(ctx, "[AcademyCloud] read start file=%q type=%q engine=%q hasURL=%v contentLen=%d requestID=%q",
|
||||
req.FileName, req.FileType, req.ParserEngine, strings.TrimSpace(req.URL) != "", len(req.FileContent), req.RequestID)
|
||||
body := httpReadRequest{
|
||||
FileName: req.FileName,
|
||||
@@ -91,46 +91,46 @@ func (p *WeKnoraCloudSignedDocumentReader) Read(ctx context.Context, req *types.
|
||||
}
|
||||
jsonBody, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] marshal read request: %v", err)
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] marshal read request: %v", err)
|
||||
return nil, fmt.Errorf("http marshal read request: %w", err)
|
||||
}
|
||||
httpReq, err := p.newSignedRequest(ctx, http.MethodPost, weKnoraCloudReaderBaseURL+"/reader", jsonBody)
|
||||
httpReq, err := p.newSignedRequest(ctx, http.MethodPost, academyCloudReaderBaseURL+"/reader", jsonBody)
|
||||
if err != nil {
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] signed read request: %v", err)
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] signed read request: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
resp, err := p.client.Do(httpReq)
|
||||
if err != nil {
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] http read request failed: %v", err)
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] http read request failed: %v", err)
|
||||
return nil, fmt.Errorf("http read failed: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusAccepted && resp.StatusCode != http.StatusOK {
|
||||
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] http read unexpected status %d: %s", resp.StatusCode, string(bodyBytes))
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] http read unexpected status %d: %s", resp.StatusCode, string(bodyBytes))
|
||||
return nil, fmt.Errorf("http read status %d: %s", resp.StatusCode, string(bodyBytes))
|
||||
}
|
||||
var submit weKnoraCloudAsyncSubmitResponse
|
||||
var submit academyCloudAsyncSubmitResponse
|
||||
if err := json.NewDecoder(resp.Body).Decode(&submit); err != nil {
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] decode read submit response: %v", err)
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] decode read submit response: %v", err)
|
||||
return nil, fmt.Errorf("http decode read submit response: %w", err)
|
||||
}
|
||||
if strings.TrimSpace(submit.TaskID) == "" {
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] submit response missing task_id (status=%q message=%q)", submit.Status, submit.Message)
|
||||
return nil, fmt.Errorf("weknoracloud docreader submit response missing task_id")
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] submit response missing task_id (status=%q message=%q)", submit.Status, submit.Message)
|
||||
return nil, fmt.Errorf("academycloud docreader submit response missing task_id")
|
||||
}
|
||||
logger.Infof(ctx, "[WeKnoraCloud] task submitted task_id=%s file=%q type=%q", submit.TaskID, req.FileName, req.FileType)
|
||||
logger.Infof(ctx, "[AcademyCloud] task submitted task_id=%s file=%q type=%q", submit.TaskID, req.FileName, req.FileType)
|
||||
return p.pollTaskResult(ctx, submit.TaskID)
|
||||
}
|
||||
|
||||
type weKnoraCloudAsyncSubmitResponse struct {
|
||||
type academyCloudAsyncSubmitResponse struct {
|
||||
TaskID string `json:"task_id"`
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
}
|
||||
|
||||
type weKnoraCloudAsyncTaskResponse struct {
|
||||
type academyCloudAsyncTaskResponse struct {
|
||||
TaskID string `json:"task_id"`
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
@@ -141,38 +141,38 @@ type weKnoraCloudAsyncTaskResponse struct {
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (p *WeKnoraCloudSignedDocumentReader) pollTaskResult(ctx context.Context, taskID string) (*types.ReadResult, error) {
|
||||
func (p *AcademyCloudSignedDocumentReader) pollTaskResult(ctx context.Context, taskID string) (*types.ReadResult, error) {
|
||||
pollCtx := ctx
|
||||
if p.pollTimeout > 0 {
|
||||
var cancel context.CancelFunc
|
||||
pollCtx, cancel = context.WithTimeout(ctx, p.pollTimeout)
|
||||
defer cancel()
|
||||
}
|
||||
statusURL := weKnoraCloudReaderBaseURL + "/" + taskID
|
||||
statusURL := academyCloudReaderBaseURL + "/" + taskID
|
||||
currentInterval := p.initialPollInterval
|
||||
for {
|
||||
httpReq, err := p.newSignedRequest(pollCtx, http.MethodGet, statusURL, nil)
|
||||
if err != nil {
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] poll signed request task_id=%s: %v", taskID, err)
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] poll signed request task_id=%s: %v", taskID, err)
|
||||
return nil, err
|
||||
}
|
||||
resp, err := p.client.Do(httpReq)
|
||||
if err != nil {
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] http poll task_id=%s failed: %v", taskID, err)
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] http poll task_id=%s failed: %v", taskID, err)
|
||||
return nil, fmt.Errorf("http poll task failed: %w", err)
|
||||
}
|
||||
var taskResp weKnoraCloudAsyncTaskResponse
|
||||
var taskResp academyCloudAsyncTaskResponse
|
||||
func() {
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||
err = fmt.Errorf("http poll task status %d: %s", resp.StatusCode, string(bodyBytes))
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] poll task_id=%s status %d: %s", taskID, resp.StatusCode, string(bodyBytes))
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] poll task_id=%s status %d: %s", taskID, resp.StatusCode, string(bodyBytes))
|
||||
return
|
||||
}
|
||||
if decodeErr := json.NewDecoder(resp.Body).Decode(&taskResp); decodeErr != nil {
|
||||
err = fmt.Errorf("http decode task response: %w", decodeErr)
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] poll task_id=%s decode response: %v", taskID, decodeErr)
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] poll task_id=%s decode response: %v", taskID, decodeErr)
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
@@ -181,40 +181,40 @@ func (p *WeKnoraCloudSignedDocumentReader) pollTaskResult(ctx context.Context, t
|
||||
switch taskResp.Status {
|
||||
case "completed":
|
||||
if taskResp.Result == nil {
|
||||
logger.Infof(ctx, "[WeKnoraCloud] task_id=%s completed with no result payload", taskID)
|
||||
logger.Infof(ctx, "[AcademyCloud] task_id=%s completed with no result payload", taskID)
|
||||
return &types.ReadResult{}, nil
|
||||
}
|
||||
res := fromHTTPReadResponse(taskResp.Result)
|
||||
if res.Error != "" {
|
||||
logger.Errorf(ctx, "[WeKnoraCloud] task_id=%s completed with result.error: %s", taskID, res.Error)
|
||||
logger.Errorf(ctx, "[AcademyCloud] task_id=%s completed with result.error: %s", taskID, res.Error)
|
||||
} else {
|
||||
logger.Debugf(ctx, "[WeKnoraCloud] task_id=%s completed ok markdownLen=%d", taskID, len(res.MarkdownContent))
|
||||
logger.Debugf(ctx, "[AcademyCloud] task_id=%s completed ok markdownLen=%d", taskID, len(res.MarkdownContent))
|
||||
}
|
||||
return res, nil
|
||||
case "failed":
|
||||
if taskResp.Error != "" {
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] task_id=%s failed: %s", taskID, taskResp.Error)
|
||||
return nil, fmt.Errorf("weknoracloud docreader task failed: %s", taskResp.Error)
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] task_id=%s failed: %s", taskID, taskResp.Error)
|
||||
return nil, fmt.Errorf("academycloud docreader task failed: %s", taskResp.Error)
|
||||
}
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] task_id=%s failed: %s", taskID, taskResp.Message)
|
||||
return nil, fmt.Errorf("weknoracloud docreader task failed: %s", taskResp.Message)
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] task_id=%s failed: %s", taskID, taskResp.Message)
|
||||
return nil, fmt.Errorf("academycloud docreader task failed: %s", taskResp.Message)
|
||||
case "cancelled":
|
||||
if taskResp.Error != "" {
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] task_id=%s cancelled: %s", taskID, taskResp.Error)
|
||||
return nil, fmt.Errorf("weknoracloud docreader task cancelled: %s", taskResp.Error)
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] task_id=%s cancelled: %s", taskID, taskResp.Error)
|
||||
return nil, fmt.Errorf("academycloud docreader task cancelled: %s", taskResp.Error)
|
||||
}
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] task_id=%s cancelled", taskID)
|
||||
return nil, fmt.Errorf("weknoracloud docreader task cancelled")
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] task_id=%s cancelled", taskID)
|
||||
return nil, fmt.Errorf("academycloud docreader task cancelled")
|
||||
}
|
||||
if err := pollCtx.Err(); err != nil {
|
||||
logger.Errorf(ctx, "[WeKnoraCloud] poll task_id=%s aborted before sleep: %v", taskID, err)
|
||||
logger.Errorf(ctx, "[AcademyCloud] poll task_id=%s aborted before sleep: %v", taskID, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Exponential backoff: multiply by 1.5 each time, cap at maxPollInterval
|
||||
select {
|
||||
case <-pollCtx.Done():
|
||||
logger.Errorf(ctx, "[WeKnoraCloud] poll task_id=%s stopped: %v", taskID, pollCtx.Err())
|
||||
logger.Errorf(ctx, "[AcademyCloud] poll task_id=%s stopped: %v", taskID, pollCtx.Err())
|
||||
return nil, pollCtx.Err()
|
||||
case <-time.After(currentInterval):
|
||||
// Update interval for next iteration
|
||||
@@ -227,14 +227,14 @@ func (p *WeKnoraCloudSignedDocumentReader) pollTaskResult(ctx context.Context, t
|
||||
}
|
||||
}
|
||||
|
||||
func (p *WeKnoraCloudSignedDocumentReader) newSignedRequest(ctx context.Context, method, url string, body []byte) (*http.Request, error) {
|
||||
func (p *AcademyCloudSignedDocumentReader) newSignedRequest(ctx context.Context, method, url string, body []byte) (*http.Request, error) {
|
||||
requestID := uuid.New().String()
|
||||
if len(body) == 0 {
|
||||
body = []byte("{}")
|
||||
}
|
||||
httpReq, err := http.NewRequestWithContext(ctx, method, url, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
logger.Errorf(context.Background(), "[WeKnoraCloud] http new request %s %s: %v", method, url, err)
|
||||
logger.Errorf(context.Background(), "[AcademyCloud] http new request %s %s: %v", method, url, err)
|
||||
return nil, fmt.Errorf("http new request: %w", err)
|
||||
}
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
@@ -246,10 +246,10 @@ func (p *WeKnoraCloudSignedDocumentReader) newSignedRequest(ctx context.Context,
|
||||
}
|
||||
|
||||
// PreprocessImage is not offered by the cloud-signed reader: page straightening
|
||||
// runs in the local docreader service, while this reader talks to WeKnoraCloud.
|
||||
// runs in the local docreader service, while this reader talks to AcademyCloud.
|
||||
// It reports that as a verdict — fallback=true, no error — so the caller's only
|
||||
// fallback (OCR the original bytes) needs no special case and nothing looks like
|
||||
// a failure in the logs.
|
||||
func (p *WeKnoraCloudSignedDocumentReader) PreprocessImage(_ context.Context, _ []byte) ([]byte, bool, error) {
|
||||
func (p *AcademyCloudSignedDocumentReader) PreprocessImage(_ context.Context, _ []byte) ([]byte, bool, error) {
|
||||
return nil, true, nil
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
package anydoc
|
||||
|
||||
// The default build links no converter: the anydoc archive is a Rust build
|
||||
// artifact, and requiring a Rust toolchain to compile WeKnora would be a steep
|
||||
// artifact, and requiring a Rust toolchain to compile Academy would be a steep
|
||||
// price for one optional engine. Everything still compiles and the engine
|
||||
// registry simply reports the engine as unavailable.
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/infrastructure/docparser/anydoc"
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
"academy/internal/infrastructure/docparser/anydoc"
|
||||
"academy/internal/logger"
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
)
|
||||
|
||||
// AnydocReader converts office documents to markdown in this process, using
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
func TestAnydocReaderMixedPDFFallsBackThroughRead(t *testing.T) {
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/infrastructure/docparser/anydoc"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/infrastructure/docparser/anydoc"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
func TestAnydocReaderRejectsUnsupportedFileType(t *testing.T) {
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/infrastructure/docparser/anydoc"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/infrastructure/docparser/anydoc"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
// TestEmbeddedVectorImageLinksResolve guards the string contract between
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
// simpleFormats lists file extensions that Go can handle without the Python service.
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestPaddleOCRVLCloudTimeoutConfig(t *testing.T) {
|
||||
{"negative", "-1s", paddleOCRVLCloudTimeout},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Setenv("WEKNORA_PADDLEOCR_VL_CLOUD_TIMEOUT", tt.value)
|
||||
t.Setenv("ACADEMY_PADDLEOCR_VL_CLOUD_TIMEOUT", tt.value)
|
||||
assert.Equal(t, tt.want, NewPaddleOCRVLCloudReader(nil).timeout)
|
||||
})
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func TestPaddleOCRVLCloudTimeoutConfig(t *testing.T) {
|
||||
// cloud keeps reporting as running.
|
||||
func TestPaddleOCRVLCloudPollStopsAtConfiguredTimeout(t *testing.T) {
|
||||
allowLoopbackSSRF(t)
|
||||
t.Setenv("WEKNORA_PADDLEOCR_VL_CLOUD_TIMEOUT", "200ms")
|
||||
t.Setenv("ACADEMY_PADDLEOCR_VL_CLOUD_TIMEOUT", "200ms")
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = io.WriteString(w, `{"code":0,"data":{"state":"running"}}`)
|
||||
@@ -70,38 +70,38 @@ func TestPaddleOCRVLCloudPollStopsAtConfiguredTimeout(t *testing.T) {
|
||||
assert.Contains(t, err.Error(), fmt.Sprintf("timed out after %s", 200*time.Millisecond))
|
||||
assert.Less(t, time.Since(start), 5*time.Second)
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatalf("poll loop ignored WEKNORA_PADDLEOCR_VL_CLOUD_TIMEOUT")
|
||||
t.Fatalf("poll loop ignored ACADEMY_PADDLEOCR_VL_CLOUD_TIMEOUT")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeKnoraCloudPollTimeoutConfig(t *testing.T) {
|
||||
func TestAcademyCloudPollTimeoutConfig(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name, value string
|
||||
want time.Duration
|
||||
}{
|
||||
{"empty", "", defaultWeKnoraCloudPollTimeout},
|
||||
{"empty", "", defaultAcademyCloudPollTimeout},
|
||||
{"minutes", "90m", 90 * time.Minute},
|
||||
{"trimmed", " 3600s ", time.Hour},
|
||||
{"invalid", "invalid", defaultWeKnoraCloudPollTimeout},
|
||||
{"zero", "0s", defaultWeKnoraCloudPollTimeout},
|
||||
{"negative", "-1s", defaultWeKnoraCloudPollTimeout},
|
||||
{"invalid", "invalid", defaultAcademyCloudPollTimeout},
|
||||
{"zero", "0s", defaultAcademyCloudPollTimeout},
|
||||
{"negative", "-1s", defaultAcademyCloudPollTimeout},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Setenv("WEKNORA_WEKNORACLOUD_TIMEOUT", tt.value)
|
||||
reader, err := NewWeKnoraCloudSignedDocumentReader("app-id", "api-key")
|
||||
t.Setenv("ACADEMY_ACADEMYCLOUD_TIMEOUT", tt.value)
|
||||
reader, err := NewAcademyCloudSignedDocumentReader("app-id", "api-key")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.want, reader.pollTimeout)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// weKnoraCloudPollTransport answers every poll with "still running" so the
|
||||
// academyCloudPollTransport answers every poll with "still running" so the
|
||||
// configured poll budget is the only thing that can end the loop.
|
||||
type weKnoraCloudPollTransport struct {
|
||||
type academyCloudPollTransport struct {
|
||||
polls atomic.Int64
|
||||
}
|
||||
|
||||
func (t *weKnoraCloudPollTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
func (t *academyCloudPollTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
t.polls.Add(1)
|
||||
body := `{"task_id":"task-1","status":"processing","progress":0.1}`
|
||||
return &http.Response{
|
||||
@@ -115,7 +115,7 @@ func (t *weKnoraCloudPollTransport) RoundTrip(req *http.Request) (*http.Response
|
||||
// The configured budget, not the old hardcoded 20m, must end the poll loop
|
||||
// whether or not the caller has a deadline of its own. Ingestion always calls
|
||||
// with a (much longer) DocReader deadline, so that case must not bypass it.
|
||||
func TestWeKnoraCloudPollStopsAtConfiguredTimeout(t *testing.T) {
|
||||
func TestAcademyCloudPollStopsAtConfiguredTimeout(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
parentCtx func() (context.Context, context.CancelFunc)
|
||||
@@ -128,11 +128,11 @@ func TestWeKnoraCloudPollStopsAtConfiguredTimeout(t *testing.T) {
|
||||
}},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Setenv("WEKNORA_WEKNORACLOUD_TIMEOUT", "300ms")
|
||||
reader, err := NewWeKnoraCloudSignedDocumentReader("app-id", "api-key")
|
||||
t.Setenv("ACADEMY_ACADEMYCLOUD_TIMEOUT", "300ms")
|
||||
reader, err := NewAcademyCloudSignedDocumentReader("app-id", "api-key")
|
||||
require.NoError(t, err)
|
||||
|
||||
transport := &weKnoraCloudPollTransport{}
|
||||
transport := &academyCloudPollTransport{}
|
||||
reader.client = &http.Client{Transport: transport}
|
||||
reader.initialPollInterval = 5 * time.Millisecond
|
||||
reader.maxPollInterval = 10 * time.Millisecond
|
||||
@@ -155,7 +155,7 @@ func TestWeKnoraCloudPollStopsAtConfiguredTimeout(t *testing.T) {
|
||||
assert.Greater(t, transport.polls.Load(), int64(1),
|
||||
"the job must actually be polled before the budget ends it")
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatalf("poll loop ignored WEKNORA_WEKNORACLOUD_TIMEOUT after %d polls", transport.polls.Load())
|
||||
t.Fatalf("poll loop ignored ACADEMY_ACADEMYCLOUD_TIMEOUT after %d polls", transport.polls.Load())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// Readers differ in where the parsing happens: in this process
|
||||
// (SimpleFormatReader, AnydocReader), in the docreader service over gRPC or
|
||||
// HTTP (GRPCDocumentReader, HTTPDocumentReader), or in a remote API (MinerU,
|
||||
// PaddleOCR-VL, WeKnora Cloud). They all return types.ReadResult, so the rest
|
||||
// PaddleOCR-VL, Academy Cloud). They all return types.ReadResult, so the rest
|
||||
// of the package — image resolution and storage, table normalization — is
|
||||
// shared regardless of which engine ran.
|
||||
package docparser
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
)
|
||||
|
||||
// EngineRegistration is what every locally registered parser engine provides:
|
||||
@@ -34,11 +34,11 @@ type ReaderDeps struct {
|
||||
Overrides map[string]string
|
||||
// Remote is the docreader client. Nil when the service is not connected.
|
||||
Remote interfaces.DocReader
|
||||
// WeKnoraCloudCredentials resolves the tenant's WeKnora Cloud
|
||||
// AcademyCloudCredentials resolves the tenant's Academy Cloud
|
||||
// credentials. It is a function rather than a value because resolving
|
||||
// them can hit the database, which most engines never need. Nil, or a
|
||||
// nil return, means the tenant has not configured them.
|
||||
WeKnoraCloudCredentials func(ctx context.Context) *types.WeKnoraCloudCredentials
|
||||
AcademyCloudCredentials func(ctx context.Context) *types.AcademyCloudCredentials
|
||||
}
|
||||
|
||||
// localEngines holds all locally registered parser engines, in registration
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/infrastructure/docparser/anydoc"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
"academy/internal/infrastructure/docparser/anydoc"
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
)
|
||||
|
||||
// stubRemote stands in for the docreader client. NewReader only ever hands it
|
||||
@@ -62,9 +62,9 @@ func TestNewReaderReportsDisconnectedDocReader(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewReaderRequiresWeKnoraCloudCredentials(t *testing.T) {
|
||||
_, err := NewReader(context.Background(), WeKnoraCloudEngineName, "docx", false, ReaderDeps{
|
||||
WeKnoraCloudCredentials: func(context.Context) *types.WeKnoraCloudCredentials { return nil },
|
||||
func TestNewReaderRequiresAcademyCloudCredentials(t *testing.T) {
|
||||
_, err := NewReader(context.Background(), AcademyCloudEngineName, "docx", false, ReaderDeps{
|
||||
AcademyCloudCredentials: func(context.Context) *types.AcademyCloudCredentials { return nil },
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("NewReader succeeded without credentials, want an error")
|
||||
|
||||
@@ -3,9 +3,9 @@ package docparser
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/infrastructure/docparser/anydoc"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/infrastructure/docparser/anydoc"
|
||||
"academy/internal/types"
|
||||
"academy/internal/utils"
|
||||
)
|
||||
|
||||
// Locally advertised parser formats must pass the shared import gate used by
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/infrastructure/docparser/anydoc"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
"academy/internal/infrastructure/docparser/anydoc"
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
)
|
||||
|
||||
// Engine names, as stored in knowledge base parser rules and shown in the UI.
|
||||
@@ -17,8 +17,8 @@ const (
|
||||
SimpleEngineName = "simple"
|
||||
// AnydocEngineName is the in-process anydoc office-document converter.
|
||||
AnydocEngineName = "anydoc"
|
||||
// WeKnoraCloudEngineName is the hosted WeKnora Cloud document reader.
|
||||
WeKnoraCloudEngineName = "weknoracloud"
|
||||
// AcademyCloudEngineName is the hosted Academy Cloud document reader.
|
||||
AcademyCloudEngineName = "academycloud"
|
||||
// MinerUEngineName is a self-hosted MinerU service.
|
||||
MinerUEngineName = "mineru"
|
||||
// MinerUCloudEngineName is the MinerU Cloud API.
|
||||
@@ -34,7 +34,7 @@ func init() {
|
||||
RegisterEngine(&builtinEngine{})
|
||||
RegisterEngine(&simpleEngine{})
|
||||
RegisterEngine(&anydocEngine{})
|
||||
RegisterEngine(&weKnoraCloudEngine{})
|
||||
RegisterEngine(&academyCloudEngine{})
|
||||
RegisterEngine(&mineruEngine{})
|
||||
RegisterEngine(&mineruCloudEngine{})
|
||||
RegisterEngine(&paddleOCRVLEngine{})
|
||||
@@ -156,37 +156,37 @@ func (e *anydocEngine) NewReader(_ context.Context, deps ReaderDeps) (interfaces
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// weknoracloud — Tenant-scoped WeKnoraCloud docreader with signed requests.
|
||||
// academycloud — Tenant-scoped AcademyCloud docreader with signed requests.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
type weKnoraCloudEngine struct{}
|
||||
type academyCloudEngine struct{}
|
||||
|
||||
func (e *weKnoraCloudEngine) Name() string { return WeKnoraCloudEngineName }
|
||||
func (e *academyCloudEngine) Name() string { return AcademyCloudEngineName }
|
||||
|
||||
func (e *weKnoraCloudEngine) Description() string { return "WeKnoraCloud document reader" }
|
||||
func (e *academyCloudEngine) Description() string { return "AcademyCloud document reader" }
|
||||
|
||||
func (e *weKnoraCloudEngine) FileTypes(_ bool) []string {
|
||||
func (e *academyCloudEngine) FileTypes(_ bool) []string {
|
||||
return []string{"docx", "doc", "pdf", "md", "markdown", "xlsx", "xls", "pptx", "ppt"}
|
||||
}
|
||||
|
||||
func (e *weKnoraCloudEngine) CheckAvailable(_ bool, overrides map[string]string) (bool, string) {
|
||||
if overrides["weknoracloud_app_id"] != "" {
|
||||
func (e *academyCloudEngine) CheckAvailable(_ bool, overrides map[string]string) (bool, string) {
|
||||
if overrides["academycloud_app_id"] != "" {
|
||||
return true, ""
|
||||
}
|
||||
return false, "WeKnora Cloud credentials not configured. Go to Settings → WeKnora Cloud to set up."
|
||||
return false, "Academy Cloud credentials not configured. Go to Settings → Academy Cloud to set up."
|
||||
}
|
||||
|
||||
func (e *weKnoraCloudEngine) NewReader(
|
||||
func (e *academyCloudEngine) NewReader(
|
||||
ctx context.Context, deps ReaderDeps,
|
||||
) (interfaces.DocReader, error) {
|
||||
if deps.WeKnoraCloudCredentials == nil {
|
||||
return nil, errEngineUnavailable(WeKnoraCloudEngineName, "no credential resolver configured")
|
||||
if deps.AcademyCloudCredentials == nil {
|
||||
return nil, errEngineUnavailable(AcademyCloudEngineName, "no credential resolver configured")
|
||||
}
|
||||
creds := deps.WeKnoraCloudCredentials(ctx)
|
||||
creds := deps.AcademyCloudCredentials(ctx)
|
||||
if creds == nil {
|
||||
return nil, errEngineUnavailable(WeKnoraCloudEngineName, "tenant credentials not configured")
|
||||
return nil, errEngineUnavailable(AcademyCloudEngineName, "tenant credentials not configured")
|
||||
}
|
||||
return NewWeKnoraCloudSignedDocumentReader(creds.AppID, creds.AppSecret)
|
||||
return NewAcademyCloudSignedDocumentReader(creds.AppID, creds.AppSecret)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
docclient "github.com/Tencent/WeKnora/docreader/client"
|
||||
"github.com/Tencent/WeKnora/docreader/proto"
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
docclient "academy/docreader/client"
|
||||
"academy/docreader/proto"
|
||||
"academy/internal/logger"
|
||||
"academy/internal/types"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"academy/internal/logger"
|
||||
)
|
||||
|
||||
// stringOr returns val (trimmed) if non-empty, otherwise fallback.
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
secutils "github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/logger"
|
||||
"academy/internal/types"
|
||||
secutils "academy/internal/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -31,11 +31,11 @@ import (
|
||||
_ "golang.org/x/image/bmp" // Register BMP decoding for image.Decode and DecodeConfig.
|
||||
_ "golang.org/x/image/webp" // Register WebP decoding for image.Decode and DecodeConfig.
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/searchutil"
|
||||
secutils "github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/searchutil"
|
||||
secutils "academy/internal/utils"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -1937,7 +1937,7 @@ func downloadImage(ctx context.Context, client *http.Client, remoteURL string) (
|
||||
return nil, "", fmt.Errorf("create request: %w", err)
|
||||
}
|
||||
// Some CDNs require a browser-like User-Agent.
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; WeKnora/1.0)")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Academy/1.0)")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
func TestResolveAndStoreRelativeHTMLImages(t *testing.T) {
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
@@ -367,7 +367,7 @@ func TestJsonToMarkdown_BOM(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestJsonToMarkdown_UnicodeContent(t *testing.T) {
|
||||
input := `{"名称": "WeKnora 知识库", "描述": "支持中文 JSON 🎉", "emoji": "🚀"}`
|
||||
input := `{"名称": "Academy 知识库", "描述": "支持中文 JSON 🎉", "emoji": "🚀"}`
|
||||
result, err := jsonToMarkdown([]byte(input))
|
||||
visualReport(t, "Unicode / Chinese / Emoji", input, result, err, []checkResult{
|
||||
check("no error", err == nil),
|
||||
@@ -499,8 +499,8 @@ func TestJsonToMarkdown_SingleElementArray(t *testing.T) {
|
||||
|
||||
func TestJsonToMarkdown_RealisticConfig(t *testing.T) {
|
||||
input := `{
|
||||
"app": {"name": "WeKnora", "version": "2.0.0", "debug": false},
|
||||
"database": {"host": "localhost", "port": 5432, "name": "weknora_db", "pool_size": 10},
|
||||
"app": {"name": "Academy", "version": "2.0.0", "debug": false},
|
||||
"database": {"host": "localhost", "port": 5432, "name": "academy_db", "pool_size": 10},
|
||||
"redis": {"host": "localhost", "port": 6379},
|
||||
"features": {"json_upload": true, "multimodel": true, "graph_extraction": false}
|
||||
}`
|
||||
@@ -509,7 +509,7 @@ func TestJsonToMarkdown_RealisticConfig(t *testing.T) {
|
||||
visualReport(t, "Realistic: App Config (fits in 1 block)", input, result, err, []checkResult{
|
||||
check("no error", err == nil),
|
||||
check("all blocks are valid JSON", allBlocksValidJSON(result)),
|
||||
check("contains 'WeKnora'", strings.Contains(result, "WeKnora")),
|
||||
check("contains 'Academy'", strings.Contains(result, "Academy")),
|
||||
check("contains 'database'", strings.Contains(result, "database")),
|
||||
check(fmt.Sprintf("single block (fits, got %d)", blocks), blocks == 1),
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ package docparser
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
type markdownImageTargetSpan struct {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
func TestScanMarkdownImageTargets(t *testing.T) {
|
||||
|
||||
@@ -15,16 +15,16 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/logger"
|
||||
"academy/internal/types"
|
||||
"academy/internal/utils"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultPollInterval = 3 * time.Second
|
||||
// defaultCloudTimeout bounds how long one batch is polled;
|
||||
// WEKNORA_MINERU_CLOUD_TIMEOUT overrides it for documents that take longer.
|
||||
// ACADEMY_MINERU_CLOUD_TIMEOUT overrides it for documents that take longer.
|
||||
defaultCloudTimeout = 600 * time.Second
|
||||
defaultBaseURL = "https://mineru.net/api/v4"
|
||||
)
|
||||
@@ -48,7 +48,7 @@ func NewMinerUCloudReader(overrides map[string]string) *MinerUCloudReader {
|
||||
return &MinerUCloudReader{
|
||||
apiKey: strings.TrimSpace(overrides["mineru_api_key"]),
|
||||
baseURL: defaultBaseURL,
|
||||
timeout: requestTimeoutFromEnv("WEKNORA_MINERU_CLOUD_TIMEOUT", defaultCloudTimeout),
|
||||
timeout: requestTimeoutFromEnv("ACADEMY_MINERU_CLOUD_TIMEOUT", defaultCloudTimeout),
|
||||
pollInterval: defaultPollInterval,
|
||||
model: stringOr(overrides["mineru_cloud_model"], "pipeline"),
|
||||
formulaEnable: parseBoolOr(overrides["mineru_cloud_enable_formula"], true),
|
||||
|
||||
@@ -17,12 +17,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/logger"
|
||||
"academy/internal/types"
|
||||
"academy/internal/utils"
|
||||
)
|
||||
|
||||
// defaultMinerUTimeout bounds one self-hosted parse; WEKNORA_MINERU_TIMEOUT
|
||||
// defaultMinerUTimeout bounds one self-hosted parse; ACADEMY_MINERU_TIMEOUT
|
||||
// overrides it for documents that take longer.
|
||||
const defaultMinerUTimeout = 1000 * time.Second // large docs can take a while
|
||||
|
||||
@@ -60,7 +60,7 @@ func NewMinerUReader(overrides map[string]string) *MinerUReader {
|
||||
|
||||
c := &MinerUReader{
|
||||
endpoint: strings.TrimRight(overrides["mineru_endpoint"], "/"),
|
||||
timeout: requestTimeoutFromEnv("WEKNORA_MINERU_TIMEOUT", defaultMinerUTimeout),
|
||||
timeout: requestTimeoutFromEnv("ACADEMY_MINERU_TIMEOUT", defaultMinerUTimeout),
|
||||
apiKey: strings.TrimSpace(overrides["mineru_server_api_key"]),
|
||||
tier: resolveMinerUTier(overrides["mineru_tier"]),
|
||||
backend: stringOr(overrides["mineru_model"], "pipeline"),
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/types"
|
||||
"academy/internal/utils"
|
||||
)
|
||||
|
||||
func TestNewMinerUReaderResolvesParseMethod(t *testing.T) {
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/sourceloc"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/sourceloc"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
// minerUBBoxScale is the coordinate range of content_list bounding boxes:
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
func TestMinerUTimeoutConfig(t *testing.T) {
|
||||
@@ -30,7 +30,7 @@ func TestMinerUTimeoutConfig(t *testing.T) {
|
||||
{"negative", "-1s", defaultMinerUTimeout},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Setenv("WEKNORA_MINERU_TIMEOUT", tt.value)
|
||||
t.Setenv("ACADEMY_MINERU_TIMEOUT", tt.value)
|
||||
assert.Equal(t, tt.want, NewMinerUReader(nil).timeout)
|
||||
})
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func TestMinerUReaderHonorsConfiguredTimeout(t *testing.T) {
|
||||
req := &types.ReadRequest{FileContent: []byte("%PDF"), FileName: "a.pdf", FileType: "pdf"}
|
||||
|
||||
t.Run("v1", func(t *testing.T) {
|
||||
t.Setenv("WEKNORA_MINERU_TIMEOUT", "200ms")
|
||||
t.Setenv("ACADEMY_MINERU_TIMEOUT", "200ms")
|
||||
statuses := make([]string, 1000)
|
||||
for i := range statuses {
|
||||
statuses[i] = "running"
|
||||
@@ -62,7 +62,7 @@ func TestMinerUReaderHonorsConfiguredTimeout(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("legacy", func(t *testing.T) {
|
||||
t.Setenv("WEKNORA_MINERU_TIMEOUT", "100ms")
|
||||
t.Setenv("ACADEMY_MINERU_TIMEOUT", "100ms")
|
||||
release := make(chan struct{})
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/v1/health" {
|
||||
@@ -88,17 +88,17 @@ func TestMinerUReaderHonorsConfiguredTimeout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMinerUCloudTimeoutConfig(t *testing.T) {
|
||||
t.Setenv("WEKNORA_MINERU_CLOUD_TIMEOUT", "")
|
||||
t.Setenv("ACADEMY_MINERU_CLOUD_TIMEOUT", "")
|
||||
assert.Equal(t, defaultCloudTimeout, NewMinerUCloudReader(nil).timeout)
|
||||
t.Setenv("WEKNORA_MINERU_CLOUD_TIMEOUT", "45m")
|
||||
t.Setenv("ACADEMY_MINERU_CLOUD_TIMEOUT", "45m")
|
||||
assert.Equal(t, 45*time.Minute, NewMinerUCloudReader(nil).timeout)
|
||||
t.Setenv("WEKNORA_MINERU_CLOUD_TIMEOUT", "0s")
|
||||
t.Setenv("ACADEMY_MINERU_CLOUD_TIMEOUT", "0s")
|
||||
assert.Equal(t, defaultCloudTimeout, NewMinerUCloudReader(nil).timeout)
|
||||
}
|
||||
|
||||
func TestMinerUCloudPollStopsAtConfiguredTimeout(t *testing.T) {
|
||||
allowLoopbackSSRF(t)
|
||||
t.Setenv("WEKNORA_MINERU_CLOUD_TIMEOUT", "200ms")
|
||||
t.Setenv("ACADEMY_MINERU_CLOUD_TIMEOUT", "200ms")
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = io.WriteString(w, `{"code":0,"data":{"extract_result":[{"state":"running"}]}}`)
|
||||
|
||||
@@ -16,9 +16,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/logger"
|
||||
"academy/internal/types"
|
||||
"academy/internal/utils"
|
||||
)
|
||||
|
||||
// MinerU 4.0 replaced the synchronous /file_parse endpoint with the V1 API:
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/types"
|
||||
"academy/internal/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -13,10 +13,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/sourceloc"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/logger"
|
||||
"academy/internal/sourceloc"
|
||||
"academy/internal/types"
|
||||
"academy/internal/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -24,8 +24,8 @@ const (
|
||||
paddleOCRVLCloudDefaultModel = "PaddleOCR-VL-1.6"
|
||||
paddleOCRVLCloudPollInterval = 5 * time.Second
|
||||
// paddleOCRVLCloudTimeout bounds how long one job is polled;
|
||||
// WEKNORA_PADDLEOCR_VL_CLOUD_TIMEOUT overrides it for documents that take
|
||||
// longer, mirroring WEKNORA_MINERU_CLOUD_TIMEOUT on the MinerU cloud reader.
|
||||
// ACADEMY_PADDLEOCR_VL_CLOUD_TIMEOUT overrides it for documents that take
|
||||
// longer, mirroring ACADEMY_MINERU_CLOUD_TIMEOUT on the MinerU cloud reader.
|
||||
paddleOCRVLCloudTimeout = 600 * time.Second
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ func NewPaddleOCRVLCloudReader(overrides map[string]string) *PaddleOCRVLCloudRea
|
||||
model: stringOr(overrides["paddleocr_vl_cloud_model"], paddleOCRVLCloudDefaultModel),
|
||||
useSeal: parseBoolOr(overrides["paddleocr_vl_cloud_use_seal_recognition"], true),
|
||||
useChart: parseBoolOr(overrides["paddleocr_vl_cloud_use_chart_recognition"], false),
|
||||
timeout: requestTimeoutFromEnv("WEKNORA_PADDLEOCR_VL_CLOUD_TIMEOUT", paddleOCRVLCloudTimeout),
|
||||
timeout: requestTimeoutFromEnv("ACADEMY_PADDLEOCR_VL_CLOUD_TIMEOUT", paddleOCRVLCloudTimeout),
|
||||
pollInterval: paddleOCRVLCloudPollInterval,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/logger"
|
||||
"github.com/Tencent/WeKnora/internal/sourceloc"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/logger"
|
||||
"academy/internal/sourceloc"
|
||||
"academy/internal/types"
|
||||
"academy/internal/utils"
|
||||
)
|
||||
|
||||
const defaultPaddleOCRVLTimeout = 1000 * time.Second // large scanned PDFs can take a while
|
||||
@@ -36,7 +36,7 @@ type PaddleOCRVLReader struct {
|
||||
// NewPaddleOCRVLReader creates a reader from ParserEngineOverrides.
|
||||
func NewPaddleOCRVLReader(overrides map[string]string) *PaddleOCRVLReader {
|
||||
return &PaddleOCRVLReader{
|
||||
timeout: requestTimeoutFromEnv("WEKNORA_PADDLEOCR_VL_TIMEOUT", defaultPaddleOCRVLTimeout),
|
||||
timeout: requestTimeoutFromEnv("ACADEMY_PADDLEOCR_VL_TIMEOUT", defaultPaddleOCRVLTimeout),
|
||||
endpoint: strings.TrimRight(overrides["paddleocr_vl_endpoint"], "/"),
|
||||
useSeal: parseBoolOr(overrides["paddleocr_vl_use_seal_recognition"], true),
|
||||
useChart: parseBoolOr(overrides["paddleocr_vl_use_chart_recognition"], false),
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/types"
|
||||
"academy/internal/utils"
|
||||
)
|
||||
|
||||
func TestPaddleOCRVLTimeoutConfig(t *testing.T) {
|
||||
@@ -32,9 +32,9 @@ func TestPaddleOCRVLTimeoutConfig(t *testing.T) {
|
||||
{"overflow", "999999999999999999999h", 1000 * time.Second},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Setenv("WEKNORA_PADDLEOCR_VL_TIMEOUT", tt.value)
|
||||
t.Setenv("ACADEMY_PADDLEOCR_VL_TIMEOUT", tt.value)
|
||||
if tt.name == "unset" {
|
||||
if err := os.Unsetenv("WEKNORA_PADDLEOCR_VL_TIMEOUT"); err != nil {
|
||||
if err := os.Unsetenv("ACADEMY_PADDLEOCR_VL_TIMEOUT"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -53,9 +53,9 @@ func TestPaddleOCRVLReadTimeout(t *testing.T) {
|
||||
for _, mode := range []string{"success", "http timeout", "parent deadline", "parent cancellation"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
t.Setenv("SSRF_WHITELIST", "127.0.0.1,localhost")
|
||||
t.Setenv("WEKNORA_PADDLEOCR_VL_TIMEOUT", "10s")
|
||||
t.Setenv("ACADEMY_PADDLEOCR_VL_TIMEOUT", "10s")
|
||||
if mode == "http timeout" {
|
||||
t.Setenv("WEKNORA_PADDLEOCR_VL_TIMEOUT", "100ms")
|
||||
t.Setenv("ACADEMY_PADDLEOCR_VL_TIMEOUT", "100ms")
|
||||
}
|
||||
arrived := make(chan struct{})
|
||||
release := make(chan struct{})
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/sourceloc"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/internal/sourceloc"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
// paddleOCRVLPage is one page of a PaddleOCR-VL layout-parsing result.
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
secutils "github.com/Tencent/WeKnora/internal/utils"
|
||||
"academy/internal/types"
|
||||
secutils "academy/internal/utils"
|
||||
)
|
||||
|
||||
// remoteImageServer serves a valid PNG for every request and counts the hits so
|
||||
|
||||
@@ -3,8 +3,8 @@ package docparser
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Tencent/WeKnora/docreader/proto"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/docreader/proto"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
// wireSourceBlock is the transport shape of a source block: a markdown range
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/Tencent/WeKnora/docreader/proto"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"academy/docreader/proto"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
const minerUContentListJSON = `[
|
||||
|
||||
Reference in new issue
Block a user