1 unstable release
0.1.0 | Mar 29, 2022 |
---|
#7 in #dialogflow
16KB
220 lines
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:
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
Dependencies
~18–36MB
~650K SLoC