# Local plugin (works with any metadata object with config_schema)local_plugin = PluginMetadata( name="whisper", config_schema={"properties": {"model_id": {"type": "string"},"device": {"type": "string"} } })# API-based plugin api_plugin = PluginMetadata( name="openai-whisper", config_schema={"properties": {"api_key": {"type": "string"}, # Presence of api_key indicates API-based"model": {"type": "string"} } })
Compatibility: These utilities are compatible with: - PluginMetadata from cjm-fasthtml-plugins - SimplePluginRegistry from cjm-fasthtml-settings - UnifiedPluginRegistry from cjm-fasthtml-plugins - Any custom object with a config_schema attribute
GPU Detection
Helper functions to determine if a plugin will use GPU resources.
Extract the plugin resource identifier from plugin configuration. Checks common plugin resource configuration keys like ‘resource_id’, ‘model_id’, ‘model’, ‘model_name’, etc.
Type
Details
plugin_config
Dict
The plugin’s configuration
Returns
Optional
Plugin resource identifier string, or None if not found
# Example: Extract resource identifiers from different configsconfigs = [ {"model_id": "whisper-large-v3", "device": "cuda"}, {"model": "llama-3.1-8b", "device": "auto"}, {"model_path": "/models/custom-model", "device": "cpu"}, {"device": "cuda"} # No resource ID]for config in configs: resource_id = get_plugin_resource_identifier(config)print(f"Config {config}: Resource ID = {resource_id}")
Config {'model_id': 'whisper-large-v3', 'device': 'cuda'}: Resource ID = whisper-large-v3
Config {'model': 'llama-3.1-8b', 'device': 'auto'}: Resource ID = llama-3.1-8b
Config {'model_path': '/models/custom-model', 'device': 'cpu'}: Resource ID = /models/custom-model
Config {'device': 'cuda'}: Resource ID = None
Resource Comparison
Compare two plugin configurations to determine if they use the same resource.
Compare two plugin configurations to see if they use the same plugin resource.
Type
Details
config1
Dict
First plugin configuration
config2
Dict
Second plugin configuration
Returns
bool
True if both configs specify the same plugin resource, False otherwise
# Example: Compare configurationsconfig_a = {"model_id": "whisper-large-v3", "device": "cuda"}config_b = {"model_id": "whisper-large-v3", "device": "cpu"} # Same resource, different deviceconfig_c = {"model_id": "whisper-medium", "device": "cuda"} # Different resourceprint(f"A vs B (same resource): {compare_plugin_resources(config_a, config_b)}")print(f"A vs C (different resource): {compare_plugin_resources(config_a, config_c)}")print(f"B vs C (different resource): {compare_plugin_resources(config_b, config_c)}")
A vs B (same resource): True
A vs C (different resource): False
B vs C (different resource): False
Combined Resource Requirements
Get comprehensive resource requirements for a plugin.
Plugin registry instance with get_plugin, load_plugin_config methods
plugin_config
Optional
None
Optional plugin configuration
Returns
Dict
Dictionary with resource requirement information (is_local, uses_gpu, plugin_resource, device)
This function is the main entry point for getting plugin resource information. It combines all the other utility functions to provide a complete picture of a plugin’s resource requirements.