Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ if result.llm_error:
print("LLM pass failed:", result.llm_error)
```

The instruction is capped at 2048 characters.
The instruction has no length cap of its own; the service limits only the size of the whole config, and a config it rejects raises `DictationError`.

`rewrite_mode` picks the model tier that runs the rewrite. `fast` is the default; `smart` follows detailed formatting instructions more reliably, at higher latency:

Expand Down
2 changes: 1 addition & 1 deletion assemblyai/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.10.12"
__version__ = "1.10.16"
9 changes: 4 additions & 5 deletions assemblyai/dictation/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def __init__(

_DICTATION_MAX_KEYTERMS_PROMPT_LEN = 8000
_DICTATION_MAX_KEYTERMS_COUNT = 100
_DICTATION_MAX_LLM_INSTRUCTION_LEN = 2048
_DICTATION_MAX_STT_PROMPT_LEN = 6000


Expand Down Expand Up @@ -117,12 +116,12 @@ class DictationConfig(BaseModel):
keyterms_prompt: Optional[List[str]] = None
"Keyterms biasing the decoder. Whitespace is stripped and empty terms dropped. Max 100 terms / 8000 characters total."

llm_instruction: Optional[str] = Field(
default=None, max_length=_DICTATION_MAX_LLM_INSTRUCTION_LEN
)
llm_instruction: Optional[str] = None
"""Instruction for a follow-up LLM pass over the transcript, e.g.
"Format this as a SOAP note." The rewritten text comes back as
`llm_response`; the raw transcript stays in `text`. Max 2048 characters."""
`llm_response`; the raw transcript stays in `text`. No client-side length
limit: the service limits only the size of the whole config, and rejects a
larger one with a 400, raised as DictationError."""

rewrite_mode: Optional[DictationRewriteMode] = None
"""Model tier that runs the rewrite: `fast` or `smart`. `smart` follows
Expand Down
44 changes: 40 additions & 4 deletions tests/unit/test_dictation.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,46 @@ def test_keyterms_prompt_at_the_count_cap_accepted():
assert len(config.keyterms_prompt) == _DICTATION_MAX_KEYTERMS_COUNT


def test_llm_instruction_too_long_raises():
# Given an llm_instruction exceeding the 2048-char cap
with pytest.raises(ValueError):
aai.DictationConfig(llm_instruction="x" * 3000)
def test_llm_instruction_longer_than_the_old_cap_accepted():
# Given an instruction far past the old 2048-char client cap, which the
# service accepts (it limits only the whole config part)
config = aai.DictationConfig(llm_instruction="x" * 49152)

# Then the config keeps it whole
assert len(config.llm_instruction) == 49152


def test_transcribe_live_sends_a_long_llm_instruction_whole(httpx_mock: HTTPXMock):
# Given a 10,000-char instruction
_mock_ok(httpx_mock)
instruction = "x" * 10000
config = aai.DictationConfig(llm_instruction=instruction)

# When streaming
aai.DictationTranscriber().transcribe_live(_chunks(b"RIFF"), config=config)

# Then the config part carries all of it, untruncated
body = httpx_mock.get_requests()[0].read()
assert f'"llm_instruction": "{instruction}"'.encode() in body


def test_oversized_config_rejection_maps_to_dictation_error(httpx_mock: HTTPXMock):
# Given a server rejecting a config part that is too large
httpx_mock.add_response(
url=LIVE_URL,
method="POST",
status_code=400,
json={"error": "config part too large"},
)

# When streaming, then the rejection surfaces as a DictationError
with pytest.raises(aai.DictationError, match="config part too large") as exc_info:
aai.DictationTranscriber().transcribe_live(
_chunks(b"RIFF"),
config=aai.DictationConfig(llm_instruction="x" * 100000),
)

assert exc_info.value.status_code == 400


def test_transcribe_live_sends_rewrite_mode(httpx_mock: HTTPXMock):
Expand Down
Loading