-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (31 loc) · 956 Bytes
/
index.js
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
import { getVariable } from './lib/getVariable.js';
import { getPromptScore } from './lib/getPromptScores.js';
import responseTexts from './lib/responseTexts.js';
export const handler = async (event) => {
const query = getVariable(event, 'q');
process.event = event;
const prompt = query
.trim()
.replace(/[^\w\sğüşıöçĞÜŞİÖÇ]/gi, '')
.toLocaleLowerCase();
let responseText = '';
let promptScores;
let sortedScores;
let bestPrompt;
if (query !== '') {
promptScores = getPromptScore(prompt, responseTexts);
sortedScores = Object.entries(promptScores).sort((a, b) => b[1] - a[1]);
bestPrompt = sortedScores[0][0] || '';
responseText = await responseTexts[bestPrompt]();
} else {
responseText = 'Merhaba, nasılsın?';
}
const response = {
statusCode: 200,
headers: {
'Content-Type': 'text/plain; charset=utf-8',
},
body: responseText,
};
return response;
};