4 ms·
// A list of ELIZA's responses const responses = {"I feel": [ "Why do you feel {0}?", "What do you think
by floxy 4y ago
// A list of ELIZA's responses
const responses = {"I feel":
[ "Why do you feel {0}?",
"What do you think is causing you to feel {0}?",
"Do you often feel {0}?",
"How do you normally deal with feeling {0}?" ],
"I want":
[ "Why do you want {0}?",
"What led you to want this?",
"Do you often find yourself wanting {0}?",
"How do you think getting what you want will make you feel?" ],
"I need":
[ "Why do you feel like you need {0}?",
"What led you to feel like you need this?",
"Do you often find yourself feeling like you need {0}?",
"How do you think getting what you need will make you feel?" ] };
// A list of keywords
const keywords = Object.keys(responses);
// A function that generates a response
function generateResponse(input) {
// Check if the input contains any of the keywords
for (let i = 0; i < keywords.length; i++) {
if (input.includes(keywords[i])) {
// If the input contains a keyword, return a random response
// that includes the remainder of the input, with personal
// pronouns conjugated correctly
const response = responses[keywords[i]][Math.floor(Math.random() * responses[keywords[i]].length)];
return response.replace("{0}", input.substring(keywords[i].length + 1));
}
}
}
// Test the function
console.log(generateResponse("I feel sad"));
console.log(generateResponse("I want a new car"));
console.log(generateResponse("I need some help"));
- deleted 4y ago[deleted]