first-update
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import logger from '@/lib/util/logger';
|
||||
import cleanService from '@/lib/services/clean';
|
||||
|
||||
// 为指定文本块进行数据清洗
|
||||
export async function POST(request, { params }) {
|
||||
try {
|
||||
const { projectId, chunkId } = params;
|
||||
|
||||
// 验证项目ID和文本块ID
|
||||
if (!projectId || !chunkId) {
|
||||
return NextResponse.json({ error: 'Project ID or text block ID cannot be empty' }, { status: 400 });
|
||||
}
|
||||
|
||||
// 获取请求体
|
||||
const { model, language = '中文' } = await request.json();
|
||||
|
||||
if (!model) {
|
||||
return NextResponse.json({ error: 'Model cannot be empty' }, { status: 400 });
|
||||
}
|
||||
|
||||
// 使用数据清洗服务
|
||||
const result = await cleanService.cleanDataForChunk(projectId, chunkId, {
|
||||
model,
|
||||
language
|
||||
});
|
||||
|
||||
// 返回清洗结果
|
||||
return NextResponse.json({
|
||||
chunkId,
|
||||
originalLength: result.originalLength,
|
||||
cleanedLength: result.cleanedLength,
|
||||
success: result.success,
|
||||
message: '数据清洗完成'
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Error cleaning data:', error);
|
||||
return NextResponse.json({ error: error.message || 'Error cleaning data' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { generateEvalQuestionsForChunk } from '@/lib/services/eval';
|
||||
import logger from '@/lib/util/logger';
|
||||
|
||||
/**
|
||||
* 为指定文本块生成测评题目
|
||||
*/
|
||||
export async function POST(request, { params }) {
|
||||
try {
|
||||
const { projectId, chunkId } = params;
|
||||
|
||||
// 验证参数
|
||||
if (!projectId || !chunkId) {
|
||||
return NextResponse.json({ error: 'Project ID and Chunk ID are required' }, { status: 400 });
|
||||
}
|
||||
|
||||
// 获取请求体
|
||||
const { model, language = 'zh-CN' } = await request.json();
|
||||
|
||||
if (!model) {
|
||||
return NextResponse.json({ error: 'Model configuration is required' }, { status: 400 });
|
||||
}
|
||||
|
||||
// 调用服务层生成测评题目
|
||||
const result = await generateEvalQuestionsForChunk(projectId, chunkId, {
|
||||
model,
|
||||
language
|
||||
});
|
||||
|
||||
return NextResponse.json(result);
|
||||
} catch (error) {
|
||||
logger.error('Error generating eval questions:', error);
|
||||
return NextResponse.json({ error: error.message || 'Failed to generate eval questions' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getQuestionsForChunk } from '@/lib/db/questions';
|
||||
import logger from '@/lib/util/logger';
|
||||
import questionService from '@/lib/services/questions';
|
||||
|
||||
// 为指定文本块生成问题
|
||||
export async function POST(request, { params }) {
|
||||
try {
|
||||
const { projectId, chunkId } = params;
|
||||
|
||||
// 验证项目ID和文本块ID
|
||||
if (!projectId || !chunkId) {
|
||||
return NextResponse.json({ error: 'Project ID or text block ID cannot be empty' }, { status: 400 });
|
||||
} // 获取请求体
|
||||
const { model, language = '中文', number, enableGaExpansion = false } = await request.json();
|
||||
|
||||
if (!model) {
|
||||
return NextResponse.json({ error: 'Model cannot be empty' }, { status: 400 });
|
||||
}
|
||||
|
||||
// 后续会根据是否有GA对来选择是否启用GA扩展选择服务函数
|
||||
const serviceFunc = questionService.generateQuestionsForChunkWithGA;
|
||||
|
||||
// 使用问题生成服务
|
||||
const result = await serviceFunc(projectId, chunkId, {
|
||||
model,
|
||||
language,
|
||||
number,
|
||||
enableGaExpansion
|
||||
});
|
||||
|
||||
// 统一返回格式,确保包含GA扩展信息
|
||||
const response = {
|
||||
chunkId,
|
||||
questions: result.questions || result.labelQuestions || [],
|
||||
total: result.total || (result.questions || result.labelQuestions || []).length,
|
||||
gaExpansionUsed: result.gaExpansionUsed || false,
|
||||
gaPairsCount: result.gaPairsCount || 0,
|
||||
expectedTotal: result.expectedTotal || result.total
|
||||
};
|
||||
|
||||
// 返回生成的问题
|
||||
return NextResponse.json(response);
|
||||
} catch (error) {
|
||||
logger.error('Error generating questions:', error);
|
||||
return NextResponse.json({ error: error.message || 'Error generating questions' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
// 获取指定文本块的问题
|
||||
export async function GET(request, { params }) {
|
||||
try {
|
||||
const { projectId, chunkId } = params;
|
||||
|
||||
// 验证项目ID和文本块ID
|
||||
if (!projectId || !chunkId) {
|
||||
return NextResponse.json({ error: 'The item ID or text block ID cannot be empty' }, { status: 400 });
|
||||
}
|
||||
|
||||
// 获取文本块的问题
|
||||
const questions = await getQuestionsForChunk(projectId, chunkId);
|
||||
|
||||
// 返回问题列表
|
||||
return NextResponse.json({
|
||||
chunkId,
|
||||
questions,
|
||||
total: questions.length
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error getting questions:', String(error));
|
||||
return NextResponse.json({ error: error.message || 'Error getting questions' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { deleteChunkById, getChunkById, updateChunkById } from '@/lib/db/chunks';
|
||||
|
||||
// 获取文本块内容
|
||||
export async function GET(request, { params }) {
|
||||
try {
|
||||
const { projectId, chunkId } = params;
|
||||
// 验证参数
|
||||
if (!projectId) {
|
||||
return NextResponse.json({ error: 'Project ID cannot be empty' }, { status: 400 });
|
||||
}
|
||||
if (!chunkId) {
|
||||
return NextResponse.json({ error: 'Text block ID cannot be empty' }, { status: 400 });
|
||||
}
|
||||
// 获取文本块内容
|
||||
const chunk = await getChunkById(chunkId);
|
||||
|
||||
return NextResponse.json(chunk);
|
||||
} catch (error) {
|
||||
console.error('Failed to get text block content:', String(error));
|
||||
return NextResponse.json({ error: error.message || 'Failed to get text block content' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
// 删除文本块
|
||||
export async function DELETE(request, { params }) {
|
||||
try {
|
||||
const { projectId, chunkId } = params;
|
||||
// 验证参数
|
||||
if (!projectId) {
|
||||
return NextResponse.json({ error: 'Project ID cannot be empty' }, { status: 400 });
|
||||
}
|
||||
if (!chunkId) {
|
||||
return NextResponse.json({ error: 'Text block ID cannot be empty' }, { status: 400 });
|
||||
}
|
||||
await deleteChunkById(chunkId);
|
||||
|
||||
return NextResponse.json({ message: 'Text block deleted successfully' });
|
||||
} catch (error) {
|
||||
console.error('Failed to delete text block:', String(error));
|
||||
return NextResponse.json({ error: error.message || 'Failed to delete text block' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑文本块内容
|
||||
export async function PATCH(request, { params }) {
|
||||
try {
|
||||
const { projectId, chunkId } = params;
|
||||
|
||||
// 验证参数
|
||||
if (!projectId) {
|
||||
return NextResponse.json({ error: '项目ID不能为空' }, { status: 400 });
|
||||
}
|
||||
|
||||
if (!chunkId) {
|
||||
return NextResponse.json({ error: '文本块ID不能为空' }, { status: 400 });
|
||||
}
|
||||
|
||||
// 解析请求体获取新内容
|
||||
const requestData = await request.json();
|
||||
const { content } = requestData;
|
||||
|
||||
if (!content) {
|
||||
return NextResponse.json({ error: '内容不能为空' }, { status: 400 });
|
||||
}
|
||||
|
||||
let res = await updateChunkById(chunkId, { content });
|
||||
return NextResponse.json(res);
|
||||
} catch (error) {
|
||||
console.error('编辑文本块失败:', String(error));
|
||||
return NextResponse.json({ error: error.message || '编辑文本块失败' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user