1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use serde_json::json;

pub use crate::api::{API, Texts, TextsBatch};

/// Workflow definition
pub struct Workflow {
    api: API
}

/// Workflow implementation
impl Workflow {
    /// Creates a Workflow instance.
    ///
    /// # Arguments
    /// * `url` - base url of txtai API
    pub fn new(url: &str) -> Workflow {
        Workflow {
            api: API::new(url)
        }
    }

    /// Executes a named workflow using elements as input.
    ///
    /// `name` workflow name
    /// `elements` list of elements to run through workflow
    pub async fn workflow(&self, name: &str, elements: &Vec<&str>) -> TextsBatch {
        // Query parameters
        let params = json!({
            "name": name,
            "elements": elements
        });

        // Execute API call
        Ok(self.api.post("workflow", &params).await?.json().await?)
    }
}