Class DeferredTranslatorFactory

java.lang.Object
ai.djl.translate.DeferredTranslatorFactory
All Implemented Interfaces:
TranslatorFactory

public class DeferredTranslatorFactory extends Object implements TranslatorFactory
A TranslatorFactory that creates the Translator based on serving.properties file.

The Criteria API cannot access serving.properties files before it's downloaded. A DeferredTranslatorFactory assumes serving.properties will provide proper Translator. If no translatorFactory is provided in serving.properties, a TranslateException will be thrown.

  • Constructor Details

    • DeferredTranslatorFactory

      public DeferredTranslatorFactory()
  • Method Details

    • getSupportedTypes

      public Set<ai.djl.util.Pair<Type,Type>> getSupportedTypes()
      Returns supported input/output classes.
      Specified by:
      getSupportedTypes in interface TranslatorFactory
      Returns:
      a set of supported input/output classes
    • isSupported

      public boolean isSupported(Class<?> input, Class<?> output)
      Returns if the input/output is supported by the TranslatorFactory.
      Specified by:
      isSupported in interface TranslatorFactory
      Parameters:
      input - the input class
      output - the output class
      Returns:
      true if the input/output type is supported
    • newInstance

      public <I, O> Translator<I,O> newInstance(Class<I> input, Class<O> output, Model model, Map<String,?> arguments) throws TranslateException
      Returns a new instance of the Translator class.
      Specified by:
      newInstance in interface TranslatorFactory
      Type Parameters:
      I - the input data type
      O - the output data type
      Parameters:
      input - the input class
      output - the output class
      model - the Model that uses the Translator
      arguments - the configurations for a new Translator instance
      Returns:
      a new instance of the Translator class
      Throws:
      TranslateException - if failed to create Translator instance