diff --git a/README.md b/README.md index 105d5c5..6f57159 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/assemblyai/__version__.py b/assemblyai/__version__.py index d6a282f..bde9546 100644 --- a/assemblyai/__version__.py +++ b/assemblyai/__version__.py @@ -1 +1 @@ -__version__ = "1.10.12" +__version__ = "1.10.16" diff --git a/assemblyai/dictation/v1/models.py b/assemblyai/dictation/v1/models.py index 273f4bd..fcfa38d 100644 --- a/assemblyai/dictation/v1/models.py +++ b/assemblyai/dictation/v1/models.py @@ -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 @@ -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 diff --git a/tests/unit/test_dictation.py b/tests/unit/test_dictation.py index f873fdf..90beade 100644 --- a/tests/unit/test_dictation.py +++ b/tests/unit/test_dictation.py @@ -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):