completion

This commit is contained in:
overcuriousity
2025-07-26 21:48:17 +02:00
parent d1b0998d9a
commit 3eb1b9d8d7
2 changed files with 23 additions and 20 deletions

View File

@@ -138,13 +138,14 @@ export const POST: APIRoute = async ({ request }) => {
let questions;
try {
// Clean up the response and parse JSON
const cleanedContent = aiContent
// Clean up the response and parse JSON
console.log('[DEBUG-ENHANCE]Raw AI content:', aiContent);
const cleanedContent = aiContent
.replace(/^```json\s*/i, '')
.replace(/\s*```\s*$/, '')
.trim();
questions = JSON.parse(cleanedContent);
console.log('[DEBUG-ENHANCE]Cleaned content:', cleanedContent);
questions = JSON.parse(cleanedContent);
if (!Array.isArray(questions) || questions.length === 0) {
throw new Error('Invalid questions format');