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
+80 -8
View File
@@ -14,6 +14,8 @@ export interface PromptTemplate {
created_by: number;
created_at: string;
updated_at: string;
template_code?: string; // 模板代码(VLM_Extraction 类型时使用)
template_abbreviation?: string; // 模板简称(VLM_Extraction 类型时使用)
}
// 提示词模板前端接口
@@ -30,6 +32,8 @@ export interface PromptTemplateUI {
created_by_username?: string; // 创建者用户名
created_at: string;
updated_at: string;
template_code?: string; // 模板代码(VLM_Extraction 类型时使用)
template_abbreviation?: string; // 模板简称(VLM_Extraction 类型时使用)
}
// 搜索参数接口
@@ -108,7 +112,9 @@ export function convertToUITemplate(template: PromptTemplate & { sso_users?: { u
created_by: template.created_by,
created_by_username: template.sso_users?.username, // 从关联的用户信息中提取用户名
created_at: formatDate(template.created_at),
updated_at: formatDate(template.updated_at)
updated_at: formatDate(template.updated_at),
template_code: template.template_code,
template_abbreviation: template.template_abbreviation
};
}
@@ -131,7 +137,7 @@ export async function getPromptTemplates(searchParams: PromptSearchParams = {},
// 构建查询参数,包含对 sso_users 表的左连接
const params: PostgrestParams = {
select: `id,template_name,template_type,description,template_content,variables,status,version,created_by,created_at,updated_at,sso_users!created_by(username)`,
select: `id,template_name,template_type,description,template_content,variables,status,version,created_by,created_at,updated_at,template_code,template_abbreviation,sso_users!created_by(username)`,
order: 'updated_at.desc',
headers: {
'Prefer': 'count=exact'
@@ -232,7 +238,7 @@ export async function getPromptTemplate(id: string, frontendJWT?: string): Promi
}
const params: PostgrestParams = {
select: `id,template_name,template_type,description,template_content,variables,status,version,created_by,created_at,updated_at,sso_users!created_by(username)`,
select: `id,template_name,template_type,description,template_content,variables,status,version,created_by,created_at,updated_at,template_code,template_abbreviation,sso_users!created_by(username)`,
filter: {
'id': `eq.${id}`
},
@@ -305,7 +311,9 @@ export async function createPromptTemplate(template: Partial<PromptTemplateUI>,
variables: variablesData,
status: mapStatusToAPI(template.status || 'active'),
version: template.version || 'v1.0',
created_by: userId // 使用当前登录用户ID
created_by: userId, // 使用当前登录用户ID
template_code: template.template_code,
template_abbreviation: template.template_abbreviation
};
if(apiTemplate){
@@ -399,11 +407,19 @@ export async function updatePromptTemplate(id: string, template: Partial<PromptT
apiTemplate.version = template.version;
}
if (template.template_code !== undefined) {
apiTemplate.template_code = template.template_code;
}
if (template.template_abbreviation !== undefined) {
apiTemplate.template_abbreviation = template.template_abbreviation;
}
// if(apiTemplate){
// console.log('apiTemplate', apiTemplate);
// throw new Error('测试错误');
// }
const response = await postgrestPut<PromptTemplate, Partial<PromptTemplate>>(
'prompt_templates',
apiTemplate,
@@ -446,7 +462,7 @@ export async function deletePromptTemplate(id: string, frontendJWT?: string): Pr
if (!id) {
return { error: '模板ID不能为空', status: 400 };
}
// 使用真实删除替代状态更新
const response = await postgrestDelete<PromptTemplate>(
'prompt_templates',
@@ -457,11 +473,11 @@ export async function deletePromptTemplate(id: string, frontendJWT?: string): Pr
token: frontendJWT
}
);
if (response.error) {
return { error: response.error, status: response.status };
}
return { success: true };
} catch (error) {
console.error('删除提示词模板失败:', error);
@@ -470,4 +486,60 @@ export async function deletePromptTemplate(id: string, frontendJWT?: string): Pr
status: 500
};
}
}
/**
* 获取指定类型的提示词模板选项
* @param templateType 模板类型(如 'VLM_Extraction', 'LLM_Extraction' 等)
* @param frontendJWT JWT token (可选)
* @returns 模板选项列表 { value: template_code, label: template_abbreviation }
*/
export async function getPromptTemplateOptions(templateType: string, frontendJWT?: string): Promise<{
data?: Array<{ value: string; label: string }>;
error?: string;
status?: number;
}> {
try {
if (!templateType) {
return { error: '模板类型不能为空', status: 400 };
}
const params: PostgrestParams = {
select: 'template_code,template_abbreviation',
filter: {
'template_type': `eq.${templateType}`,
'status': 'gte.0' // 只查询有效状态的模板
},
order: 'template_abbreviation.asc', // 按标签排序
token: frontendJWT
};
const response = await postgrestGet<Array<{ template_code: string; template_abbreviation: string }>>('prompt_templates', params);
if (response.error) {
console.error('获取提示词模板选项失败:', response.error);
return { error: response.error, status: response.status };
}
const extractedData = extractApiData<Array<{ template_code: string; template_abbreviation: string }>>(response.data);
if (!extractedData) {
console.error('提取提示词模板选项数据失败');
return { error: '获取提示词模板选项失败', status: 500 };
}
// 转换为选项格式
const options = extractedData.map(item => ({
value: item.template_code,
label: item.template_abbreviation
}));
return { data: options };
} catch (error) {
console.error('获取提示词模板选项出错:', error);
return {
error: error instanceof Error ? error.message : '获取提示词模板选项失败',
status: 500
};
}
}