Handling Input / Output with Inferless
To build APIs with inferless you need to follow Inference Protocol v2. You can define all the inputs that you need to process the model in a schema file ‘input_schema.py’. For outputs you can return a dict with key and value pairs for different outputs.
Input Schema
You have to define the input_schema.py in your GitHub/Gitlab repository this will help us create the Input parameters :
For each input, there are 3 fields required
-
datatype: “STRING”, “BOOL”, “INT8”, “INT16”, “INT32”, “FP16” “FP32”, “UINT8”, “UINT16”, “UINT32”, “UINT64”, “INT64” , “FP64” , “BYTES”, “BF16”
-
shape: The length of the array, If the shape is [1] you will get the variable, if the array > 1 you will get an array, If the length is variable you can put -1
-
required: If the parameter is required in all API calls
-
example( optional ): Sample value for calling the API
In code
In input_schema.py
Output Schema
You can return any dictionary in the return statement of app.py. You don’t need to provide any configuration. There are some limitations on the dictories that you can return.
Possible return types are
- String
- Float
- Int
- List[String|Float|Int]
You can’t have nested dictionaries, arrays of arrays, or arrays of dictionaries.
If you have nested Object/Dictionary you can serialise the object to JSON and return the JSON string.