Skip to main content
The OgaModel class is the core interface for loading and managing generative AI models in ONNX Runtime GenAI. It provides methods to create model instances from configuration files or custom configurations.

Class Definition

Defined in: ~/workspace/source/src/ort_genai.h:227

Methods

Create()

Create a new model instance from a configuration path.
const char*
required
Path to the model configuration directory containing the model files and genai_config.json
Returns: std::unique_ptr<OgaModel> - A unique pointer to the created model instance Throws: std::runtime_error if the model cannot be loaded

Example

Create() with Runtime Settings

Create a model with custom runtime settings.
const char*
required
Path to the model configuration directory
const OgaRuntimeSettings&
required
Runtime settings for the model
Returns: std::unique_ptr<OgaModel> - A unique pointer to the created model instance

Example

Create() from Config

Create a model from a custom configuration object.
const OgaConfig&
required
Custom configuration object for the model
Returns: std::unique_ptr<OgaModel> - A unique pointer to the created model instance

Example

GetType()

Get the model type.
Returns: OgaString - The model type (e.g., “gpt2”, “llama”)

Example

GetDeviceType()

Get the device type the model is running on.
Returns: OgaString - The device type (e.g., “cpu”, “cuda”, “dml”)

Example

Complete Example

Here’s a complete example demonstrating model creation and basic usage:

Resource Management

The OgaModel class uses RAII (Resource Acquisition Is Initialization) principles:
  • Models are returned as std::unique_ptr, providing automatic memory management
  • The model is automatically destroyed when the unique pointer goes out of scope
  • No manual cleanup is required

See Also