decthings

API client for Rust


This page covers the official Rust API client for Decthings. Using it, you can communicate with Decthings from your own Rust code.

Installation

The package is available for installation on Crates.io. To install, run cargo add decthings-api. From your own code, import the client and create a new client instance:

use decthings_api::{DecthingsClient, DecthingsClientOptions};

#[tokio::main]
async fn main() {
    let client = DecthingsClient::new(DecthingsClientOptions {
        api_key: Some("<myapikey>".to_string()),
        ..Default::default()
    });
}

An API key is used to add authentication to the Decthings requests, so that you for example can access your own private models. To create a new API key, navigate to the API keys page. Click create, and a new key will be generated for you. Copy the key and add it to your script:

Replace <myapikey> in the example above with your own key.

Important: Make sure to keep your key safe! Never commit your key to source control such as git, and if you share your code, make sure you don't include your key.

Protocol

The client is smart in choosing the HTTP or WebSocket API - it will use HTTP until an event is being listened to, in which case it will switch to WebSocket and use that until no event is being listened to.

Example

Below are some examples of how you can call methods. Navigate to the desired methods to see more details.

use decthings_api::{
    rpc::{
        dataset::{AddEntriesParams, DataToAddForKey},
        model::{EvaluateParams, GetModelsParams},
    },
    tensor::DecthingsTensor,
    DecthingsClient, DecthingsClientOptions, DecthingsParameterProvider,
    DecthingsParameterProviderData,
};

#[tokio::main]
async fn main() {
    let client = DecthingsClient::new(DecthingsClientOptions {
        api_key: Some("<myapikey>".to_string()),
        ..Default::default()
    });

    let get_models_result = client
        .model
        .get_models(GetModelsParams {
            model_ids: None::<&[String]>,
        })
        .await;

    let evaluate_result = client
        .model
        .evaluate(EvaluateParams {
            model_id: "<modelid>",
            params: vec![DecthingsParameterProvider {
                name: "<parameter>",
                data: DecthingsParameterProviderData::Data(vec![DecthingsTensor::String(
                    decthings_api::ndarray::array!["My input text"]
                        .into_shape([])
                        .unwrap()
                        .into_dyn()
                        .into(),
                )]),
            }],
            snapshot_id: None,
        })
        .await;

    let add_entries_result = client
        .dataset
        .add_entries(AddEntriesParams {
            dataset_id: "<datasetid>",
            keys: vec![DataToAddForKey {
                key: "<key>",
                data: vec![DecthingsTensor::I32(
                    decthings_api::ndarray::array![7]
                        .into_shape([])
                        .unwrap()
                        .into_dyn()
                        .into(),
                )],
            }],
            dataset_version_id: None,
        })
        .await;
}

Product

  • Documentation
  • Pricing
  • API reference
  • Guides

Company

  • Support

Get going!

Sign up
  • Terms and conditions
  • Privacy policy
  • Cookie policy
  • GitHub
  • LinkedIn

This website uses cookies to enhance the experience.

Learn more