2 个版本 (1 个稳定版)

使用旧 Rust 2015

1.0.0 2017 年 11 月 15 日
0.1.0 2017 年 2 月 18 日

#918 in 机器学习

自定义许可证

12KB
181

Witty

非官方的 Rust 语言 wit.ai 客户端库。

免责声明

这是一个非官方客户端实现!它不提供任何保证,并且 Wit.ai 对在使用此库时可能出现的任何错误不承担任何责任。

这是将 Wit.ai 的官方 Ruby 客户端 移植到 Rust 的版本。

注意

Wit.ai 决定从 2018 年 1 月 1 日起关闭其聊天机器人/会话 API。此决定导致弃用了 run_actionsconverse 方法。

因此,此库现在仅处理与 Wit.ai 服务器的通信。

有关如何方便过渡的详细说明,请参阅 变更日志

安装

此项目可在 Crates.io 上找到,并可以使用 cargo 进行安装。

[dependencies]
witty = "1.0.0"

用法

要创建客户端,您需要从 Wit.ai 获取一个令牌。

extern crate witty;
use witty::Value; # Serde JSON value struct

fn main() {
    let token = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
    let client = witty::client(token);
    let result = client.message("What's the weather like?");

    match result {
        Ok(response) => println!("The server returns: {:?}", response),
        Err(error) => println!("Something went wrong... {:?}", error)
    };
}

方法

Client 暴露了一个方法

message

用于查询 API 以确定输入消息的含义。

message(
  message: &str
) -> Result<Value, super::http::HttpError>
  • message - wit.ai 将处理的输入消息。

返回值是 API 响应的上下文。

错误

所有错误结构体都包含一个 message 字段和一个 code 字段。 message 字段是可读的,并描述了此错误发生的原因以及从环境收集的任何附加信息。 code 字段表示错误产生的地方和它代表的问题类别。

以下是一个错误列表及其可能的代码和解释

  • ExeccutionError

    • 102 - API 返回了错误类型响应。
    • 105 - API响应返回未知类型。
    • 106 - 连接到API时出现问题。
  • HttpError

    • 100 - 无法连接到服务器
    • 101 - 服务器返回了消息

注意: HttpError 结构体还有一个额外的 status 字段,该字段包含响应的HTTP状态码。此代码还将与规范说明一起在消息中显示。

许可证

本项目采用MIT许可证授权。与Wit.ai无任何关联。

依赖项

~18–28MB
~506K SLoC