4

In honor of Weizenbaum's Centenary, I asked ChatGPT to program ELIZA

 1 year ago
source link: https://news.ycombinator.com/item?id=34305518
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

In honor of Weizenbaum's Centenary, I asked ChatGPT to program ELIZA In honor of Weizenbaum's Centenary, I asked ChatGPT to program ELIZA 21 points by abrax3141 3 hours ago | hide | past | favorite | 9 comments

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.

Today, Jan 8th, is the 100th centenary of Joseph Weizenbaum's birth, so I asked ChatGPT to write ELIZA in js.

Long dialog (~10 rounds) short, here's where it ended up:

''' // 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"));

My conclusion: It's not yet up to being a 1970s 13 year old programmer....yet. :-)

---- (Apparently ''' ... ''' doesn't do code in HN. Sorry for the wrap-around formatting.)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK