Giter Club home page Giter Club logo

turingrobot's Introduction

TuringRobot

图灵机器人的 Unity 脚本,使用 WEB API 通讯。

使用

参考 TuringRobotDemo.cs 使用 TuringRobot.cs 脚本,注意修改 TuringRobotDemo.cs 中的 API_Key 为你注册的图灵机器人 API_Key

声明命名空间:

using HuiHut.Turing;

定义变量:

// 图灵机器人
private TuringRobot turingRobot = new TuringRobot();

// 图灵机器人API Key (此处改为你的 API_Key )
public string API_Key = @"2ee6e84a755b4ac2b5b2cc25d992b03a";

// 随机生成用户ID,用于关联上下文语境
private string userID = new System.Random().Next(0, int.MaxValue).ToString();

// 用户输入消息
private string userMessage = string.Empty;

// 机器人回复的消息
private string robotMessage = string.Empty;

// 机器人返回链接列表
private List<string> robotLinks = new List<string>();

初始化图灵机器人:

// Use this for initialization
void Start()
{
    // 使用设备唯一标识
    userID = SystemInfo.deviceUniqueIdentifier;

    // 初始化图灵机器人
    turingRobot.initRobot(API_Key, userID);
}

聊天:

// 用户消息传入机器人,获取机器人回复信息、回复链接
turingRobot.Chat(userMessage, ref robotMessage, ref robotLinks);

使用回复信息、回复链接:

// 判断返回消息有无链接
if (robotLinks.Count == 0)  // 机器人回复的消息无链接
{
    // Debug输出机器人回复的消息
    Debug.Log("TuringRobot: " + robotMessage);
}
else  // 机器人回复的消息有链接
{
    // Debug输出机器人回复的消息
    Debug.Log("TuringRobot: " + robotMessage);
    // Debug输出机器人回复的每个链接
    foreach (string Link in robotLinks)
        Debug.Log("\n" + Link);
}

turingrobot's People

Contributors

huihut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.