4 releases
Uses old Rust 2015
0.1.1 | Jun 15, 2017 |
---|---|
0.1.0 | Apr 1, 2017 |
0.0.4 | Jun 15, 2017 |
0.0.1 | Apr 1, 2017 |
#75 in #microsoft
27KB
521 lines
Cogs
Non-blocking Microsoft Cognition APIs client for Rust.
WIP
Note: Since Tokio-based Hyper is not yet published to Crates.io, this lib hasn't been published yet either.
Usage
Library
You'll need to clone this repo and specify a path.
cogs = { path = "$cloned_path" }
Command line
Clone this repo, cd into it, then run
cargo install
Then either set an AZURE_SUBSCRIPTION_KEY
in your environment, or pass it in via command line.
cogs --from=en --to=de --repl
**************************** Cogs ****************************
Enter text and get back a translation. Ctrl+C to exit.
Hi, my name is Lloyd.
Hallo, ist mein Name Lloyd.
Links
- Translation API docs here
lib.rs
:
Cogs is a non-blocking client for Microsoft cognition services
Although it is a WIP and not all the APIs are implemented, it contains enough infrastructure for you to being using it. All you need to do to add support for a new endpoint is to implement Cog (see cogs module) for your endpoint. To see an example of this, check the translations module.
Example usage
let mut core = tokio_core::reactor::Core::new().unwrap();
let handle = core.handle();
let client = hyper::Client::configure()
.connector(hyper_tls::HttpsConnector::new(4, &handle).unwrap())
.keep_alive(true)
.build(&handle);
let credentials = Credentials::new(sub_key);
let engine = Engine::new(credentials, client);
let translate_req = TranslateRequest {
text: "Hello",
from: Some("en"),
to: "de",
content_type: None,
category: None,
};
let work = engine.run(translate_req);
// TODO: get a sandbox key so this actually comes back as "Hallo"
assert_eq!(core.run(work).unwrap(), "")
Dependencies
~10–19MB
~261K SLoC