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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
assume index is not always in stream chunk
Ishaan Jaffb93152e97876
diff --git a/litellm/llms/sagemaker.py b/litellm/llms/sagemaker.pyindex 14097bb22cc..a839c03b79f 100644--- a/litellm/llms/sagemaker.py+++ b/litellm/llms/sagemaker.py@@ -808,16 +808,21 @@ class AWSEventStreamDecoder:self.model = modelself.parser = EventStreamJSONParser()self.content_blocks: List = []+ self.index = 0def _chunk_parser(self, chunk_data: dict) -> GChunk:verbose_logger.debug("in sagemaker chunk parser, chunk_data %s", chunk_data)- _token = chunk_data["token"]- _index = chunk_data["index"]+ _token = chunk_data.get("token", {}) or {}+ _index = chunk_data.get("index", None)+ if _index is None:+ _index = self.index+ self.index += 1is_finished = Falsefinish_reason = ""- if _token["text"] == "<|endoftext|>":+ _text = _token.get("text", "")+ if _text == "<|endoftext|>":return GChunk(text="",index=_index,@@ -826,7 +831,7 @@ class AWSEventStreamDecoder:)return GChunk(- text=_token["text"],+ text=_text,index=_index,is_finished=is_finished,finish_reason=finish_reason,