-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.d.ts
More file actions
202 lines (173 loc) · 5.6 KB
/
index.d.ts
File metadata and controls
202 lines (173 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* TypeScript definitions for Extract2MD
*/
// Core configuration interfaces
export interface OCRConfig {
language?: string;
oem?: number;
psm?: number;
workerPath?: string;
corePath?: string;
langPath?: string;
options?: any;
}
export interface WebLLMConfig {
modelId?: string;
temperature?: number;
maxTokens?: number;
streamingEnabled?: boolean;
customModel?: CustomModelConfig;
options?: any;
}
export interface PostProcessRule {
find: RegExp | string;
replace: string;
}
export interface ProgressReport {
stage: string;
message: string;
currentPage?: number;
totalPages?: number;
progress?: number;
usage?: any;
error?: any;
}
export interface TesseractConfig {
workerPath?: string;
corePath?: string;
langPath?: string;
language?: string;
options?: any;
}
export interface CustomModelConfig {
model: string;
model_id: string;
model_lib: string;
required_features?: string[];
overrides?: any;
}
export interface LLMConfig {
model?: string;
customModel?: CustomModelConfig;
options?: {
temperature?: number;
maxTokens?: number;
[key: string]: any;
};
}
export interface SystemPromptsConfig {
singleExtraction?: string;
combinedExtraction?: string;
}
export interface ProcessingConfig {
splitPascalCase?: boolean;
pdfRenderScale?: number;
postProcessRules?: PostProcessRule[];
}
export interface Extract2MDConfig {
pdfJsWorkerSrc?: string;
tesseract?: TesseractConfig;
llm?: LLMConfig;
systemPrompts?: SystemPromptsConfig;
processing?: ProcessingConfig;
progressCallback?: (report: ProgressReport) => void;
}
export interface WebLLMEngineConfig {
progressCallback?: (report: ProgressReport) => void;
defaultModel?: string;
customModelConfig?: CustomModelConfig;
}
export interface GenerationOptions {
temperature?: number;
maxTokens?: number;
[key: string]: any;
}
export interface ModelInfo {
isInitialized: boolean;
currentModelId: string | null;
isReady: boolean;
}
export interface ValidationResult {
isValid: boolean;
issues: string[];
}
export class WebLLMEngine {
constructor(config?: WebLLMEngineConfig);
initialize(modelId?: string | null, modelConfig?: any): Promise<void>;
generate(prompt: string, options?: GenerationOptions): Promise<string>;
generateStream(
prompt: string,
options?: GenerationOptions,
onChunk?: (chunk: string, fullResponse: string) => void
): Promise<string>;
isReady(): boolean;
getModelInfo(): ModelInfo;
cleanup(): Promise<void>;
}
export class OutputParser {
constructor();
parse(rawOutput: string): string;
removeThinkingBlocks(text: string): string;
applyCleanupPatterns(text: string): string;
ensureMarkdownStructure(text: string): string;
extractMarkdownContent(text: string): string;
validateMarkdown(text: string): ValidationResult;
applyCustomRules(text: string, customRules?: PostProcessRule[]): string;
}
export class SystemPrompts {
static getSingleExtractionPrompt(customization?: string): string;
static getCombinedExtractionPrompt(customization?: string): string;
static getSingleExtractionUserPrompt(extractedText: string): string;
static getCombinedExtractionUserPrompt(quickExtraction: string, ocrExtraction: string): string;
static buildSystemPrompt(scenarioType: 'single' | 'combined', customization?: string): string;
static buildUserPrompt(scenarioType: 'single' | 'combined', ...extractionResults: string[]): string;
static getThinkingEnabledPrompt(basePrompt: string): string;
}
export class ConfigValidator {
static getDefaultConfig(): Extract2MDConfig;
static validate(config?: any): Extract2MDConfig;
static validateTesseractConfig(tesseractConfig: any): void;
static validateLLMConfig(llmConfig: any): void;
static validateCustomModel(customModel: any): void;
static validateLLMOptions(options: any): void;
static validateProcessingConfig(processingConfig: any): void;
static validateSystemPrompts(systemPrompts: any): void;
static deepMerge(target: any, source: any): any;
static isObject(value: any): boolean;
static fromJSON(jsonString: string): Extract2MDConfig;
static getSchema(): any;
}
export class Extract2MDConverter {
constructor(config?: Extract2MDConfig);
// Scenario-specific static methods
static quickConvertOnly(pdfFile: File, options?: Extract2MDConfig): Promise<string>;
static highAccuracyConvertOnly(pdfFile: File, options?: Extract2MDConfig): Promise<string>;
static quickConvertWithLLM(pdfFile: File, options?: Extract2MDConfig): Promise<string>;
static highAccuracyConvertWithLLM(pdfFile: File, options?: Extract2MDConfig): Promise<string>;
static combinedConvertWithLLM(pdfFile: File, options?: Extract2MDConfig): Promise<string>;
}
// Legacy support - keeping the old interface available
export interface Extract2MDOptions extends Extract2MDConfig {}
export interface ConvertOptions {
postProcessRules?: PostProcessRule[];
}
export interface HighAccuracyConvertOptions extends ConvertOptions {
tesseractLanguage?: string;
tesseractOptions?: any;
pdfRenderScale?: number;
}
export interface LLMRewriteOptions {
llmModel?: string;
llmPromptTemplate?: (text: string) => string;
chatOpts?: any;
}
// Legacy class for backwards compatibility
export class LegacyExtract2MDConverter {
constructor(options?: Extract2MDOptions);
quickConvert(pdfFile: File, options?: ConvertOptions): Promise<string>;
highAccuracyConvert(pdfFile: File, options?: HighAccuracyConvertOptions): Promise<string>;
llmRewrite(textToRewrite: string, options?: LLMRewriteOptions): Promise<string>;
unloadLLM(): Promise<void>;
}
// Default export
export default Extract2MDConverter;