mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-31 15:45:08 +08:00
Fix: The minimum size of the historical message window for the classification operator is 1. #12778 (#12779)
### What problem does this PR solve? Fix: The minimum size of the historical message window for the classification operator is 1. #12778 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import { useFormContext } from 'react-hook-form';
|
import { useFormContext } from 'react-hook-form';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import NumberInput from './originui/number-input';
|
||||||
import {
|
import {
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
@ -7,9 +8,13 @@ import {
|
|||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage,
|
FormMessage,
|
||||||
} from './ui/form';
|
} from './ui/form';
|
||||||
import { NumberInput } from './ui/input';
|
|
||||||
|
|
||||||
export function MessageHistoryWindowSizeFormField() {
|
type MessageHistoryWindowSizeFormFieldProps = {
|
||||||
|
min?: number;
|
||||||
|
};
|
||||||
|
export function MessageHistoryWindowSizeFormField({
|
||||||
|
min,
|
||||||
|
}: MessageHistoryWindowSizeFormFieldProps) {
|
||||||
const form = useFormContext();
|
const form = useFormContext();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@ -23,7 +28,7 @@ export function MessageHistoryWindowSizeFormField() {
|
|||||||
{t('flow.messageHistoryWindowSize')}
|
{t('flow.messageHistoryWindowSize')}
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<NumberInput {...field}></NumberInput>
|
<NumberInput {...field} min={min} className="w-full"></NumberInput>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|||||||
@ -1,5 +1,13 @@
|
|||||||
|
import { isNumber, trim } from 'lodash';
|
||||||
import { MinusIcon, PlusIcon } from 'lucide-react';
|
import { MinusIcon, PlusIcon } from 'lucide-react';
|
||||||
import React, { useEffect, useMemo, useState } from 'react';
|
import React, {
|
||||||
|
FocusEventHandler,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
|
|
||||||
interface NumberInputProps {
|
interface NumberInputProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
@ -18,10 +26,12 @@ const NumberInput: React.FC<NumberInputProps> = ({
|
|||||||
min = 0,
|
min = 0,
|
||||||
max = Infinity,
|
max = Infinity,
|
||||||
}) => {
|
}) => {
|
||||||
const [value, setValue] = useState<number>(() => {
|
const [value, setValue] = useState<number | ''>(() => {
|
||||||
return initialValue ?? 0;
|
return initialValue ?? 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const valueRef = useRef<number>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (initialValue !== undefined) {
|
if (initialValue !== undefined) {
|
||||||
setValue(initialValue);
|
setValue(initialValue);
|
||||||
@ -29,13 +39,16 @@ const NumberInput: React.FC<NumberInputProps> = ({
|
|||||||
}, [initialValue]);
|
}, [initialValue]);
|
||||||
|
|
||||||
const handleDecrement = () => {
|
const handleDecrement = () => {
|
||||||
if (value > 0) {
|
if (isNumber(value) && value > min) {
|
||||||
setValue(value - 1);
|
setValue(value - 1);
|
||||||
onChange?.(value - 1);
|
onChange?.(value - 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleIncrement = () => {
|
const handleIncrement = () => {
|
||||||
|
if (!isNumber(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (value > max - 1) {
|
if (value > max - 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -44,9 +57,19 @@ const NumberInput: React.FC<NumberInputProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const newValue = Number(e.target.value);
|
const currentValue = e.target.value;
|
||||||
|
const newValue = Number(currentValue);
|
||||||
|
|
||||||
|
if (trim(currentValue) === '') {
|
||||||
|
if (isNumber(value)) {
|
||||||
|
valueRef.current = value;
|
||||||
|
}
|
||||||
|
setValue('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isNaN(newValue)) {
|
if (!isNaN(newValue)) {
|
||||||
if (newValue > max) {
|
if (newValue > max || newValue < min) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setValue(newValue);
|
setValue(newValue);
|
||||||
@ -54,12 +77,16 @@ const NumberInput: React.FC<NumberInputProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleInput = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleBlur: FocusEventHandler<HTMLInputElement> = useCallback(() => {
|
||||||
// If the input value is not a number, the input is not allowed
|
if (isNumber(value)) {
|
||||||
if (!/^\d*$/.test(e.target.value)) {
|
onChange?.(value);
|
||||||
e.preventDefault();
|
} else {
|
||||||
|
const previousValue = valueRef.current ?? min;
|
||||||
|
setValue(previousValue);
|
||||||
|
onChange?.(previousValue);
|
||||||
}
|
}
|
||||||
};
|
}, [min, onChange, value]);
|
||||||
|
|
||||||
const style = useMemo(
|
const style = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
height: height ? `${height.toString().replace('px', '')}px` : 'auto',
|
height: height ? `${height.toString().replace('px', '')}px` : 'auto',
|
||||||
@ -82,8 +109,8 @@ const NumberInput: React.FC<NumberInputProps> = ({
|
|||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={value}
|
value={value}
|
||||||
onInput={handleInput}
|
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
|
onBlur={handleBlur}
|
||||||
className="w-full flex-1 text-center bg-transparent focus:outline-none"
|
className="w-full flex-1 text-center bg-transparent focus:outline-none"
|
||||||
style={style}
|
style={style}
|
||||||
min={min}
|
min={min}
|
||||||
|
|||||||
@ -206,6 +206,8 @@ export const InnerBlurInput = React.forwardRef<
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
InnerBlurInput.displayName = 'BlurInput';
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
InnerBlurInput.whyDidYouRender = true;
|
InnerBlurInput.whyDidYouRender = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,9 @@ function CategorizeForm({ node }: INextOperatorForm) {
|
|||||||
<QueryVariable></QueryVariable>
|
<QueryVariable></QueryVariable>
|
||||||
<LargeModelFormField></LargeModelFormField>
|
<LargeModelFormField></LargeModelFormField>
|
||||||
</FormContainer>
|
</FormContainer>
|
||||||
<MessageHistoryWindowSizeFormField></MessageHistoryWindowSizeFormField>
|
<MessageHistoryWindowSizeFormField
|
||||||
|
min={1}
|
||||||
|
></MessageHistoryWindowSizeFormField>
|
||||||
<DynamicCategorize nodeId={node?.id}></DynamicCategorize>
|
<DynamicCategorize nodeId={node?.id}></DynamicCategorize>
|
||||||
<Output list={outputList}></Output>
|
<Output list={outputList}></Output>
|
||||||
</FormWrapper>
|
</FormWrapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user