simplify the model selector

This commit is contained in:
LUIS NOVO 2024-10-30 14:30:29 -03:00
parent 8bb5db158f
commit 859b7f6e7e
6 changed files with 151 additions and 75 deletions

View file

@ -8,8 +8,6 @@ from typing import Optional
from openai import OpenAI
from open_notebook.domain.models import Model
@dataclass
class SpeechToTextModel(ABC):
@ -42,21 +40,3 @@ class OpenAISpeechToTextModel(SpeechToTextModel):
model=self.model_name, file=audio
)
return transcription.text
SPEECH_TO_TEXT_CLASS_MAP = {
"openai": OpenAISpeechToTextModel,
}
# todo: acho que dá pra juntar todos os get models em uma coisa só
def get_speech_to_text_model(model_id):
assert model_id, "Model ID cannot be empty"
model = Model.get(model_id)
if not model:
raise ValueError(f"Model with ID {model_id} not found")
if model.provider not in SPEECH_TO_TEXT_CLASS_MAP.keys():
raise ValueError(
f"Provider {model.provider} not compatible with Embedding Models"
)
return SPEECH_TO_TEXT_CLASS_MAP[model.provider](model_name=model.name)