-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extensions][py][hf] 1/n asr scaffolding
Setting up the asr parser class
- Loading branch information
1 parent
3f0cbce
commit 485faf6
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...ython/src/aiconfig_extension_hugging_face/local_inference/automatic_speech_recognition.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from typing import Any, Coroutine, Dict, Optional, List, TYPE_CHECKING | ||
from aiconfig import ParameterizedModelParser, InferenceOptions, AIConfig | ||
|
||
from aiconfig.schema import Prompt, Output | ||
from transformers import Pipeline | ||
|
||
if TYPE_CHECKING: | ||
from aiconfig import AIConfigRuntime | ||
""" | ||
Model Parser for HuggingFace ASR (Automatic Speech Recognition) models. | ||
""" | ||
|
||
|
||
class HuggingFaceAutomaticSpeechRecognition(ParameterizedModelParser): | ||
def __init__(self): | ||
""" | ||
Returns: | ||
HuggingFaceAutomaticSpeechRecognition | ||
Usage: | ||
1. Create a new model parser object with the model ID of the model to use. | ||
parser = HuggingFaceAutomaticSpeechRecognition() | ||
2. Add the model parser to the registry. | ||
config.register_model_parser(parser) | ||
""" | ||
super().__init__() | ||
self.generators: dict[str, Pipeline] = {} | ||
|
||
def id(self) -> str: | ||
""" | ||
Returns an identifier for the Model Parser | ||
""" | ||
return "HuggingFaceAutomaticSpeechRecognition" | ||
|
||
async def serialize( | ||
self, | ||
prompt_name: str, | ||
data: Any, | ||
ai_config: "AIConfigRuntime", | ||
parameters: Optional[Dict[str, Any]] = None, | ||
**completion_params, | ||
) -> List[Prompt]: | ||
""" | ||
Defines how a prompt and model inference settings get serialized in the .aiconfig. | ||
Args: | ||
prompt (str): The prompt to be serialized. | ||
data (Any): Model-specific inference settings to be serialized. | ||
ai_config (AIConfigRuntime): The AIConfig Runtime. | ||
parameters (Dict[str, Any], optional): Model-specific parameters. Defaults to None. | ||
Returns: | ||
str: Serialized representation of the prompt and inference settings. | ||
""" | ||
|
||
async def deserialize( | ||
self, | ||
prompt: Prompt, | ||
aiconfig: "AIConfig", | ||
params: Optional[Dict[str, Any]] = {}, | ||
) -> Dict[str, Any]: | ||
pass | ||
|
||
async def run_inference(self, prompt: Prompt, aiconfig: "AIConfigRuntime", options: InferenceOptions, parameters: Dict[str, Any]) -> list[Output]: | ||
pass |