思知机器人

想在博客里添加闲聊功能,想要一个机器人,之前试过图灵机器

机器人项目汇总

(17条消息) 史上最全面聊天机器人总结,图灵、思知、小爱、小微,作者已接入到自己的开源IM项目中使用_xmcy001122的专栏-CSDN博客_思知机器人

image-20211212161209431

聊天机器人gitee资料

Awesome-Chatbot: 聊天机器人资源合集:项目,语聊,论文,教程。Awesome Chatbot Projects,Corpus,Papers,Tutorials. (gitee.com)

开源聊天工具,安全

自建聊天机器人

自建聊天服务器、机器人与多平台桥接 - 知乎 (zhihu.com)

思知机器人操作

Python+思知机器人=微信聊天自动回复(还会撩妹~) - 简书 (jianshu.com)

# -*- coding:utf-8-*-
import requests
import itchat


headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
        'Referer': 'https://robot.ownthink.com/',
}        #  出于习惯加上的请求头,可无


def get_data(text):
  # 请求思知机器人API所需要的一些信息  
    data = {
        "appid": "填自己的",
        "userid": "填自己的",
        "spoken": text,
    }
    return data


def get_answer(text):
    # 获取思知机器人的回复信息
    data = get_data(text)
    url = 'https://api.ownthink.com/bot'  # API接口
    response = requests.post(url=url, data=data, headers=headers) 
    response.encoding = 'utf-8'
    result = response.json()
    answer = result['data']['info']['text']
    return answer


@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
    myself = itchat.get_friends(update=True)[0]['NickName']
    friend = msg['User']['NickName']
    content = msg['Content']  # 好友发来信息的内容
    if friend != myself and friend != 'FRIEND':
        print('%s: %s' % (friend, content))
        answer = get_answer(msg['Text'])  # 收到信息时,调用思知机器人并获取机器人的回复信息
        itchat.send(answer, msg['FromUserName'])  # 将机器人的回复信息转发给该好友
        print('我:%s' % answer)


itchat.auto_login(hotReload=True)
itchat.run()

知识图谱的使用

知识图谱可视化 - 知乎 (zhihu.com)

import os
import sys
import requests
def KG_View(entity):
    url = 'https://api.ownthink.com/kg/knowledge?entity=%s'%entity      # 知识图谱AP
    sess = requests.get(url) # 请求
    text = sess.text # 获取返回的数据
    response = eval(text) # 转为字典类型
    knowledge = response['data']
    nodes = []
    for avp in knowledge['avp']:
        if avp[1] == knowledge['entity']:
            continue
        node = {'source': knowledge['entity'], 'target': avp[1], 'type': "resolved", 'rela':avp[0]}
        nodes.append(node)
    for node in nodes:
        node = str(node)
        node = node.replace("'type'", 'type').replace("'source'", 'source').replace("'target'", 'target')
        print(node+',')
if __name__=='__main__':
    while True:
        i = input("请输入要查询的内容: " )
        if(i == 'i'):
            break
        try:
            KG_View(i)
        except :
            print("没有该词语")

<!DOCTYPE html>
<meta charset="utf-8">
<style>.link {  fill: none;  stroke: #666;  stroke-width: 1.5px;}#licensing {  fill: green;}.link.licensing {  stroke: green;}.link.resolved {  stroke-dasharray: 0,2 1;}circle {  fill: #ccc;  stroke: #333;  stroke-width: 1.5px;}text {  font: 12px Microsoft YaHei;  pointer-events: none;  text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, 0 -1px 0 #fff, -1px 0 0 #fff;}.linetext {    font-size: 12px Microsoft YaHei;}</style>
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
​
var links = 
[
{source: '艾伦·麦席森·图灵', target: 'Alan Mathison Turing', 'rela': '外文名', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '英国', 'rela': '国籍', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '英国伦敦', 'rela': '出生地', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '1912年6月23日', 'rela': '出生日期', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '1954年6月7日', 'rela': '逝世日期', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '数学家,逻辑学家,密码学家', 'rela': '职业', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '剑桥大学国王学院,普林斯顿大学', 'rela': '毕业院校', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '“计算机科学之父”', 'rela': '主要成就', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '提出“图灵测试”概念', 'rela': '主要成就', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '人工智能', 'rela': '主要成就', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '破解德国的著名密码系统Enigma', 'rela': '主要成就', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '《论数字计算在决断难题中的应用》', 'rela': '代表作品', type: 'resolved'},
{source: '艾伦·麦席森·图灵', target: '《机器能思考吗?》', 'rela': '代表作品', type: 'resolved'},
];
​
var nodes = {};
​
links.forEach(function(link)
{
  link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
  link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
});