raptor-form-fields.tsx


Overview

raptor-form-fields.tsx is a React functional component file that provides a configurable form interface for managing "Raptor" parsing settings within a document parsing or knowledge configuration system. It integrates tightly with React Hook Form for form state management and leverages UI components for an interactive user experience.

The file contains logic to conditionally show or hide Raptor-specific form fields based on the selected document parser type, allowing users to toggle the use of Raptor parsing and configure parameters such as token limits, thresholds, clustering, random seeds, and prompt text.


Detailed Explanation

Constants

These constants help avoid hardcoding string literals throughout the component.


Component: RaptorFormFields

Description

Main React functional component rendering Raptor-specific form fields. It conditionally displays an enable/disable switch for using Raptor parsing, and if enabled, shows various configurable fields including:

Dependencies

Internal Logic

Rendered UI Elements

  1. Use Raptor Switch:
    A switch toggle field to enable or disable Raptor parsing.
    Displays label with tooltip and validation messages.

  2. Conditional Raptor Configuration Fields (visible only if Use Raptor is ON):

    • Prompt Textarea: Multi-line text input for prompt configuration.

    • Max Token Slider: Slider input ranging from 0 to 2048.

    • Threshold Slider: Slider input ranging from 0 to 1 with step 0.01.

    • Max Cluster Slider: Slider input ranging from 1 to 1024.

    • Random Seed Input: Number input with a button to generate a new random seed.

Each field is wrapped with appropriate form validation message and tooltip support.


Usage Example

import { useForm, FormProvider } from 'react-hook-form';
import RaptorFormFields from './raptor-form-fields';

const MyFormComponent = () => {
  const methods = useForm({
    defaultValues: {
      parser_config: {
        raptor: {
          use_raptor: false,
          random_seed: 0,
          max_token: 256,
          threshold: 0.1,
          max_cluster: 64,
          prompt: '',
        },
      },
    },
  });

  return (
    <FormProvider {...methods}>
      <form>
        <RaptorFormFields />
        {/* Other form fields */}
      </form>
    </FormProvider>
  );
};

Important Implementation Details


Interaction with Other System Parts


Visual Diagram

componentDiagram
    direction TB
    component RaptorFormFields {
        +useFormContext()
        +useWatch(UseRaptorField)
        +changeRaptor(isUseRaptor: boolean)
        +handleGenerate()
        +render()
    }
    component useFormContext
    component useWatch
    component useTranslate
    component SliderInputFormField
    component Switch
    component Button
    component Input
    component Textarea
    component FormField

    RaptorFormFields --> useFormContext : get form control
    RaptorFormFields --> useWatch : watch UseRaptorField
    RaptorFormFields --> useTranslate : get localized strings
    RaptorFormFields --> FormField : render form fields
    RaptorFormFields --> Switch : toggle Use Raptor
    RaptorFormFields --> SliderInputFormField : render sliders
    RaptorFormFields --> Textarea : render prompt input
    RaptorFormFields --> Input : render random seed input
    RaptorFormFields --> Button : generate random seed

Summary

raptor-form-fields.tsx is a dedicated React component handling the user interface and logic for configuring Raptor parser settings within a larger document processing or knowledge configuration system. It uses React Hook Form for state control, provides conditional rendering based on parser type, and offers an intuitive set of configuration controls with localization and validation support. This modular design simplifies integration into broader forms and promotes consistent user experience across parsing configurations.