{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "< I can't understand you.\n", "< the weather is sunny\n", "< I don't know, sorry.\n", "< I can't answer that.\n", "< I don't know, sorry.\n", "< good winter time!\n", "< Bye\n" ] } ], "source": [ "import random\n", "import re\n", "\n", "no_responses = [\n", " \"I can't answer that.\",\n", " \"I don't know, sorry.\",\n", " \"I can't understand you.\",\n", " \"Can you elaborate, please?\"\n", "]\n", "\n", "responses = {\n", " \"name\": [\n", " \"my name is AI-BOT\",\n", " \"they call me AI-BOT\",\n", " \"I go by AI-BOT\"\n", " ],\n", " \"weather\": [\n", " \"the weather is sunny\",\n", " \"it's sunny today\"\n", " ],\n", " \"hockey\": [\n", " \"good winter time!\",\n", " \"we have to wait for the lake to be frozen\"\n", " ]\n", "}\n", "\n", "intent_database = [key for key in responses.keys()]\n", "\n", "while True:\n", " message = input(\"> \")\n", "\n", " if message == \"bye\":\n", " print(\"< Bye\")\n", " break\n", " \n", " message = re.sub(\"[ ,.?!:;]\", \" \", message)\n", " words = message.split()\n", "\n", " intent_word = next((word for word in words if word in intent_database), None)\n", " if intent_word != None:\n", " print(\"<\", random.choice(responses[intent_word]))\n", " else:\n", " print(\"<\", random.choice(no_responses))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "ui-cviko1", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.2" } }, "nbformat": 4, "nbformat_minor": 2 }