Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assemblyai/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.5.2"
__version__ = "1.5.3"
72 changes: 43 additions & 29 deletions assemblyai/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,11 +1025,12 @@ class RawTranscriptionConfig(BaseModel):
"The domain to use for the transcription (e.g. 'medical-v1')."

if pydantic_v2:
model_config = ConfigDict(extra="allow")
model_config = ConfigDict(extra="allow", validate_assignment=True)
else:

class Config:
extra = "allow"
validate_assignment = True


class TranscriptionConfig:
Expand Down Expand Up @@ -1059,13 +1060,15 @@ def __init__(
redact_pii: Optional[bool] = None,
redact_pii_audio: Optional[bool] = None,
redact_pii_audio_quality: Optional[PIIRedactedAudioQuality] = None,
redact_pii_audio_options: Optional[RedactPiiAudioOptions] = None,
redact_pii_audio_options: Optional[
Union[RedactPiiAudioOptions, Dict[str, Any]]
] = None,
redact_pii_policies: Optional[List[PIIRedactionPolicy]] = None,
redact_pii_sub: Optional[PIISubstitutionPolicy] = None,
redact_pii_return_unredacted: Optional[bool] = None,
speaker_labels: Optional[bool] = None,
speakers_expected: Optional[int] = None,
speaker_options: Optional[SpeakerOptions] = None,
speaker_options: Optional[Union[SpeakerOptions, Dict[str, Any]]] = None,
content_safety: Optional[bool] = None,
content_safety_confidence: Optional[int] = None,
iab_categories: Optional[bool] = None,
Expand All @@ -1080,7 +1083,9 @@ def __init__(
auto_highlights: Optional[bool] = None,
language_detection: Optional[bool] = None,
language_confidence_threshold: Optional[float] = None,
language_detection_options: Optional[LanguageDetectionOptions] = None,
language_detection_options: Optional[
Union[LanguageDetectionOptions, Dict[str, Any]]
] = None,
speech_threshold: Optional[float] = None,
raw_transcription_config: Optional[RawTranscriptionConfig] = None,
speech_model: Optional[SpeechModel] = None,
Expand All @@ -1089,8 +1094,12 @@ def __init__(
temperature: Optional[float] = None,
remove_audio_tags: Optional[str] = None,
keyterms_prompt: Optional[List[str]] = None,
keyterms_prompt_options: Optional[KeytermsPromptOptions] = None,
speech_understanding: Optional[SpeechUnderstandingRequest] = None,
keyterms_prompt_options: Optional[
Union[KeytermsPromptOptions, Dict[str, Any]]
] = None,
speech_understanding: Optional[
Union[SpeechUnderstandingRequest, Dict[str, Any]]
] = None,
domain: Optional[str] = None,
) -> None:
"""
Expand Down Expand Up @@ -1191,16 +1200,16 @@ def __init__(
self.auto_highlights = auto_highlights
self.language_detection = language_detection
self.language_confidence_threshold = language_confidence_threshold
self.language_detection_options = language_detection_options
self.language_detection_options = language_detection_options # type: ignore[assignment]
self.speech_threshold = speech_threshold
self.speech_model = speech_model
self.speech_models = speech_models
self.prompt = prompt
self.temperature = temperature
self.remove_audio_tags = remove_audio_tags
self.keyterms_prompt = keyterms_prompt
self.keyterms_prompt_options = keyterms_prompt_options
self.speech_understanding = speech_understanding
self.keyterms_prompt_options = keyterms_prompt_options # type: ignore[assignment]
self.speech_understanding = speech_understanding # type: ignore[assignment]
self.domain = domain

@property
Expand Down Expand Up @@ -1288,11 +1297,12 @@ def keyterms_prompt_options(self) -> Optional[KeytermsPromptOptions]:

@keyterms_prompt_options.setter
def keyterms_prompt_options(
self, keyterms_prompt_options: Optional[KeytermsPromptOptions]
self,
keyterms_prompt_options: Optional[Union[KeytermsPromptOptions, Dict[str, Any]]],
) -> None:
"Sets the keyterms_prompt_options to use for the transcription."

self._raw_transcription_config.keyterms_prompt_options = keyterms_prompt_options
self._raw_transcription_config.keyterms_prompt_options = keyterms_prompt_options # type: ignore[assignment]

@property
def speech_understanding(self) -> Optional[SpeechUnderstandingRequest]:
Expand All @@ -1301,10 +1311,15 @@ def speech_understanding(self) -> Optional[SpeechUnderstandingRequest]:

@speech_understanding.setter
def speech_understanding(
self, speech_understanding: Optional[SpeechUnderstandingRequest]
self,
speech_understanding: Optional[
Union[SpeechUnderstandingRequest, Dict[str, Any]]
],
) -> None:
"Sets the speech understanding configuration for LLM Gateway features."
self._raw_transcription_config.speech_understanding = speech_understanding
# `RawTranscriptionConfig`'s `validate_assignment` coerces a dict to `SpeechUnderstandingRequest`
# at runtime; mypy doesn't model that, so the narrower assignment is type: ignore'd here.
self._raw_transcription_config.speech_understanding = speech_understanding # type: ignore[assignment]

@property
def domain(self) -> Optional[str]:
Expand Down Expand Up @@ -1679,11 +1694,11 @@ def language_detection_options(self) -> Optional[LanguageDetectionOptions]:

@language_detection_options.setter
def language_detection_options(
self, options: Optional[LanguageDetectionOptions]
self, options: Optional[Union[LanguageDetectionOptions, Dict[str, Any]]]
) -> None:
"Set the options for controlling the behavior or Automatic Language Detection."

self._raw_transcription_config.language_detection_options = options
self._raw_transcription_config.language_detection_options = options # type: ignore[assignment]

@property
def speech_threshold(self) -> Optional[float]:
Expand Down Expand Up @@ -1739,7 +1754,7 @@ def set_speaker_diarization(
self,
enable: Optional[bool] = True,
speakers_expected: Optional[int] = None,
speaker_options: Optional[SpeakerOptions] = None,
speaker_options: Optional[Union[SpeakerOptions, Dict[str, Any]]] = None,
) -> Self:
"""
Whether to enable Speaker Diarization on the transcript.
Expand All @@ -1764,7 +1779,7 @@ def set_speaker_diarization(
if speakers_expected is not None:
self._raw_transcription_config.speakers_expected = speakers_expected
if speaker_options is not None:
self._raw_transcription_config.speaker_options = speaker_options
self._raw_transcription_config.speaker_options = speaker_options # type: ignore[assignment]

return self

Expand Down Expand Up @@ -1857,7 +1872,9 @@ def set_redact_pii(
enable: Optional[bool] = True,
redact_audio: Optional[bool] = None,
redact_audio_quality: Optional[PIIRedactedAudioQuality] = None,
redact_audio_options: Optional[RedactPiiAudioOptions] = None,
redact_audio_options: Optional[
Union[RedactPiiAudioOptions, Dict[str, Any]]
] = None,
policies: Optional[List[PIIRedactionPolicy]] = None,
substitution: Optional[PIISubstitutionPolicy] = None,
return_unredacted: Optional[bool] = None,
Expand Down Expand Up @@ -1892,7 +1909,7 @@ def set_redact_pii(
self._raw_transcription_config.redact_pii = True
self._raw_transcription_config.redact_pii_audio = redact_audio
self._raw_transcription_config.redact_pii_audio_quality = redact_audio_quality
self._raw_transcription_config.redact_pii_audio_options = redact_audio_options
self._raw_transcription_config.redact_pii_audio_options = redact_audio_options # type: ignore[assignment]
self._raw_transcription_config.redact_pii_policies = policies
self._raw_transcription_config.redact_pii_sub = substitution
self._raw_transcription_config.redact_pii_return_unredacted = return_unredacted
Expand Down Expand Up @@ -1927,16 +1944,13 @@ def set_custom_spelling(
if self._raw_transcription_config.custom_spelling is None or override:
self._raw_transcription_config.custom_spelling = []

for to, from_ in replacement.items():
if isinstance(from_, str):
from_ = [from_]

self._raw_transcription_config.custom_spelling.append(
{
"from": list(from_),
"to": to,
}
)
new_entries: List[Dict[str, Union[str, List[str]]]] = [
{"from": [from_] if isinstance(from_, str) else list(from_), "to": to}
for to, from_ in replacement.items()
]
self._raw_transcription_config.custom_spelling = (
self._raw_transcription_config.custom_spelling + new_entries
)

return self

Expand Down
Loading
Loading