zhou zhou
12 小时以前 287a666e1b2bb155e86aa88ebace201d1e8a51f6
rsf-admin/src/page/system/aiParam/AiParamForm.jsx
@@ -6,6 +6,7 @@
    SelectInput,
    TextInput,
    useNotify,
    useTranslate,
} from "react-admin";
import { Alert, Button, Grid, Stack, Typography } from "@mui/material";
import StatusSelectInput from "@/page/components/StatusSelectInput";
@@ -17,6 +18,7 @@
const AiParamValidateSection = ({ formData, readOnly }) => {
    const notify = useNotify();
    const translate = useTranslate();
    const [loading, setLoading] = useState(false);
    const [result, setResult] = useState(null);
@@ -25,11 +27,11 @@
        try {
            const data = await validateAiParamDraft(formData);
            setResult(data);
            notify(data?.message || "AI 参数验证成功");
            notify(data?.message || translate("ai.param.validate.success"));
        } catch (error) {
            const nextResult = {
                status: "INVALID",
                message: error?.message || "AI 参数验证失败",
                message: error?.message || translate("ai.param.validate.failed"),
            };
            setResult(nextResult);
            notify(nextResult.message, { type: "error" });
@@ -44,10 +46,10 @@
                <Grid item xs={12}>
                    <Stack direction="row" spacing={1} alignItems="center">
                        <Button variant="outlined" onClick={handleValidate} disabled={loading}>
                            {loading ? "验证中..." : "保存前验证"}
                            {loading ? translate("ai.param.validate.loading") : translate("ai.param.validate.beforeSave")}
                        </Button>
                        <Typography variant="body2" color="text.secondary">
                            会直接校验当前 Base URL、API Key 与模型是否可调用。
                            {translate("ai.param.validate.description")}
                        </Typography>
                    </Stack>
                </Grid>
@@ -65,72 +67,76 @@
    );
};
const AiParamForm = ({ readOnly = false }) => (
const AiParamForm = ({ readOnly = false }) => {
    const translate = useTranslate();
    return (
    <Grid container spacing={2} width={{ xs: "100%", xl: "80%" }}>
        <Grid item xs={12}>
            <Typography variant="h6">主要配置</Typography>
            <Typography variant="h6">{translate("ai.param.form.sections.main")}</Typography>
        </Grid>
        <Grid item xs={12} md={6}>
            <TextInput source="name" label="名称" fullWidth disabled={readOnly} />
            <TextInput source="name" label="common.field.name" fullWidth disabled={readOnly} />
        </Grid>
        <Grid item xs={12} md={6}>
            <SelectInput source="providerType" label="提供方类型" choices={providerChoices} fullWidth disabled={readOnly} />
            <SelectInput source="providerType" label="ai.param.fields.providerType" choices={providerChoices} fullWidth disabled={readOnly} />
        </Grid>
        <Grid item xs={12}>
            <TextInput source="baseUrl" label="Base URL" fullWidth disabled={readOnly} />
            <TextInput source="baseUrl" label="ai.param.fields.baseUrl" fullWidth disabled={readOnly} />
        </Grid>
        <Grid item xs={12} md={6}>
            <TextInput source="apiKey" label="API Key" fullWidth disabled={readOnly} />
            <TextInput source="apiKey" label="ai.param.fields.apiKey" fullWidth disabled={readOnly} />
        </Grid>
        <Grid item xs={12} md={6}>
            <TextInput source="model" label="模型" fullWidth disabled={readOnly} />
            <TextInput source="model" label="ai.param.fields.model" fullWidth disabled={readOnly} />
        </Grid>
        <Grid item xs={12} md={3}>
            <NumberInput source="temperature" label="Temperature" fullWidth disabled={readOnly} />
            <NumberInput source="temperature" label="ai.param.fields.temperature" fullWidth disabled={readOnly} />
        </Grid>
        <Grid item xs={12} md={3}>
            <NumberInput source="topP" label="Top P" fullWidth disabled={readOnly} />
            <NumberInput source="topP" label="ai.param.fields.topP" fullWidth disabled={readOnly} />
        </Grid>
        <Grid item xs={12} md={3}>
            <NumberInput source="maxTokens" label="Max Tokens" fullWidth disabled={readOnly} />
            <NumberInput source="maxTokens" label="ai.param.fields.maxTokens" fullWidth disabled={readOnly} />
        </Grid>
        <Grid item xs={12} md={3}>
            <NumberInput source="timeoutMs" label="Timeout(ms)" fullWidth disabled={readOnly} />
            <NumberInput source="timeoutMs" label="ai.param.fields.timeoutMs" fullWidth disabled={readOnly} />
        </Grid>
        <Grid item xs={12} md={6}>
            <BooleanInput source="streamingEnabled" label="启用流式响应" disabled={readOnly} />
            <BooleanInput source="streamingEnabled" label="ai.param.fields.streamingEnabled" disabled={readOnly} />
        </Grid>
        <Grid item xs={12} md={6}>
            <StatusSelectInput disabled={readOnly} />
        </Grid>
        <Grid item xs={12}>
            <TextInput source="memo" label="备注" fullWidth multiline minRows={3} disabled={readOnly} />
            <TextInput source="memo" label="common.field.memo" fullWidth multiline minRows={3} disabled={readOnly} />
        </Grid>
        <FormDataConsumer>
            {({ formData }) => <AiParamValidateSection formData={formData} readOnly={readOnly} />}
        </FormDataConsumer>
        <Grid item xs={12}>
            <Typography variant="h6">运行与审计信息</Typography>
            <Typography variant="h6">{translate("ai.param.form.sections.runtime")}</Typography>
        </Grid>
        <Grid item xs={12} md={3}>
            <TextInput source="validateStatus" label="最近校验状态" fullWidth disabled />
            <TextInput source="validateStatus" label="ai.param.fields.validateStatus" fullWidth disabled />
        </Grid>
        <Grid item xs={12} md={3}>
            <TextInput source="lastValidateElapsedMs" label="最近校验耗时(ms)" fullWidth disabled />
            <TextInput source="lastValidateElapsedMs" label="ai.param.fields.lastValidateElapsedMs" fullWidth disabled />
        </Grid>
        <Grid item xs={12} md={3}>
            <TextInput source="lastValidateTime$" label="最近校验时间" fullWidth disabled />
            <TextInput source="lastValidateTime$" label="ai.param.fields.lastValidateTime" fullWidth disabled />
        </Grid>
        <Grid item xs={12} md={3}>
            <TextInput source="updateBy" label="最近更新人" fullWidth disabled />
            <TextInput source="updateBy" label="ai.common.lastUpdatedBy" fullWidth disabled />
        </Grid>
        <Grid item xs={12}>
            <TextInput source="lastValidateMessage" label="最近校验结果" fullWidth multiline minRows={3} disabled />
            <TextInput source="lastValidateMessage" label="ai.param.fields.lastValidateMessage" fullWidth multiline minRows={3} disabled />
        </Grid>
        <Grid item xs={12}>
            <TextInput source="updateTime$" label="最近更新时间" fullWidth disabled />
            <TextInput source="updateTime$" label="ai.common.lastUpdatedAt" fullWidth disabled />
        </Grid>
    </Grid>
);
    );
};
export default AiParamForm;