Skip to content

Commit e3b3b3a

Browse files
he-jamesAssemblyAI
andauthored
chore: sync sdk code with DeepLearning repo (#140)
Co-authored-by: AssemblyAI <engineering.sdk@assemblyai.com>
1 parent c23c85a commit e3b3b3a

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

assemblyai/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.44.3"
1+
__version__ = "0.45.0"

assemblyai/types.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,11 @@ class RawTranscriptionConfig(BaseModel):
657657
The speech model to use for the transcription.
658658
"""
659659

660+
speech_models: Optional[List[str]] = None
661+
"""
662+
The list of speech models to use for the transcription in priority order.
663+
"""
664+
660665
prompt: Optional[str] = None
661666
"The prompt used to generate the transcript with the Slam-1 speech model. Can't be used together with `keyterms_prompt`."
662667

@@ -708,6 +713,7 @@ def __init__(
708713
speech_threshold: Optional[float] = None,
709714
raw_transcription_config: Optional[RawTranscriptionConfig] = None,
710715
speech_model: Optional[SpeechModel] = None,
716+
speech_models: Optional[List[str]] = None,
711717
prompt: Optional[str] = None,
712718
keyterms_prompt: Optional[List[str]] = None,
713719
) -> None:
@@ -801,6 +807,7 @@ def __init__(
801807
self.language_detection_options = language_detection_options
802808
self.speech_threshold = speech_threshold
803809
self.speech_model = speech_model
810+
self.speech_models = speech_models
804811
self.prompt = prompt
805812
self.keyterms_prompt = keyterms_prompt
806813

@@ -831,6 +838,16 @@ def speech_model(self, speech_model: Optional[SpeechModel]) -> None:
831838
"Sets the speech model to use for the transcription."
832839
self._raw_transcription_config.speech_model = speech_model
833840

841+
@property
842+
def speech_models(self) -> Optional[List[str]]:
843+
"The list of speech models to use for the transcription in priority order."
844+
return self._raw_transcription_config.speech_models
845+
846+
@speech_models.setter
847+
def speech_models(self, speech_models: Optional[List[str]]) -> None:
848+
"Sets the list of speech models to use for the transcription in priority order."
849+
self._raw_transcription_config.speech_models = speech_models
850+
834851
@property
835852
def prompt(self) -> Optional[str]:
836853
"The prompt to use for the transcription."
@@ -1902,6 +1919,9 @@ class BaseTranscript(BaseModel):
19021919
speech_model: Optional[SpeechModel] = None
19031920
"The speech model to use for the transcription."
19041921

1922+
speech_models: Optional[List[str]] = None
1923+
"The list of speech models to use for the transcription in priority order."
1924+
19051925
prompt: Optional[str] = None
19061926
"The prompt used to generate the transcript with the Slam-1 speech model. Can't be used together with `keyterms_prompt`."
19071927

@@ -1973,6 +1993,9 @@ class TranscriptResponse(BaseTranscript):
19731993
speech_model: Optional[SpeechModel] = None
19741994
"The speech model used for the transcription"
19751995

1996+
speech_model_used: Optional[str] = None
1997+
"The actual speech model that was used for the transcription"
1998+
19761999
prompt: Optional[str] = None
19772000
"When Slam-1 is enabled, the prompt used to generate the transcript"
19782001

tests/unit/test_transcript.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import assemblyai as aai
1010
from assemblyai.api import ENDPOINT_TRANSCRIPT
1111
from tests.unit import factories
12-
from assemblyai.types import SpeechModel
1312

1413
aai.settings.api_key = "test"
1514

@@ -451,3 +450,39 @@ def test_delete_by_id_async(httpx_mock: HTTPXMock):
451450
assert transcript.error is None
452451
assert transcript.text == mock_transcript_response["text"]
453452
assert transcript.audio_url == mock_transcript_response["audio_url"]
453+
454+
455+
def test_speech_model_used_field_deserialization():
456+
"""
457+
Tests that the speech_model_used field can be properly deserialized.
458+
"""
459+
mock_transcript_response = factories.generate_dict_factory(
460+
factories.TranscriptCompletedResponseFactory
461+
)()
462+
463+
# Add speech_model_used to the mock response
464+
mock_transcript_response["speech_model_used"] = "best"
465+
466+
transcript_response = aai.types.TranscriptResponse(**mock_transcript_response)
467+
468+
assert transcript_response.speech_model_used == "best"
469+
470+
471+
def test_speech_model_used_field_missing():
472+
"""
473+
Tests that the speech_model_used field being missing does not break deserialization.
474+
This is important because the field has not yet been added to the API for all users.
475+
"""
476+
mock_transcript_response = factories.generate_dict_factory(
477+
factories.TranscriptCompletedResponseFactory
478+
)()
479+
480+
# Explicitly ensure speech_model_used is not in the response
481+
if "speech_model_used" in mock_transcript_response:
482+
del mock_transcript_response["speech_model_used"]
483+
484+
# This should not raise an exception
485+
transcript_response = aai.types.TranscriptResponse(**mock_transcript_response)
486+
487+
# The field should be None when not present
488+
assert transcript_response.speech_model_used is None

0 commit comments

Comments
 (0)