Text Inputs

Include plain text inputs within inference requests sent to Modzy

Many NLP models, and some tabular models, work exclusively with text-based inputs. Modzy uses a simple JSON structure for including plain text inputs directly in the body of an inference submission. The examples below demonstrate how to submit plain text to any model that accepts plain text as an input. Each of these examples submit the same input to Modzy's Sentiment Analysis model, but do so in different languages and with different SDKs. In the example below, you will need to replace placeholder values with valid inputs:

  • Replace API_KEY with a valid API key string
  • If necessary, replace https://app.modzy.com/ with the URL of your instance of Modzy

Single Input

curl https://app.modzy.com/api/jobs -X POST \
 -H 'Content-Type: application/json' \
 -H 'Authorization: ApiKey API_KEY' \
 -d '{
      "model": {
        "identifier": "ed542963de",
        "version": "1.0.1"
      },
      "input": {
        "type": "text",
        "sources": {
          "first-phone-call": {
            "input.txt": "Mr Watson, come here. I want to see you."
          }
        }
      }
    }'
import json
from modzy import ApiClient
from modzy._util import file_to_bytes

#Initialize your Modzy client
client = ApiClient(base_url="https://app.modzy.com/api", api_key=API_KEY)

#Create a dictionary for your text input(s)
sources = {}

#Add any number of inputs
sources["first-phone-call"] = {
    "input.txt": "Mr Watson, come here. I want to see you.",
}

#Once you are ready, submit the job
job = client.jobs.submit_text("ed542963de", "1.0.1", sources)

#Print the response from your job submission
print(json.dumps(job))
const modzy = require("@modzy/modzy-sdk");

//Initialize the client
const modzyClient = new modzy.ModzyClient("https://app.modzy.com/api", API_KEY)

let sources = {};
//Add any number of inputs
sources["first-phone-call"] = {
    "input.txt": "Mr Watson, come here. I want to see you.",
};

//Once you are ready, submit the job
modzyClient
  .submitJobText("ed542963de", "1.0.1", sources)
  .then(
    (job)=>{
      console.log(JSON.stringify(job));
    }
  )
  .catch(
    (error)=>{
      console.error("Modzy job submission failed with code " + error.code + " and message " + error.message);
    }
  );
package main

import (
    "context"
    "log"
    "time"

    modzy "github.com/modzy/sdk-go"
)

func main() {
    ctx := context.TODO()
  // Replace BASE_URL and API_KEY with valid values
    baseURL := "https://app.modzy.com"
    apiKey := API_KEY

  // Initialize the API client
    client := modzy.NewClient(baseURL).WithAPIKey(apiKey)

  // Create a map with a single text input
    mapSource := map[string]modzy.TextInputItem{
        "first-phone-call": {
            "input.txt": "Mr Watson, come here. I want to see you.",
        },
    }

  // Send your input to the sentiment analysis model by specifying ID and version number
    submitResponse, _ := client.Jobs().SubmitJobText(ctx, &modzy.SubmitJobTextInput{
        ModelIdentifier: "ed542963de",
        ModelVersion:    "1.0.1",
        Inputs:          mapSource,
    })

  // Check on the status of your request to analyze the sentiment of your input once a second
    jobDetails, _ := submitResponse.WaitForCompletion(ctx, time.Second)

  //When the input is done processing, retrive the results from Modzy, and log them to your terminal
    if jobDetails.Details.Status == modzy.JobStatusCompleted {
        results, _ := submitResponse.GetResults(ctx)
        for key := range mapSource {
            if result, exists := results.Results.Results[key]; exists {
                log.Printf("    %s:\n", key)
                modelRes := result.Data["results.json"].(map[string]interface{})
                for key2, val2 := range modelRes {
                    log.Printf("    %s:%f\n", key2, val2)
                }
            }
        }
    }
}
package mysample;

import com.modzy.sdk.ModzyClient;
import com.modzy.sdk.model.Job;
import com.modzy.sdk.model.JobInput;
import com.modzy.sdk.model.JobInputStream;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

public class JobSample{

  public static void main(String args[]) throws Exception{
    ModzyClient modzyClient = new ModzyClient("https://app.modzy.com/api", API_KEY);
    JobInput<String> jobInput = new JobInputText();
    Map<String,String> mapSource = new HashMap<>();
    //Add any number of inputs
    mapSource.put("input.txt", "Mr Watson, come here. I want to see you.");
    jobInput.addSource("first-phone-call", mapSource);
    //Once you are ready, submit the job
    Job job = modzyClient.getJobClient().submitJob("ed542963de", "1.0.1", jobInput);
    System.out.println(String.format("job: %s", job));
  }

}

Multiple Inputs

If you would like to process multiple inputs in the same inference submission, you can do so by adding multiple plain text inputs to the sources object in your request.

