fix: 训练后模型没选中

This commit is contained in:
archer
2023-03-26 13:56:00 +08:00
parent 41b6401c13
commit 98c458dcf8
9 changed files with 35 additions and 32 deletions

View File

@@ -1,15 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { connectToDatabase, Model, Training } from '@/service/mongo';
import { getOpenAIApi } from '@/service/utils/chat';
import formidable from 'formidable';
import { authToken, getUserOpenaiKey } from '@/service/utils/tools';
import { join } from 'path';
import fs from 'fs';
import type { ModelSchema } from '@/types/mongoSchema';
import type { OpenAIApi } from 'openai';
import { ModelStatusEnum, TrainingStatusEnum } from '@/constants/model';
import { httpsAgent } from '@/service/utils/tools';
import { connectToDatabase, Training } from '@/service/mongo';
import { authToken } from '@/service/utils/tools';
// 关闭next默认的bodyParser处理方式
export const config = {
@@ -18,7 +10,7 @@ export const config = {
}
};
/* 上传文件,开始微调 */
/* 获取模型训练记录 */
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
const { authorization } = req.headers;
@@ -30,7 +22,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (!modelId) {
throw new Error('参数错误');
}
const userId = await authToken(authorization);
await authToken(authorization);
await connectToDatabase();

View File

@@ -52,7 +52,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// 删除训练文件
openai.deleteFile(data.training_files[0].id, { httpsAgent });
// 更新模型
// 更新模型状态和模型内容
await Model.findByIdAndUpdate(modelId, {
status: ModelStatusEnum.running,
updateTime: new Date(),
@@ -72,6 +72,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
});
}
/* 取消微调 */
if (data.status === OpenAiTuneStatusEnum.cancelled) {
// 删除训练文件
openai.deleteFile(data.training_files[0].id, { httpsAgent });
@@ -87,11 +88,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
});
return jsonRes(res, {
data: '模型微调取消'
data: '模型微调取消'
});
}
throw new Error('模型还在训练中');
jsonRes(res, {
data: '模型还在训练中'
});
} catch (err: any) {
jsonRes(res, {
code: 500,

View File

@@ -30,6 +30,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
throw new Error('无权操作');
}
const { modelId } = req.query;
if (!modelId) {
throw new Error('参数错误');
}
@@ -67,7 +68,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
});
const file = files.file;
// 上传文件
// 上传文件到 openai
// @ts-ignore
const uploadRes = await openai.createFile(
// @ts-ignore