@heripo/document-processor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.ko.md +332 -0
- package/README.md +332 -0
- package/dist/index.cjs +4325 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1420 -0
- package/dist/index.d.ts +1420 -0
- package/dist/index.js +4262 -0
- package/dist/index.js.map +1 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Support. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 heripo lab
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.ko.md
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# @heripo/document-processor
|
|
2
|
+
|
|
3
|
+
> LLM 기반 문서 구조 분석 및 처리 라이브러리
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@heripo/document-processor)
|
|
6
|
+
[](https://nodejs.org/)
|
|
7
|
+

|
|
8
|
+
[](../../LICENSE)
|
|
9
|
+
|
|
10
|
+
[English](./README.md) | **한국어**
|
|
11
|
+
|
|
12
|
+
> **참고**: 프로젝트 전체 개요, 설치 방법, 로드맵은 [루트 README](../../README.ko.md)를 먼저 확인해 주세요.
|
|
13
|
+
|
|
14
|
+
`@heripo/document-processor`는 DoclingDocument를 ProcessedDocument로 변환하여 LLM 분석에 최적화된 형태로 만드는 라이브러리입니다.
|
|
15
|
+
|
|
16
|
+
## 목차
|
|
17
|
+
|
|
18
|
+
- [주요 기능](#주요-기능)
|
|
19
|
+
- [설치](#설치)
|
|
20
|
+
- [사용법](#사용법)
|
|
21
|
+
- [처리 파이프라인](#처리-파이프라인)
|
|
22
|
+
- [API 문서](#api-문서)
|
|
23
|
+
- [라이선스](#라이선스)
|
|
24
|
+
|
|
25
|
+
## 주요 기능
|
|
26
|
+
|
|
27
|
+
- **목차 추출**: 규칙 기반 + LLM 폴백으로 목차 자동 인식
|
|
28
|
+
- **계층 구조**: 장/절/소절 계층 구조 자동 생성
|
|
29
|
+
- **페이지 매핑**: Vision LLM을 활용한 실제 페이지 번호 매핑
|
|
30
|
+
- **캡션 파싱**: 이미지 및 테이블 캡션 자동 파싱
|
|
31
|
+
- **LLM 유연성**: OpenAI, Anthropic, Google 등 다양한 LLM 지원
|
|
32
|
+
- **Fallback 재시도**: 실패 시 자동으로 fallback 모델로 재시도
|
|
33
|
+
|
|
34
|
+
## 설치
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# npm으로 설치
|
|
38
|
+
npm install @heripo/document-processor @heripo/model
|
|
39
|
+
|
|
40
|
+
# pnpm으로 설치
|
|
41
|
+
pnpm add @heripo/document-processor @heripo/model
|
|
42
|
+
|
|
43
|
+
# yarn으로 설치
|
|
44
|
+
yarn add @heripo/document-processor @heripo/model
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
추가로 LLM 프로파이더의 SDK가 필요합니다:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Vercel AI SDK와 프로파이더 패키지
|
|
51
|
+
npm install ai @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 사용법
|
|
55
|
+
|
|
56
|
+
### 기본 사용법
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
60
|
+
import { DocumentProcessor } from '@heripo/document-processor';
|
|
61
|
+
import { Logger } from '@heripo/logger';
|
|
62
|
+
|
|
63
|
+
const logger = Logger(...);
|
|
64
|
+
|
|
65
|
+
// 기본 사용 - fallback 모델만 지정
|
|
66
|
+
const processor = new DocumentProcessor({
|
|
67
|
+
logger,
|
|
68
|
+
fallbackModel: anthropic('claude-opus-4-5'),
|
|
69
|
+
textCleanerBatchSize: 10,
|
|
70
|
+
captionParserBatchSize: 5,
|
|
71
|
+
captionValidatorBatchSize: 5,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// 문서 처리
|
|
75
|
+
const processedDoc = await processor.process(
|
|
76
|
+
doclingDocument, // PDF 파서 출력
|
|
77
|
+
'report-001', // 리포트 ID
|
|
78
|
+
outputPath, // 이미지/페이지가 있는 디렉토리
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// 결과 사용
|
|
82
|
+
console.log('목차:', processedDoc.chapters);
|
|
83
|
+
console.log('이미지:', processedDoc.images);
|
|
84
|
+
console.log('표:', processedDoc.tables);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 고급 사용법 - 컴포넌트별 모델 지정
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
91
|
+
import { openai } from '@ai-sdk/openai';
|
|
92
|
+
|
|
93
|
+
const processor = new DocumentProcessor({
|
|
94
|
+
logger,
|
|
95
|
+
// Fallback 모델 (실패 시 재시도용)
|
|
96
|
+
fallbackModel: anthropic('claude-opus-4-5'),
|
|
97
|
+
|
|
98
|
+
// 컴포넌트별 모델 지정
|
|
99
|
+
pageRangeParserModel: openai('gpt-5.1'), // Vision 필요
|
|
100
|
+
tocExtractorModel: openai('gpt-5.1'), // 구조화 출력
|
|
101
|
+
validatorModel: openai('gpt-5.2'), // 간단한 검증
|
|
102
|
+
visionTocExtractorModel: openai('gpt-5.1'), // Vision 필요
|
|
103
|
+
captionParserModel: openai('gpt-5-mini'), // 캡션 파싱
|
|
104
|
+
|
|
105
|
+
// 배치 크기 설정
|
|
106
|
+
textCleanerBatchSize: 20, // 동기 처리 (크게 가능)
|
|
107
|
+
captionParserBatchSize: 10, // LLM 호출 (중간)
|
|
108
|
+
captionValidatorBatchSize: 10, // LLM 호출 (중간)
|
|
109
|
+
|
|
110
|
+
// 재시도 설정
|
|
111
|
+
maxRetries: 3,
|
|
112
|
+
enableFallbackRetry: true, // fallback 모델로 자동 재시도
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const processedDoc = await processor.process(
|
|
116
|
+
doclingDocument,
|
|
117
|
+
'report-001',
|
|
118
|
+
outputPath,
|
|
119
|
+
);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## 처리 파이프라인
|
|
123
|
+
|
|
124
|
+
DocumentProcessor는 다음 5단계 파이프라인으로 문서를 처리합니다:
|
|
125
|
+
|
|
126
|
+
### 1. 텍스트 정리 (TextCleaner)
|
|
127
|
+
|
|
128
|
+
- Unicode 정규화 (NFC)
|
|
129
|
+
- 공백 정리
|
|
130
|
+
- 유효하지 않은 텍스트 필터링 (숫자만 있는 텍스트, 빈 텍스트)
|
|
131
|
+
|
|
132
|
+
### 2. 페이지 범위 매핑 (PageRangeParser - Vision LLM)
|
|
133
|
+
|
|
134
|
+
- 페이지 이미지에서 실제 페이지 번호 추출
|
|
135
|
+
- PDF 페이지와 문서 논리적 페이지 매핑
|
|
136
|
+
- 스캔 오류로 인한 페이지 번호 불일치 처리
|
|
137
|
+
|
|
138
|
+
### 3. TOC 추출 (5단계 파이프라인)
|
|
139
|
+
|
|
140
|
+
#### Stage 1: TocFinder (규칙 기반)
|
|
141
|
+
|
|
142
|
+
- 키워드 검색 (목차, 차례, Contents, Table of Contents)
|
|
143
|
+
- 구조 분석 (페이지 번호 패턴이 있는 리스트/테이블)
|
|
144
|
+
- 연속 마커가 있는 다중 페이지 TOC 감지
|
|
145
|
+
|
|
146
|
+
#### Stage 2: MarkdownConverter
|
|
147
|
+
|
|
148
|
+
- 그룹 → 들여쓰기 리스트 형식
|
|
149
|
+
- 테이블 → 마크다운 테이블 형식
|
|
150
|
+
- LLM 처리를 위한 계층 구조 보존
|
|
151
|
+
|
|
152
|
+
#### Stage 3: TocContentValidator (LLM 검증)
|
|
153
|
+
|
|
154
|
+
- 추출된 내용이 실제 TOC인지 검증
|
|
155
|
+
- 신뢰도 점수 및 이유 반환
|
|
156
|
+
|
|
157
|
+
#### Stage 4: VisionTocExtractor (Vision LLM 폴백)
|
|
158
|
+
|
|
159
|
+
- 규칙 기반 추출 실패 또는 검증 실패 시 사용
|
|
160
|
+
- 페이지 이미지에서 직접 TOC 추출
|
|
161
|
+
|
|
162
|
+
#### Stage 5: TocExtractor (LLM 구조화)
|
|
163
|
+
|
|
164
|
+
- 계층적 TocEntry[] 추출 (title, level, pageNo)
|
|
165
|
+
- 중첩된 섹션을 위한 재귀적 children 구조
|
|
166
|
+
|
|
167
|
+
### 4. 리소스 변환
|
|
168
|
+
|
|
169
|
+
- **이미지**: CaptionParser로 캡션 추출 및 파싱
|
|
170
|
+
- **테이블**: 그리드 데이터 변환 및 캡션 파싱
|
|
171
|
+
- **캡션 검증**: CaptionValidator로 파싱 결과 검증
|
|
172
|
+
|
|
173
|
+
### 5. 챕터 변환 (ChapterConverter)
|
|
174
|
+
|
|
175
|
+
- TOC 기반 챕터 트리 구성
|
|
176
|
+
- Chapter 계층 생성
|
|
177
|
+
- 페이지 범위별로 텍스트 블록을 챕터에 연결
|
|
178
|
+
- 이미지/테이블 ID를 적절한 챕터에 연결
|
|
179
|
+
- Fallback: TOC가 비어있을 때 단일 "Document" 챕터 생성
|
|
180
|
+
|
|
181
|
+
## API 문서
|
|
182
|
+
|
|
183
|
+
### DocumentProcessor 클래스
|
|
184
|
+
|
|
185
|
+
#### 생성자 옵션
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
interface DocumentProcessorOptions {
|
|
189
|
+
logger: Logger; // 로거 인스턴스 (필수)
|
|
190
|
+
|
|
191
|
+
// LLM 모델 설정
|
|
192
|
+
fallbackModel: LanguageModel; // Fallback 모델 (필수)
|
|
193
|
+
pageRangeParserModel?: LanguageModel; // 페이지 범위 파서용
|
|
194
|
+
tocExtractorModel?: LanguageModel; // TOC 추출용
|
|
195
|
+
validatorModel?: LanguageModel; // 검증용
|
|
196
|
+
visionTocExtractorModel?: LanguageModel; // Vision TOC 추출용
|
|
197
|
+
captionParserModel?: LanguageModel; // 캡션 파서용
|
|
198
|
+
|
|
199
|
+
// 배치 처리 설정
|
|
200
|
+
textCleanerBatchSize?: number; // 텍스트 정리 (기본값: 10)
|
|
201
|
+
captionParserBatchSize?: number; // 캡션 파싱 (기본값: 5)
|
|
202
|
+
captionValidatorBatchSize?: number; // 캡션 검증 (기본값: 5)
|
|
203
|
+
|
|
204
|
+
// 재시도 설정
|
|
205
|
+
maxRetries?: number; // LLM API 재시도 횟수 (기본값: 3)
|
|
206
|
+
enableFallbackRetry?: boolean; // Fallback 재시도 활성화 (기본값: true)
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### 메서드
|
|
211
|
+
|
|
212
|
+
##### `process(doclingDoc, reportId, outputPath): Promise<ProcessedDocument>`
|
|
213
|
+
|
|
214
|
+
DoclingDocument를 ProcessedDocument로 변환합니다.
|
|
215
|
+
|
|
216
|
+
**파라미터:**
|
|
217
|
+
|
|
218
|
+
- `doclingDoc` (DoclingDocument): PDF 파서의 출력
|
|
219
|
+
- `reportId` (string): 리포트 ID
|
|
220
|
+
- `outputPath` (string): 이미지/페이지가 있는 출력 디렉토리
|
|
221
|
+
|
|
222
|
+
**반환값:**
|
|
223
|
+
|
|
224
|
+
- `Promise<ProcessedDocument>`: 처리된 문서
|
|
225
|
+
|
|
226
|
+
### Fallback 재시도 메커니즘
|
|
227
|
+
|
|
228
|
+
`enableFallbackRetry: true`로 설정하면, LLM 컴포넌트가 실패할 때 자동으로 fallbackModel로 재시도합니다:
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const processor = new DocumentProcessor({
|
|
232
|
+
logger,
|
|
233
|
+
fallbackModel: anthropic('claude-opus-4-5'), // 재시도용
|
|
234
|
+
pageRangeParserModel: openai('gpt-5.2'), // 첫 시도
|
|
235
|
+
enableFallbackRetry: true, // 실패 시 fallback 사용
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// pageRangeParserModel이 실패하면 자동으로 fallbackModel로 재시도
|
|
239
|
+
const result = await processor.process(doc, 'id', 'path');
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### 배치 크기 파라미터
|
|
243
|
+
|
|
244
|
+
- **textCleanerBatchSize**: 동기 텍스트 정규화 및 필터링 배치 크기. 로컬 처리이므로 큰 값 가능
|
|
245
|
+
- **captionParserBatchSize**: LLM 기반 캡션 파싱 배치 크기. API 요청 동시성 및 비용 관리를 위해 작은 값 사용
|
|
246
|
+
- **captionValidatorBatchSize**: LLM 기반 캡션 검증 배치 크기. 검증 요청 동시성 제한을 위해 작은 값 사용
|
|
247
|
+
|
|
248
|
+
## 에러 처리
|
|
249
|
+
|
|
250
|
+
### TocExtractError
|
|
251
|
+
|
|
252
|
+
TOC 추출 실패 시 발생하는 에러들:
|
|
253
|
+
|
|
254
|
+
- `TocNotFoundError`: 문서에서 TOC를 찾을 수 없음
|
|
255
|
+
- `TocParseError`: LLM 응답 파싱 실패
|
|
256
|
+
- `TocValidationError`: TOC 검증 실패
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
try {
|
|
260
|
+
const result = await processor.process(doc, 'id', 'path');
|
|
261
|
+
} catch (error) {
|
|
262
|
+
if (error instanceof TocNotFoundError) {
|
|
263
|
+
console.log('TOC를 찾을 수 없습니다. 단일 챕터로 처리됩니다.');
|
|
264
|
+
} else if (error instanceof TocParseError) {
|
|
265
|
+
console.error('TOC 파싱 실패:', error.message);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### PageRangeParseError
|
|
271
|
+
|
|
272
|
+
페이지 범위 파싱 실패:
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
import { PageRangeParseError } from '@heripo/document-processor';
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### CaptionParseError & CaptionValidationError
|
|
279
|
+
|
|
280
|
+
캡션 파싱/검증 실패:
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import {
|
|
284
|
+
CaptionParseError,
|
|
285
|
+
CaptionValidationError,
|
|
286
|
+
} from '@heripo/document-processor';
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## 토큰 사용량 추적
|
|
290
|
+
|
|
291
|
+
주요 LLM 컴포넌트는 토큰 사용량을 반환합니다:
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
// PageRangeParser
|
|
295
|
+
const { pageRangeMap, tokenUsage } = await pageRangeParser.parse(doc);
|
|
296
|
+
console.log('토큰 사용:', tokenUsage);
|
|
297
|
+
|
|
298
|
+
// TocExtractor
|
|
299
|
+
const { entries, tokenUsage } = await tocExtractor.extract(markdown);
|
|
300
|
+
console.log('토큰 사용:', tokenUsage);
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## 관련 패키지
|
|
304
|
+
|
|
305
|
+
- [@heripo/pdf-parser](../pdf-parser) - PDF 파싱 및 OCR
|
|
306
|
+
- [@heripo/model](../model) - 데이터 모델 및 타입 정의
|
|
307
|
+
|
|
308
|
+
## 라이선스
|
|
309
|
+
|
|
310
|
+
이 패키지는 [Apache License 2.0](../../LICENSE) 라이선스 하에 배포됩니다.
|
|
311
|
+
|
|
312
|
+
## 기여하기
|
|
313
|
+
|
|
314
|
+
기여는 언제나 환영합니다! [기여 가이드](../../CONTRIBUTING.ko.md)를 참고하세요.
|
|
315
|
+
|
|
316
|
+
## 이슈 및 지원
|
|
317
|
+
|
|
318
|
+
- **버그 리포트**: [GitHub Issues](https://github.com/heripo-lab/heripo-engine/issues)
|
|
319
|
+
- **토론**: [GitHub Discussions](https://github.com/heripo-lab/heripo-engine/discussions)
|
|
320
|
+
|
|
321
|
+
## 프로젝트 전체 정보
|
|
322
|
+
|
|
323
|
+
이 패키지에서 다루지 않는 프로젝트 전체 정보는 [루트 README](../../README.ko.md)에서 확인하세요:
|
|
324
|
+
|
|
325
|
+
- **인용 및 출처 표기**: 학술 인용(BibTeX) 및 출처 표기 방법
|
|
326
|
+
- **기여 가이드라인**: 개발 가이드라인, 커밋 규칙, PR 절차
|
|
327
|
+
- **커뮤니티**: 이슈 트래커, 토론, 보안 정책
|
|
328
|
+
- **로드맵**: 프로젝트 개발 계획
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
**heripo lab** | [GitHub](https://github.com/heripo-lab) | [heripo engine](https://github.com/heripo-lab/heripo-engine)
|