From 733be9db760acd38e41f15f69bd0930373e3306d Mon Sep 17 00:00:00 2001 From: honeybear <952787097@qq.com> Date: Thu, 13 Jul 2023 14:46:42 +0000 Subject: [PATCH] add js/artificial-intelligence.js. Signed-off-by: honeybear <952787097@qq.com> --- js/artificial-intelligence.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 js/artificial-intelligence.js diff --git a/js/artificial-intelligence.js b/js/artificial-intelligence.js new file mode 100644 index 0000000..b53dac5 --- /dev/null +++ b/js/artificial-intelligence.js @@ -0,0 +1,27 @@ +// 定义一个对象,包含问题和对应的回答 +var knowledgeBase = { + "你好": "你好,有什么我可以帮助你的吗?", + "你是谁": "我是AI智能客服系统。", + "天气怎么样": "你在哪个城市?", + "北京": "北京的天气是晴朗的。", + "上海": "上海的天气是多云的。", + "谢谢": "不客气,有什么其他问题我可以帮助你的吗?" +}; + +// 定义一个函数,用于处理用户输入的问题 +function processInput(input) { + // 遍历知识库,查找匹配的问题 + for (var question in knowledgeBase) { + if (input.includes(question)) { + return knowledgeBase[question]; // 返回匹配的回答 + } + } + + // 如果没有匹配的问题,返回默认回答 + return "抱歉,我不明白你的问题。"; +} + +// 测试代码 +var userInput = "天气怎么样"; +var answer = processInput(userInput); +console.log(answer); // 输出:"你在哪个城市?" \ No newline at end of file -- Gitee