Build Converter Strategy
Build config dataclasses and strategy helpers for modality converter construction.
KwargsBuildConfig(kwargs=dict())
dataclass
Config for building a converter using raw keyword arguments.
build(cls)
Build a converter using raw keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type[BaseModalityConverter]
|
The converter class to build. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BaseModalityConverter |
BaseModalityConverter
|
The built converter. |
LMRPBuildConfig(lmrp_config, extra_kwargs=dict())
dataclass
Config for building a converter using an LMRP configuration.
build(cls)
Build a converter using an LMRP configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type[BaseModalityConverter]
|
The converter class to build. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BaseModalityConverter |
BaseModalityConverter
|
The built converter. |
PresetBuildConfig(preset, extra_kwargs=dict())
dataclass
Config for building a converter using a named preset.
build(cls)
Build a converter using a named preset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type[BaseModalityConverter]
|
The converter class to build. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BaseModalityConverter |
BaseModalityConverter
|
The built converter. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the class does not implement |
build_config_from_params(strategy, preset, kwargs)
Construct the typed build config for the given strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
ModalityConverterBuildStrategy
|
The build strategy. |
required |
preset
|
str | None
|
The preset name, required for PRESET strategy. |
required |
kwargs
|
dict[str, Any]
|
Remaining keyword arguments from the caller. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ConverterBuildConfig |
ConverterBuildConfig
|
Config instance carrying the build logic for the strategy. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the strategy is unsupported or required params are missing. |
determine_build_strategy(preset, kwargs)
Determine the build strategy from the provided configuration.
Priority by order: 1. LMRP config -> LMRP strategy 2. Preset -> PRESET strategy 3. Fallback -> KWARGS strategy
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset
|
str | None
|
The preset to use. |
required |
kwargs
|
dict[str, Any]
|
Additional keyword arguments. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ModalityConverterBuildStrategy |
ModalityConverterBuildStrategy
|
The determined build strategy. |
determine_transcriber_approach(model_id)
Determine the modality converter approach based on the model ID's provider and name.
This helper is used to automatically select the most appropriate transcription approach (e.g., Gemini, Google Cloud, Whisper, Prosa) when building an audio-to-text converter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
ModelId
|
The model ID to inspect, containing provider and name information. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ModalityConverterApproach |
'ModalityConverterApproach'
|
The determined approach for transcription. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the modality converter approach cannot be determined for the given model ID. |
Example
Determining approach from model ID
from gllm_inference.schema.model_id import ModelId
# Gemini model -> LM_BASED approach
model_id = ModelId.from_string("google/gemini-1.5-pro")
approach = determine_transcriber_approach(model_id)
print(approach) # ModalityConverterApproach.GEMINI
# Prosa model -> ASR approach
model_id = ModelId.from_string("prosa/v2")
approach = determine_transcriber_approach(model_id)
print(approach) # ModalityConverterApproach.PROSA
determine_transcript_approach(model_id)
Determine the canonical transcription approach based on model metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
ModelId
|
The model ID to inspect. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ModalityConverterApproach |
'ModalityConverterApproach'
|
Canonical approach type ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the approach cannot be determined for the given model ID. |
determine_transcript_provider(model_id)
Determine the transcript provider implied by a model ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
ModelId
|
The model ID to inspect. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider name when inferable (e.g. |