When I was 13 (many decades ago), I wrote the BASIC ELIZA that many of you have probably experienced (if you are of a certain age) or (if you are not ...) you've almost certainly experienced a knock-off of mine.<p>Today, Jan 8th, is the 100th centenary of Joseph Weizenbaum's birth, so I asked ChatGPT to write ELIZA in js.<p>Long dialog (~10 rounds) short, here's where it ended up:<p>'''
// 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?"
]
};<p>// A list of keywords
const keywords = Object.keys(responses);<p>// 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));
}
}
}<p>// Test the function
console.log(generateResponse("I feel sad"));
console.log(generateResponse("I want a new car"));
console.log(generateResponse("I need some help"));<p>'''<p>My conclusion: It's not yet up to being a 1970s 13 year old programmer....yet. :-)<p>----
(Apparently ''' ... ''' doesn't do code in HN. Sorry for the wrap-around formatting.)