Files
ragflow/web/src/hooks/parser-config-utils.ts
Jack c81081f8ef Refactor: Doc change parser (#14327)
### What problem does this PR solve?

Before migration
Web API: POST /v1/document/change_parser
HTTP API: PATCH /api/v1/datasets/<dataset_id>/documents

After consolidation, Restful API
PATCH /api/v1/datasets/<dataset_id>/documents

### Type of change

- [x] Refactoring
2026-04-27 23:42:57 +08:00

91 lines
2.0 KiB
TypeScript

/**
* Utility functions for extracting parser and raptor config extensions.
* These functions extract known fields from parser/raptor config objects
* and merge unknown fields into the `ext` field for flexible configuration.
*/
/**
* Extracts Raptor configuration with extra fields merged into ext.
* @param raptorConfig - The raptor configuration object
* @returns Processed raptor config with extra fields in ext
*/
export const extractRaptorConfigExt = (
raptorConfig: Record<string, any> | undefined,
) => {
if (!raptorConfig) return raptorConfig;
const {
use_raptor,
prompt,
max_token,
threshold,
max_cluster,
random_seed,
auto_disable_for_structured_data,
ext,
...raptorExt
} = raptorConfig;
return {
use_raptor,
prompt,
max_token,
threshold,
max_cluster,
random_seed,
auto_disable_for_structured_data,
ext: { ...ext, ...raptorExt },
};
};
/**
* Extracts Parser configuration with extra fields merged into ext.
* @param parserConfig - The parser configuration object
* @returns Processed parser config with extra fields in ext
*/
export const extractParserConfigExt = (
parserConfig: Record<string, any> | undefined,
) => {
if (!parserConfig) return parserConfig;
const {
auto_keywords,
auto_questions,
chunk_token_num,
delimiter,
graphrag,
html4excel,
layout_recognize,
raptor,
tag_kb_ids,
topn_tags,
filename_embd_weight,
task_page_size,
pages,
children_delimiter,
use_parent_child,
enable_children,
ext,
...parserExt
} = parserConfig;
return {
auto_keywords,
auto_questions,
chunk_token_num,
delimiter,
graphrag,
html4excel,
layout_recognize,
raptor: extractRaptorConfigExt(raptor),
tag_kb_ids,
topn_tags,
filename_embd_weight,
task_page_size,
pages,
parent_child: enable_children
? {
children_delimiter,
use_parent_child: use_parent_child ?? enable_children,
}
: undefined,
ext: { ...ext, ...parserExt },
};
};