Skip to content

Commit c7c4107

Browse files
committed
add AmazonAnthropicClaudeStreamDecoder
1 parent ce4987d commit c7c4107

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

litellm/llms/bedrock/chat/invoke_transformations/anthropic_claude3_transformation.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
import httpx
44

55
import litellm
6+
from litellm.llms.anthropic.chat.handler import (
7+
ModelResponseIterator as AnthropicModelResponseIterator,
8+
)
69
from litellm.llms.anthropic.chat.transformation import AnthropicConfig
10+
from litellm.llms.bedrock.chat.invoke_handler import AWSEventStreamDecoder
711
from litellm.llms.bedrock.chat.invoke_transformations.base_invoke_transformation import (
812
AmazonInvokeConfig,
913
)
1014
from litellm.types.llms.openai import AllMessageValues
15+
from litellm.types.utils import GenericStreamingChunk as GChunk
1116
from litellm.types.utils import ModelResponse
1217

1318
if TYPE_CHECKING:
@@ -78,3 +83,19 @@ def transform_response(
7883
api_key=api_key,
7984
json_mode=json_mode,
8085
)
86+
87+
88+
class AmazonAnthropicClaudeStreamDecoder(AWSEventStreamDecoder):
89+
def __init__(
90+
self,
91+
model: str,
92+
sync_stream: bool,
93+
) -> None:
94+
super().__init__(model=model)
95+
self.anthropic_model_response_iterator = AnthropicModelResponseIterator(
96+
streaming_response=None,
97+
sync_stream=sync_stream,
98+
)
99+
100+
def _chunk_parser(self, chunk_data: dict) -> GChunk:
101+
return self.anthropic_model_response_iterator.chunk_parser(chunk=chunk_data)

0 commit comments

Comments
 (0)