typed-dialogflow

Crates.iotyped-dialogflow
lib.rstyped-dialogflow
version0.1.0
sourcesrc
created_at2022-03-29 17:05:22.552645
updated_at2022-03-29 17:05:22.552645
descriptionAn easy-to-use typed Google Dialogflow client
homepage
repositoryhttps://github.com/edgarogh/typed-dialogflow
max_upload_size
id558643
size54,958
Edgar Onghena (edgarogh)

documentation

README

typed-dialogflow

An easy-to-use typed Google Dialogflow client for Rust

This library was extracted from a personal project. As a result, it may still be very basic and quite rigid. However, I'm all for this library growing and becoming more capable.

Example

The concept of this library is to provide a relatively type-safe interface to Dialogflow. Intents are modelled as a single Rust enum that you can pattern-match on.

Take the following Dialogflow intents:

A screenshot of the Dialogflow dashboard with 3 intents named "hello", "weather" and "thank_you"

You can then query and deserialize intents with this code :

#[derive(Debug, Eq, PartialEq, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
enum Intent {
  Hello,
  Weather {
    location: String,
  },
  ThankYou,
}

let intent = dialogflow.detect_intent_serde::<Intent>("What's the weather like in Antarctica ?").await.unwrap();

match intent {
  Intent::Weather { location } => println!("The user asked for the weather in/at {location}"),
  ...
}

Testing

Due to the private / proprietary / externally-hosted nature of Dialogflow, testing this library isn't as easy as any other library. In addition to that, because Dialogflow relies on AI, there's always a small probability that a text may be interpreted differently if the model is re-trained, making tests undeterministic. I could eventually try to make the Google Backend mockable to test the deserialization part of the library. Besides that, I'm running tests locally on a private Dialogflow model, but having tests run on only one computer makes it impossible to enforce rules about having the code pass tests before being commited.

License

MIT OR APACHE-2.0

Commit count: 4

cargo fmt