You've already forked ui-cviko1
100 lines
2.3 KiB
Plaintext
100 lines
2.3 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"< I go by AI-BOT\n",
|
|
"< it's sunny today\n",
|
|
"< we have to wait for the lake to be frozen\n",
|
|
"< it's sunny today\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",
|
|
"communication_stack = []\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",
|
|
" for word in words:\n",
|
|
" if word in intent_database:\n",
|
|
" communication_stack.append(word)\n",
|
|
" \n",
|
|
" if communication_stack:\n",
|
|
" print(\"<\", random.choice(responses[communication_stack.pop()]))\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
|
|
}
|