index.tsx
Overview
This file, index.tsx, defines a React functional component named ParseConfiguration used in a knowledge configuration context. The component renders a dynamic form interface that allows users to configure parser options, specifically for a parser type referred to as "raptor". It includes various controls such as switches, sliders, input numbers, and text areas to customize parsing behavior.
Additionally, the file exports utility constants and functions that determine whether certain parser configurations or UI elements should be displayed, based on the type of document parser selected.
Key features of the file:
Conditional rendering of parser configuration options based on parser type.
User interface for configuring parameters such as prompt texts, token limits, thresholds, clustering, and random seeds.
Integration with localization (i18n) for user-facing labels and tooltips.
Utility functions to exclude specific parser types from showing certain UI elements.
Exported Constants and Functions
excludedParseMethods: DocumentParserType[]
An array listing document parser types for which the "raptor" parse configuration should not be shown.
Values included:
DocumentParserType.TableDocumentParserType.ResumeDocumentParserType.OneDocumentParserType.PictureDocumentParserType.KnowledgeGraphDocumentParserType.QaDocumentParserType.Tag
showRaptorParseConfiguration(parserId: DocumentParserType | undefined): boolean
Determines whether the "raptor" parse configuration UI should be shown for a given parser ID.
Parameters:
parserId(DocumentParserType | undefined): The parser type identifier.
Returns:
trueif the parser type is not inexcludedParseMethods.falseotherwise.
Usage example:
if (showRaptorParseConfiguration(currentParserId)) { return <ParseConfiguration />; }
excludedTagParseMethods: DocumentParserType[]
An array listing document parser types for which tag items should not be shown.
Values included:
DocumentParserType.TableDocumentParserType.KnowledgeGraphDocumentParserType.Tag
showTagItems(parserId: DocumentParserType): boolean
Determines whether tag items should be displayed for a given parser ID.
Parameters:
parserId(DocumentParserType): The parser type identifier.
Returns:
trueif the parser type is not inexcludedTagParseMethods.falseotherwise.
Component: ParseConfiguration
Description
ParseConfiguration is a React functional component that renders a form section dedicated to configuring the "raptor" parser settings. It integrates with Ant Design's form system (Form.useFormInstance()) and a translation hook (useTranslate) for localization.
The form includes controls to enable or disable the raptor parser and, when enabled, display and manipulate various parameters such as prompts, token limits, thresholds, cluster sizes, and random seed values.
Usage
This component is intended to be used within a larger form managing document parser configurations. It conditionally shows fields depending on whether the "raptor" parser is enabled.
import ParseConfiguration from './index.tsx';
// Inside a parent form
<Form>
{/* Other form items */}
<ParseConfiguration />
</Form>
Internal Methods
handleGenerate()
Purpose: Generates a random seed value between 0 and 10,000 and sets it in the form state under
parser_config.raptor.random_seed.Usage: Triggered by clicking the "plus" button beside the random seed input field.
Implementation detail: Uses
lodash'srandomfunction.
Rendered Form Items
Field Name | Description | UI Control Type | Validation | Initial Value | Tooltip |
|---|---|---|---|---|---|
| Toggle to enable/disable raptor parser | Switch | None |
| Translated "useRaptorTip" |
| Text prompt for the parser | TextArea | Required | Translated "promptText" | Translated "promptTip" |
| Maximum token count | Slider + InputNumber | Required, max 2048 | 256 | Translated "maxTokenTip" |
| Threshold value (range 0-1) | Slider + InputNumber | Required, [0,1] with step 0.01 | 0.1 | Translated "thresholdTip" |
| Maximum cluster count | Slider + InputNumber | Required, 1 to 1024 | 64 | Translated "maxClusterTip" |
| Seed for randomization | InputNumber + Button | Required | 0 | N/A |
Important Implementation Details
The component uses Ant Design's
Form.ItemwithshouldUpdateto conditionally render the detailed parameters only when theuse_raptorswitch is enabled.The
Flexcomponent (likely a layout utility) is used for horizontal alignment of sliders and input numbers.Validation rules enforce required inputs and range limits.
The random seed generation button uses a plus icon to generate a new random seed value on demand.
Interaction with Other Parts of the System
Integration with constants: Uses
DocumentParserTypeenum imported from@/constants/knowledgeto handle parser types.Localization: Uses
useTranslatehook from@/hooks/common-hooksto fetch translated strings under the namespaceknowledgeConfiguration.UI Components: Leverages Ant Design (
antd) components for form controls and icons (PlusOutlined).Utility: Uses Lodash
randomto generate random seed values.Form context: Assumes usage inside an Ant Design
Formcomponent to manage state and validation.
This component and utilities are likely used in a larger document parser configuration page or modal, where the user selects a parser type and configures its parameters.
Visual Diagram
componentDiagram
direction TB
component ParseConfiguration {
+handleGenerate()
+render()
}
component Form {
+useFormInstance()
}
component Localization {
+useTranslate()
}
component AntdComponents {
+Switch
+Slider
+InputNumber
+Input.TextArea
+Button
+Form.Item
}
component Utility {
+random()
}
ParseConfiguration --> Form : uses
ParseConfiguration --> Localization : uses
ParseConfiguration --> AntdComponents : renders UI controls
ParseConfiguration --> Utility : calls random() for seed generation
Summary
Provides a user interface for configuring the "raptor" parser with detailed parameters.
Conditionals enable/disable the detailed configuration based on the
use_raptorflag.Excludes certain parser types from showing these configurations via utility functions.
Employs localization and Ant Design for UI consistency.
Supports random seed generation for parser configurations.
This file is a focused configuration component and related utilities to support dynamic display of parser options in a knowledge/document parsing system.