Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(soniox): accumulate cue start indices in linear time

Dan Lemon0a582975de53
diff --git a/litellm/llms/soniox/common_utils.py b/litellm/llms/soniox/common_utils.py
index fc85e2b719c..b4597ef2a50 100644
--- a/litellm/llms/soniox/common_utils.py
+++ b/litellm/llms/soniox/common_utils.py
@@ -5,7 +5,7 @@ Shared utilities for the Soniox provider (https://soniox.com).
import unicodedata
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
-from functools import reduce
+from itertools import accumulate, groupby
from typing import Any, Final
from litellm.llms.base_llm.chat.transformation import BaseLLMException
@@ -266,14 +266,16 @@ def _should_break(cue: Sequence[_Word], word: _Word) -> bool:
def _cue_start_indices(words: Sequence[_Word]) -> tuple[int, ...]:
- def step(starts: tuple[int, ...], index: int) -> tuple[int, ...]:
+ def next_start(start: int, index: int) -> int:
if words[index - 1].text.rstrip().endswith(_SENTENCE_END_CHARS):
- return (*starts, index)
- if _should_break(words[starts[-1] : index], words[index]):
- return (*starts, index)
- return starts
-
- return reduce(step, range(1, len(words)), (0,)) if words else ()
+ return index
+ if _should_break(words[start:index], words[index]):
+ return index
+ return start
+
+ if not words:
+ return ()
+ return tuple(start for start, _ in groupby(accumulate(range(1, len(words)), next_start, initial=0)))
def _build_cue(ws: Sequence[_Word]) -> _Cue | None: