Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
baskaryan committed Jun 20, 2024
1 parent b557b7f commit 98567a2
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions libs/aws/langchain_aws/chat_models/bedrock_converse.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def _parse_stream_event(event: Dict[str, Any]) -> Optional[BaseMessageChunk]:
tool_call_chunks.append(
ToolCallChunk(
name=block.get("name"),
id=block.get("tool_use_id"),
id=block.get("id"),
args=block.get("input"),
index=event["contentBlockStart"]["contentBlockIndex"],
)
Expand All @@ -589,7 +589,7 @@ def _parse_stream_event(event: Dict[str, Any]) -> Optional[BaseMessageChunk]:
tool_call_chunks.append(
ToolCallChunk(
name=block.get("name"),
id=block.get("tool_use_id"),
id=block.get("id"),
args=block.get("input"),
index=event["contentBlockDelta"]["contentBlockIndex"],
)
Expand Down Expand Up @@ -844,21 +844,15 @@ def _upsert_tool_calls_to_bedrock_content(
def _format_openai_image_url(image_url: str) -> Dict:
"""
Formats an image of format data:image/jpeg;base64,{b64_string}
to a dict for anthropic api
to a dict for bedrock api.
{
"type": "base64",
"media_type": "image/jpeg",
"data": "/9j/4AAQSkZJRg...",
}
And throws an error if it's not a b64 image
And throws an error if url is not a b64 image.
"""
regex = r"^data:image/(?P<media_type>.+);base64,(?P<data>.+)$"
match = re.match(regex, image_url)
if match is None:
raise ValueError(
"Bedrock does not currently support OpenAI-format image urls, only "
"Bedrock does not currently support OpenAI-format image URLs, only "
"base64-encoded images. Example: data:image/png;base64,'/9j/4AAQSk'..."
)
return {
Expand Down

0 comments on commit 98567a2

Please sign in to comment.