Class Config

java.lang.Object
smile.onnx.genai.Config
All Implemented Interfaces:
AutoCloseable

public final class Config extends Object implements AutoCloseable
GenAI model configuration: execution providers and overlay JSON.

Providers are applied in insertion order. Typical usage:

try (var config = Config.of("models/phi-3")) {
    config.clearProviders()
          .appendProvider("cuda")
          .setProviderOption("cuda", "device_id", "0");
    try (var model = Model.of(config)) { ... }
}
  • Method Details

    • of

      public static Config of(String modelDir)
      Creates a config from a GenAI model directory.
      Parameters:
      modelDir - path containing genai_config.json and model files.
      Returns:
      a new config owned by the caller.
    • of

      public static Config of(Path modelDir)
      Creates a config from a GenAI model directory.
      Parameters:
      modelDir - path containing genai_config.json and model files.
      Returns:
      a new config owned by the caller.
    • clearProviders

      public Config clearProviders()
      Clears the execution-provider list.
      Returns:
      this for chaining.
    • appendProvider

      public Config appendProvider(String providerName)
      Appends an execution provider if it is not already present.
      Parameters:
      providerName - provider name (e.g. "cpu", "cuda").
      Returns:
      this for chaining.
    • setProviderOption

      public Config setProviderOption(String providerName, String key, String value)
      Sets a provider option.
      Parameters:
      providerName - provider name.
      key - option key.
      value - option value.
      Returns:
      this for chaining.
    • overlay

      public Config overlay(String json)
      Overlays a JSON fragment onto the loaded config.
      Parameters:
      json - JSON string to merge.
      Returns:
      this for chaining.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable