fix: 完善提示词管理页面的优化,数据库中添加相关字段来区分vlm和llm提示词。评查点设置中抽取设置的多模态抽取的类型通过查询数据库来返回数据。

This commit is contained in:
2025-11-11 01:16:27 +08:00
parent ddad57529d
commit 95381ddcc2
7 changed files with 261 additions and 76 deletions
+38 -4
View File
@@ -51,6 +51,7 @@ import { RuleContext } from "~/contexts/RuleContext";
import { postgrestGet, postgrestPost, postgrestPut } from "~/api/postgrest-client";
import { toastService } from '~/components/ui/Toast';
import type { UserRole } from '~/root';
import { getPromptTemplateOptions } from '~/api/prompts/prompts';
export const meta: MetaFunction = () => {
return [
@@ -160,13 +161,16 @@ export default function RuleNew() {
const [formData, setFormData] = useState<EvaluationPoint>({});
const [evaluationPointGroups, setEvaluationPointGroups] = useState<EvaluationPointGroup[]>([]);
// 判断表单是否为只读模式
const isReadOnly = userRole === 'common';
// 添加用于共享的字段数据状态
const [extractionFields, setExtractionFields] = useState<string[]>([]);
// VLM字段类型选项
const [vlmFieldTypeOptions, setVlmFieldTypeOptions] = useState<Array<{ value: string; label: string }>>([]);
/**
* 从表单数据中提取所有字段
* 用于编辑模式下初始化字段数据
@@ -355,6 +359,34 @@ export default function RuleNew() {
}
}, [frontendJWT]);
/**
* 获取VLM字段类型选项
* 从API获取多模态抽取的字段类型选项
*/
const fetchVlmFieldTypeOptions = useCallback(async () => {
try {
// console.log("获取VLM字段类型选项");
const response = await getPromptTemplateOptions('VLM_Extraction', frontendJWT);
if (response.data && Array.isArray(response.data)) {
// 添加自定义选项
const optionsWithCustom = [
...response.data,
{ value: 'custom', label: '自定义' }
];
setVlmFieldTypeOptions(optionsWithCustom);
} else if (response.error) {
console.error('获取VLM字段类型选项失败:', response.error);
// 使用默认选项作为备选
setVlmFieldTypeOptions(EVALUATION_OPTIONS.vlmFieldTypeOptions);
}
} catch (error) {
console.error('获取VLM字段类型选项失败:', error);
// 使用默认选项作为备选
setVlmFieldTypeOptions(EVALUATION_OPTIONS.vlmFieldTypeOptions);
}
}, [frontendJWT]);
const handleSave = async () => {
// console.log("保存评查点", formData);
@@ -917,7 +949,9 @@ export default function RuleNew() {
// 获取评查点组数据
fetchEvaluationPointGroups();
}, [location.search, fetchEvaluationPoint, fetchEvaluationPointGroups, resetFormData]);
// 获取VLM字段类型选项
fetchVlmFieldTypeOptions();
}, [location.search, fetchEvaluationPoint, fetchEvaluationPointGroups, fetchVlmFieldTypeOptions, resetFormData]);
// 渲染页面内容
return (
@@ -958,7 +992,7 @@ export default function RuleNew() {
onChange={handleExtractionSettingsChange}
initialData={formData}
promptTypeOptions={EVALUATION_OPTIONS.llmPromptTypeOptions}
vlmFieldTypeOptions={EVALUATION_OPTIONS.vlmFieldTypeOptions}
vlmFieldTypeOptions={vlmFieldTypeOptions.length > 0 ? vlmFieldTypeOptions : EVALUATION_OPTIONS.vlmFieldTypeOptions}
/>
</div>