@@ -2,43 +2,15 @@ import React, { FC, useCallback, useEffect, useRef } from 'react' import { TextFieldProps } from '@mui/material/TextField/TextField' import classes from './model-input.module.scss' -import { PredictPrice } from './predict-price' import { LoadImage } from '#/app/components/input_components/load_image' import { SendBtn } from '#/app/components/input_components/send_button' import { IModelInputs } from '#/shared/api/models/models' - -function buildTypeVersionsMap(inputs: IModelInputs[]): Record { - const byType = new Map() - for (const item of inputs) { - const list = byType.get(item.type) ?? [] - list.push(item.versions) - byType.set(item.type, list) - } - const result: Record = {} - for (const [type, versionsList] of byType) { - if (versionsList.some((v) => v.length === 0)) { - result[type] = [] - } else { - result[type] = [...new Set(versionsList.flat())] - } - } - return result -} - -function inputAppliesToVersion(input: IModelInputs, currentVersion: string): boolean { - return input.versions.length === 0 || input.versions.includes(currentVersion) -} - -/** Учитывает только inputs, актуальные для версии — иначе required с другой версии (второй image) ломает валидацию */ -function buildRequiredForVersion(inputs: IModelInputs[], currentVersion: string): (string | null)[] { - const requiredTypes = new Set() - for (const el of inputs) { - if (!inputAppliesToVersion(el, currentVersion)) continue - if (el.required) requiredTypes.add(el.type) - } - return [...requiredTypes] -} +import { TooltipCustom } from '#/shared' +import { SvgIcon } from '#/shared/ui/svg' +import { Typography } from '@mui/material' +import { ThreePOutlined } from '@mui/icons-material' +import { PredictPrice } from './predict-price' interface Input { loading: boolean @@ -87,12 +59,6 @@ export const ModelInput: FC = ({ const [types, setTypes] = React.useState([]) const [typeVersions, setTypeVersions] = React.useState({}) const [internalValue, setInternalValue] = React.useState('') - const hasAttachInput = - typeVersions && - Object.entries(typeVersions).some(([type, versions]) => { - if (type === 'text') return false - return Array.isArray(versions) && (versions.length === 0 || versions.includes(currentVersion)) - }) // Используем внешнее значение если оно передано, иначе внутреннее const value = externalValue !== undefined ? externalValue : internalValue @@ -116,11 +82,11 @@ export const ModelInput: FC = ({ useEffect(() => { if (input_types) { - setRequired(buildRequiredForVersion(input_types, currentVersion)) + setRequired(input_types.map((el) => (el.required ? el.type : null))) setTypes(input_types.map((el) => el.type)) - setTypeVersions(buildTypeVersionsMap(input_types)) + setTypeVersions(input_types.reduce((a, v) => ({ ...a, [v.type]: v.versions }), {})) } - }, [input_types, currentVersion]) + }, [input_types]) useEffect(() => { if (input_types && typeVersions && !typeVersions['text']) { @@ -131,7 +97,7 @@ export const ModelInput: FC = ({ ) { setDisabled(false) } - }, [typeVersions, currentVersion, input_types]) + }, [typeVersions]) useEffect(() => { if (resendValue) { @@ -217,8 +183,23 @@ export const ModelInput: FC = ({ >
- - {hasAttachInput && ( + {typeof predictedPrice === 'string' && ( + styles === 'chats' ? ( + + ) : ( + +
+ + + {Math.ceil(Number(predictedPrice))} + +
+
+ ) + )} + {typeVersions['image'] && + (typeVersions['image'].length === 0 || + typeVersions['image'].includes(currentVersion)) && ( <> {!blocked && ( { + // return { price: getMockPrice() } + const { data: result } = await axios.post( getApiUrl() + '/ml_model/predict-price/', data,