mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-11 06:05:45 +08:00
Fix: update LayoutRecognizeFormField to accept ownerTenantId and refactor model handling in LLM requests (#16781)
This commit is contained in:
@@ -32,6 +32,7 @@ export function LayoutRecognizeFormField({
|
||||
showMineruOptions = true,
|
||||
showPaddleocrOptions = true,
|
||||
testId,
|
||||
ownerTenantId,
|
||||
}: {
|
||||
name?: string;
|
||||
horizontal?: boolean;
|
||||
@@ -40,11 +41,15 @@ export function LayoutRecognizeFormField({
|
||||
showMineruOptions?: boolean;
|
||||
showPaddleocrOptions?: boolean;
|
||||
testId?: string;
|
||||
ownerTenantId?: string;
|
||||
}) {
|
||||
const form = useFormContext();
|
||||
|
||||
const { t } = useTranslate('knowledgeDetails');
|
||||
const { data: allAddedModels } = useFetchAllAddedModels();
|
||||
const { data: allAddedModels } = useFetchAllAddedModels(
|
||||
undefined,
|
||||
ownerTenantId,
|
||||
);
|
||||
|
||||
const treeData = useMemo(() => {
|
||||
const list = optionsWithoutLLM
|
||||
|
||||
@@ -29,7 +29,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { buildModelValue, parseModelValue } from '@/utils/llm-util';
|
||||
import { parseModelValue } from '@/utils/llm-util';
|
||||
import { useWarnEmptyModel } from './use-warn-empty-model';
|
||||
|
||||
export const enum LLMApiAction {
|
||||
@@ -616,7 +616,7 @@ export const useFetchDefaultModelDictionary = (showEmptyModelWarn = false) => {
|
||||
const dict: Record<string, string> = {};
|
||||
Object.entries(ModelTypeToField).forEach(([key, field]) => {
|
||||
const model = defaultModels.find((m) => m.model_type === key);
|
||||
dict[field] = model && model.enable ? buildModelValue(model) : '';
|
||||
dict[field] = model && model.enable ? model.model_id : '';
|
||||
});
|
||||
return dict;
|
||||
}, [defaultModels]);
|
||||
|
||||
@@ -111,6 +111,7 @@ export interface IInstanceModel {
|
||||
}
|
||||
|
||||
export interface IDefaultModel {
|
||||
model_id: string;
|
||||
enable: boolean;
|
||||
model_instance: string;
|
||||
model_name: string;
|
||||
|
||||
@@ -118,10 +118,8 @@ export interface IUpdateProviderInstanceRequestBody {
|
||||
}
|
||||
|
||||
export interface ISetDefaultModelRequestBody {
|
||||
model_provider: string;
|
||||
model_instance: string;
|
||||
model_type: string;
|
||||
model_name: string;
|
||||
model_id: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,7 @@ import { memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
||||
import { useForm, useWatch } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { AgentDialogueMode, BeginQueryType } from '../../constant';
|
||||
import { useOwnerTenantId } from '../../context';
|
||||
import { INextOperatorForm } from '../../interface';
|
||||
import { ParameterDialog } from './parameter-dialog';
|
||||
import { QueryTable } from './query-table';
|
||||
@@ -38,6 +39,7 @@ const ModeOptions = [
|
||||
|
||||
function BeginForm({ node }: INextOperatorForm) {
|
||||
const { t } = useTranslation();
|
||||
const ownerTenantId = useOwnerTenantId();
|
||||
|
||||
const values = useValues(node);
|
||||
|
||||
@@ -207,6 +209,7 @@ function BeginForm({ node }: INextOperatorForm) {
|
||||
horizontal={false}
|
||||
showMineruOptions={false}
|
||||
showPaddleocrOptions={false}
|
||||
ownerTenantId={ownerTenantId}
|
||||
></LayoutRecognizeFormField>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -8,6 +8,7 @@ import { RAGFlowFormItem } from '@/components/ragflow-form';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { upperCase, upperFirst } from 'lodash';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useOwnerTenantId } from '../../context';
|
||||
import {
|
||||
FileType,
|
||||
OutputFormatMap,
|
||||
@@ -61,12 +62,14 @@ export function ParserMethodFormField({
|
||||
optionsWithoutLLM,
|
||||
}: CommonProps & { optionsWithoutLLM?: { value: string; label: string }[] }) {
|
||||
const { t } = useTranslation();
|
||||
const ownerTenantId = useOwnerTenantId();
|
||||
return (
|
||||
<LayoutRecognizeFormField
|
||||
name={buildFieldNameWithPrefix(`parse_method`, prefix)}
|
||||
horizontal={false}
|
||||
optionsWithoutLLM={optionsWithoutLLM}
|
||||
label={t('flow.parserMethod')}
|
||||
ownerTenantId={ownerTenantId}
|
||||
></LayoutRecognizeFormField>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { useForm, useWatch } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { z } from 'zod';
|
||||
import { BeginQueryType } from '../../constant';
|
||||
import { useOwnerTenantId } from '../../context';
|
||||
import { BeginQuery, INextOperatorForm } from '../../interface';
|
||||
import { ParameterDialog } from '../begin-form/parameter-dialog';
|
||||
import { QueryTable } from '../begin-form/query-table';
|
||||
@@ -29,6 +30,7 @@ import { useWatchFormChange } from './use-watch-change';
|
||||
|
||||
function UserFillUpForm({ node }: INextOperatorForm) {
|
||||
const { t } = useTranslation();
|
||||
const ownerTenantId = useOwnerTenantId();
|
||||
|
||||
const values = useValues(node);
|
||||
|
||||
@@ -169,6 +171,7 @@ function UserFillUpForm({ node }: INextOperatorForm) {
|
||||
horizontal={false}
|
||||
showMineruOptions={false}
|
||||
showPaddleocrOptions={false}
|
||||
ownerTenantId={ownerTenantId}
|
||||
></LayoutRecognizeFormField>
|
||||
)}
|
||||
</Form>
|
||||
|
||||
@@ -7,13 +7,15 @@ import {
|
||||
ConfigurationFormContainer,
|
||||
MainContainer,
|
||||
} from '../configuration-form-container';
|
||||
import { useKnowledgeBaseContext } from '../../contexts/knowledge-base-context';
|
||||
import { AutoMetadata } from './common-item';
|
||||
|
||||
export function BookConfiguration() {
|
||||
const ownerTenantId = useKnowledgeBaseContext().knowledgeBase?.tenant_id;
|
||||
return (
|
||||
<MainContainer>
|
||||
<ConfigurationFormContainer>
|
||||
<LayoutRecognizeFormField></LayoutRecognizeFormField>
|
||||
<LayoutRecognizeFormField ownerTenantId={ownerTenantId}></LayoutRecognizeFormField>
|
||||
</ConfigurationFormContainer>
|
||||
|
||||
<ConfigurationFormContainer>
|
||||
|
||||
@@ -7,13 +7,15 @@ import {
|
||||
ConfigurationFormContainer,
|
||||
MainContainer,
|
||||
} from '../configuration-form-container';
|
||||
import { useKnowledgeBaseContext } from '../../contexts/knowledge-base-context';
|
||||
import { AutoMetadata } from './common-item';
|
||||
|
||||
export function LawsConfiguration() {
|
||||
const ownerTenantId = useKnowledgeBaseContext().knowledgeBase?.tenant_id;
|
||||
return (
|
||||
<MainContainer>
|
||||
<ConfigurationFormContainer>
|
||||
<LayoutRecognizeFormField></LayoutRecognizeFormField>
|
||||
<LayoutRecognizeFormField ownerTenantId={ownerTenantId}></LayoutRecognizeFormField>
|
||||
</ConfigurationFormContainer>
|
||||
|
||||
<ConfigurationFormContainer>
|
||||
|
||||
@@ -7,13 +7,15 @@ import {
|
||||
ConfigurationFormContainer,
|
||||
MainContainer,
|
||||
} from '../configuration-form-container';
|
||||
import { useKnowledgeBaseContext } from '../../contexts/knowledge-base-context';
|
||||
import { AutoMetadata } from './common-item';
|
||||
|
||||
export function ManualConfiguration() {
|
||||
const ownerTenantId = useKnowledgeBaseContext().knowledgeBase?.tenant_id;
|
||||
return (
|
||||
<MainContainer>
|
||||
<ConfigurationFormContainer>
|
||||
<LayoutRecognizeFormField></LayoutRecognizeFormField>
|
||||
<LayoutRecognizeFormField ownerTenantId={ownerTenantId}></LayoutRecognizeFormField>
|
||||
</ConfigurationFormContainer>
|
||||
|
||||
<ConfigurationFormContainer>
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
ConfigurationFormContainer,
|
||||
MainContainer,
|
||||
} from '../configuration-form-container';
|
||||
import { useKnowledgeBaseContext } from '../../contexts/knowledge-base-context';
|
||||
import {
|
||||
AutoMetadata,
|
||||
EnableTocToggle,
|
||||
@@ -20,11 +21,15 @@ import {
|
||||
} from './common-item';
|
||||
|
||||
export function NaiveConfiguration() {
|
||||
const ownerTenantId = useKnowledgeBaseContext().knowledgeBase?.tenant_id;
|
||||
return (
|
||||
<MainContainer>
|
||||
<ConfigurationFormContainer>
|
||||
<CompilationTemplateFormField horizontal></CompilationTemplateFormField>
|
||||
<LayoutRecognizeFormField testId="ds-settings-parser-pdf-parser-select"></LayoutRecognizeFormField>
|
||||
<LayoutRecognizeFormField
|
||||
testId="ds-settings-parser-pdf-parser-select"
|
||||
ownerTenantId={ownerTenantId}
|
||||
></LayoutRecognizeFormField>
|
||||
<MaxTokenNumberFormField
|
||||
initialValue={512}
|
||||
sliderTestId="ds-settings-parser-recommended-chunk-size-slider"
|
||||
|
||||
@@ -4,12 +4,14 @@ import {
|
||||
} from '@/components/auto-keywords-form-field';
|
||||
import { LayoutRecognizeFormField } from '@/components/layout-recognize-form-field';
|
||||
import { ConfigurationFormContainer } from '../configuration-form-container';
|
||||
import { useKnowledgeBaseContext } from '../../contexts/knowledge-base-context';
|
||||
import { AutoMetadata } from './common-item';
|
||||
|
||||
export function OneConfiguration() {
|
||||
const ownerTenantId = useKnowledgeBaseContext().knowledgeBase?.tenant_id;
|
||||
return (
|
||||
<ConfigurationFormContainer>
|
||||
<LayoutRecognizeFormField></LayoutRecognizeFormField>
|
||||
<LayoutRecognizeFormField ownerTenantId={ownerTenantId}></LayoutRecognizeFormField>
|
||||
<>
|
||||
<AutoMetadata />
|
||||
<AutoKeywordsFormField></AutoKeywordsFormField>
|
||||
|
||||
@@ -7,13 +7,15 @@ import {
|
||||
ConfigurationFormContainer,
|
||||
MainContainer,
|
||||
} from '../configuration-form-container';
|
||||
import { useKnowledgeBaseContext } from '../../contexts/knowledge-base-context';
|
||||
import { AutoMetadata } from './common-item';
|
||||
|
||||
export function PaperConfiguration() {
|
||||
const ownerTenantId = useKnowledgeBaseContext().knowledgeBase?.tenant_id;
|
||||
return (
|
||||
<MainContainer>
|
||||
<ConfigurationFormContainer>
|
||||
<LayoutRecognizeFormField></LayoutRecognizeFormField>
|
||||
<LayoutRecognizeFormField ownerTenantId={ownerTenantId}></LayoutRecognizeFormField>
|
||||
</ConfigurationFormContainer>
|
||||
|
||||
<ConfigurationFormContainer>
|
||||
|
||||
@@ -7,13 +7,15 @@ import {
|
||||
ConfigurationFormContainer,
|
||||
MainContainer,
|
||||
} from '../configuration-form-container';
|
||||
import { useKnowledgeBaseContext } from '../../contexts/knowledge-base-context';
|
||||
import { AutoMetadata } from './common-item';
|
||||
|
||||
export function PresentationConfiguration() {
|
||||
const ownerTenantId = useKnowledgeBaseContext().knowledgeBase?.tenant_id;
|
||||
return (
|
||||
<MainContainer>
|
||||
<ConfigurationFormContainer>
|
||||
<LayoutRecognizeFormField></LayoutRecognizeFormField>
|
||||
<LayoutRecognizeFormField ownerTenantId={ownerTenantId}></LayoutRecognizeFormField>
|
||||
</ConfigurationFormContainer>
|
||||
|
||||
<ConfigurationFormContainer>
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
useFetchDefaultModelDictionary,
|
||||
useSetDefaultModel,
|
||||
} from '@/hooks/use-llm-request';
|
||||
import { parseModelValue } from '@/utils/llm-util';
|
||||
import { CircleQuestionMark } from 'lucide-react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
@@ -92,15 +91,13 @@ function SystemSetting() {
|
||||
|
||||
if (!value) {
|
||||
await setDefaultModel({
|
||||
model_provider: '',
|
||||
model_instance: '',
|
||||
model_name: '',
|
||||
model_id: '',
|
||||
model_type: modelType,
|
||||
});
|
||||
} else {
|
||||
const parsed = parseModelValue(value);
|
||||
if (!parsed) return;
|
||||
await setDefaultModel({ ...parsed, model_type: modelType });
|
||||
// const parsed = parseModelValue(value);
|
||||
// if (!parsed) return;
|
||||
await setDefaultModel({ model_id: value, model_type: modelType });
|
||||
}
|
||||
},
|
||||
[setDefaultModel],
|
||||
|
||||
Reference in New Issue
Block a user