mirror of
https://github.com/ostris/ai-toolkit.git
synced 2026-04-28 02:01:29 +00:00
Show the console log on the job overview in the ui.
This commit is contained in:
35
ui/src/app/api/jobs/[jobID]/log/route.ts
Normal file
35
ui/src/app/api/jobs/[jobID]/log/route.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { getTrainingFolder } from '@/server/settings';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: { jobID: string } }) {
|
||||
const { jobID } = await params;
|
||||
|
||||
const job = await prisma.job.findUnique({
|
||||
where: { id: jobID },
|
||||
});
|
||||
|
||||
if (!job) {
|
||||
return NextResponse.json({ error: 'Job not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
const trainingFolder = await getTrainingFolder();
|
||||
const jobFolder = path.join(trainingFolder, job.name);
|
||||
const logPath = path.join(jobFolder, 'log.txt');
|
||||
|
||||
if (!fs.existsSync(logPath)) {
|
||||
return NextResponse.json({ log: '' });
|
||||
}
|
||||
let log = '';
|
||||
try {
|
||||
log = fs.readFileSync(logPath, 'utf-8');
|
||||
} catch (error) {
|
||||
console.error('Error reading log file:', error);
|
||||
log = 'Error reading log file';
|
||||
}
|
||||
return NextResponse.json({ log: log });
|
||||
}
|
||||
@@ -96,6 +96,7 @@ export async function GET(request: NextRequest, { params }: { params: { jobID: s
|
||||
const additionalEnv: any = {
|
||||
AITK_JOB_ID: jobID,
|
||||
CUDA_VISIBLE_DEVICES: `${job.gpu_ids}`,
|
||||
IS_AI_TOOLKIT_UI: '1'
|
||||
};
|
||||
|
||||
// HF_TOKEN
|
||||
|
||||
Reference in New Issue
Block a user