Key Features
- Model loading and configuration
- Text generation with customizable parameters
- Tokenization and decoding
- Multi-modal processing (images and audio)
- Adapter support for model customization
- Engine-based request scheduling
Memory Management
The C API follows a consistent pattern for memory management:Object Lifecycle
- Creation: Objects are created through
OgaCreate*()functions that return a pointer to the object - Usage: Objects are passed to other API functions
- Destruction: Objects must be explicitly destroyed using corresponding
OgaDestroy*()functions
Example Pattern
Error Handling
All API functions that can fail return anOgaResult* pointer:
- Success: Returns
NULL - Failure: Returns a pointer to an
OgaResultobject containing error information
Error Handling Pattern
OgaResult. The returned string is owned by the OgaResult and will be freed when the result is destroyed.OgaResult object and frees its resources.Example
Basic Usage Pattern
Here’s a complete example of using the C API for text generation:Library Initialization and Shutdown
Logging Configuration
name: The name of the logging optionvalue: The boolean value to set
name: The name of the logging optionvalue: The string value to set
nullptr to disable callback and revert to the default destination.Parameters:callback: Function pointer to the logging callback (ornullptrto disable)
String Management
GPU Device Management
device_id: The GPU device ID to use
device_id: Pointer to store the current GPU device ID
Execution Provider Registration
registration_name: Name for the registrationlibrary_path: Path to the provider library
registration_name: Name of the registration to unregister
Next Steps
Model Functions
Learn about model creation, configuration, and management
Generator Functions
Explore text generation and inference capabilities