当前位置: 首页 > news >正文

关于我用AI编写了一个聊天机器人……(7)

此次更新为v1.3.4版本,更新内容:增加显示时间功能

代码如下:

#include <bits/stdc++.h>
#include <ctime> 
using namespace std;
string userInput;
class VirtualRobot {
public:void chat() {cout << "你好!我是你的虚拟机器人。你想和我聊些什么?" << endl;while (true) {cout << "你: ";getline(cin, userInput);if (userInput == "退出") {cout << "虚拟机器人: 再见!" << endl;break;} else {cout << "虚拟机器人: " << generateResponse(userInput) << endl;}}}
private:string generateResponse(const string& input) {string response;// 转换输入字符串为小写,便于匹配string lowercaseInput = input;transform(lowercaseInput.begin(), lowercaseInput.end(), lowercaseInput.begin(), ::tolower);if (containsKeyword(lowercaseInput, "你是谁")) {  response = "我是你的虚拟机器人" ;  } else if (containsKeyword(lowercaseInput, "退出")) {  response = "好的,再见!";} else if (containsKeyword(lowercaseInput, "打开")) {  response = "对不起,我不能打开任何东西。";  } else if (containsKeyword(lowercaseInput, "谢谢")) {response = "不客气!";} else if (containsKeyword(lowercaseInput, "你好")) {response = "你好!有什么我可以帮到你的吗?";} else if (containsKeyword(lowercaseInput, "你能干什么")||containsKeyword(lowercaseInput, "你的功能")) {response = "我可以和你聊天,并回答你关于编程、技术和计算机相关的问题。";} else if (containsKeyword(lowercaseInput, "什么语言")) {response = "我是用C++开发的。";} else if (containsKeyword(lowercaseInput, "感谢")) {response = "不客气,有什么我可以帮到你的吗?";}else if (containsKeyword(lowercaseInput, "现在时间")) {time_t curtime;time(&curtime);response = ctime(&curtime);} else {response = "抱歉,我还不知道该如何回答这个问题。";}return response;}bool containsKeyword(const string& input, const string& keyword) {// 检查输入字符串是否包含关键词return input.find(keyword) != string::npos;}
};int main() {cout<<"-----chatrobot v1.3.4-----"<<endl; VirtualRobot robot;robot.chat();return 0;
}

c++获取系统时间参考:https://blog.csdn.net/qq_33210042/article/details/119822899

http://www.lryc.cn/news/292035.html

相关文章:

  • WebService的services.xml问题
  • 永久删除 Elasticsearch 中的主节点
  • 从搜索引擎到答案引擎:LLM驱动的变革
  • IDEA如何进行远程Debug调试
  • 故障诊断 | 一文解决,GRU门控循环单元故障诊断(Matlab)
  • C语言数据结构之二叉树
  • 《HTML 简易速速上手小册》第1章:HTML 入门(2024 最新版)
  • 笔记本电脑Win11重装系统教程
  • 突破编程_C++_面试(基础知识(3))
  • AI的安全应答之道
  • 【昕宝爸爸小模块】日志系列之什么是分布式日志系统
  • 如何在淘宝和Shopee上进行选品:策略和原则
  • C++/数据结构:二叉搜索树的实现与应用
  • C++引用、内联函数、auto关键字介绍以及C++中无法使用NULL的原因
  • RabbitMQ之三种队列之间的区别及如何选型
  • 【ArcGIS微课1000例】0099:土地利用变化分析
  • 学习鸿蒙基础(2)
  • 2024年美国大学生数学建模竞赛思路与源代码【2024美赛C题】
  • Windows11搭建GPU版本PyTorch环境详细过程
  • Springboot项目基础配置:小白也能快速上手!
  • 20240127在ubuntu20.04.6下配置whisper
  • C# 递归执行顺序
  • go 实现暴力破解数独
  • go语言-字符串处理常用函数
  • DevOps落地笔记-05|非功能需求:如何有效关注非功能需求
  • vs 撤销本地 commit 并保留更改
  • 深度解读NVMe计算存储协议-1
  • CHS_06.2.3.4_2+用信号量实现进程互斥、同步、前驱关系
  • Web实战丨基于Django的简单网页计数器
  • mysql8安装基础操作(一)