|
import { c as redirect, b as base } from './index-JNnR1J8_.js'; |
|
import { resolve } from 'path'; |
|
import { existsSync, mkdirSync, writeFileSync } from 'fs'; |
|
|
|
function createLogFile(text, namePrefix = "") { |
|
const logsDirectory = resolve("/logs"); |
|
if (!existsSync(logsDirectory)) { |
|
mkdirSync(logsDirectory); |
|
} |
|
const timestamp = ( new Date()).toISOString().replace(/[:.]/g, ""); |
|
const logFilePath = resolve(logsDirectory, `${namePrefix}${timestamp}.json`); |
|
writeFileSync(logFilePath, text); |
|
console.log(`Log file created: ${logFilePath}`); |
|
} |
|
const POST = async ({ locals, request }) => { |
|
try { |
|
const body = await request.json(); |
|
let prompt = body.user_query; |
|
let template = body.prompt_template; |
|
let search_results = body.search_results; |
|
let llm_response = body.llm_response; |
|
let user_score = body.user_score; |
|
let user_comment = body.user_comment; |
|
createLogFile(JSON.stringify({ |
|
prompt, |
|
template, |
|
search_results, |
|
llm_response, |
|
user_score, |
|
user_comment |
|
}), "llmresponse-"); |
|
return new Response( |
|
JSON.stringify({ success: true }), |
|
{ |
|
headers: { "Content-Type": "application/json" } |
|
} |
|
); |
|
} catch (e) { |
|
return new Response( |
|
JSON.stringify({ success: false, error: e }), |
|
{ |
|
headers: { "Content-Type": "application/json" } |
|
} |
|
); |
|
} |
|
}; |
|
const GET = async () => { |
|
throw redirect(302, `${base}/`); |
|
}; |
|
|
|
export { GET, POST }; |
|
|
|
|