File size: 1,534 Bytes
cf07b75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 = (/* @__PURE__ */ 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 };
//# sourceMappingURL=_server.ts-OSIPCWCP.js.map