curl https://app.modzy.com/api/jobs -X POST \
 -H 'Content-Type: application/json' \
 -H 'Authorization: ApiKey API_KEY' \
 -d '{
      "model": {
        "identifier": "ed542963de",
        "version": "1.0.1"
      },
      "input": {
        "type": "text",
        "sources": {
            "Review 1": {
                "input.txt": "Great CD"
            },
            "Review 2": {
                "input.txt": "One of the best game music soundtracks - for a game I didnt really play"
            },
            "Review 3": {
                "input.txt": "Batteries died within a year ..."
            },
            "Review 4": {
                "input.txt": "works fine, but Maha Energy is better"
            }
          }
        }
      }
    }'
import json
from modzy import ApiClient
from modzy._util import file_to_bytes

#Initialize your Modzy client
client = ApiClient(base_url="https://app.modzy.com/api", api_key=API_KEY)

#Create a dictionary for your text input(s)
sources = {}

#Add any number of inputs
sources["Review 1"] = {
  "input.txt": "Great CD",
}
sources["Review 2"] = {
  "input.txt": "One of the best game music soundtracks - for a game I didnt really play",
}
sources["Review 3"] = {
  "input.txt": "Batteries died within a year ...",
}
sources["Review 4"] = {
  "input.txt": "works fine, but Maha Energy is better",
}

#Once you are ready, submit the job
job = client.jobs.submit_text("ed542963de", "1.0.1", sources)

#Print the response from your job submission
print(json.dumps(job))
const modzy = require("@modzy/modzy-sdk");

//Initialize the client
const modzyClient = new modzy.ModzyClient("https://app.modzy.com/api", API_KEY)

let sources = {};
//Add any number of inputs
sources["Review 1"] = {
  "input.txt": "Great CD",
};
sources["Review 2"] = {
  "input.txt": "One of the best game music soundtracks - for a game I didnt really play",
};
sources["Review 3"] = {
  "input.txt": "Batteries died within a year ...",
};
sources["Review 4"] = {
  "input.txt": "works fine, but Maha Energy is better",
};

//Once you are ready, submit the job
modzyClient
  .submitJobText("ed542963de", "1.0.1", sources)
  .then(
    (job)=>{
      console.log(JSON.stringify(job));
    }
  )
  .catch(
    (error)=>{
      console.error("Modzy job submission failed with code " + error.code + " and message " + error.message);
    }
  );
package main

import (
    "context"
    "log"
    "time"

    modzy "github.com/modzy/sdk-go"
)

func main() {
    ctx := context.TODO()
  // Replace BASE_URL and API_KEY with valid values
    baseURL := "https://app.modzy.com"
    apiKey := API_KEY

  // Initialize the API client
    client := modzy.NewClient(baseURL).WithAPIKey(apiKey)

  // Create a map with multiple inputs
    mapSource := map[string]modzy.TextInputItem{
        "Review 1": {
            "input.txt": "Great CD",
        },
        "Review 2": {
            "input.txt": "One of the best game music soundtracks - for a game I didnt really play",
        },
        "Review 3": {
            "input.txt": "Batteries died within a year ...",
        },
        "Review 4": {
            "input.txt": "works fine, but Maha Energy is better",
        },
    }

  // Send your input to the sentiment analysis model by specifying ID and version number
    submitResponse, _ := client.Jobs().SubmitJobText(ctx, &modzy.SubmitJobTextInput{
        ModelIdentifier: "ed542963de",
        ModelVersion:    "1.0.1",
        Inputs:          mapSource,
    })

  // Check on the status of your request to analyze the sentiment of your input once a second
    jobDetails, _ := submitResponse.WaitForCompletion(ctx, time.Second)

  //When the input is done processing, retrive the results from Modzy, and log them to your terminal
    if jobDetails.Details.Status == modzy.JobStatusCompleted {
        results, _ := submitResponse.GetResults(ctx)
        for key := range mapSource {
            if result, exists := results.Results.Results[key]; exists {
                log.Printf("    %s:\n", key)
                modelRes := result.Data["results.json"].(map[string]interface{})
                for key2, val2 := range modelRes {
                    log.Printf("    %s:%f\n", key2, val2)
                }
            }
        }
    }
}
package mysample;

import com.modzy.sdk.ModzyClient;
import com.modzy.sdk.model.Job;
import com.modzy.sdk.model.JobInput;
import com.modzy.sdk.model.JobInputStream;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

public class JobSample{

  public static void main(String args[]) throws Exception{
    ModzyClient modzyClient = new ModzyClient("https://app.modzy.com/api", API_KEY);
    JobInput<String> jobInput = new JobInputText();
    Map<String,String> mapSource = new HashMap<>();
    //Add any number of inputs
    mapSource.put("input.txt", "Mr Watson, come here. I want to see you.");
    jobInput.addSource("first-phone-call", mapSource);
    //Once you are ready, submit the job
    Job job = modzyClient.getJobClient().submitJob("ed542963de", "1.0.1", jobInput);
    System.out.println(String.format("job: %s", job));
  }

}

Did this page help you?