|
43 | 43 | _DEFAULT_BEDROCK_MODEL_ID = "{}.anthropic.claude-sonnet-4-6" |
44 | 44 | DEFAULT_BEDROCK_REGION = "us-west-2" |
45 | 45 |
|
| 46 | +_BEDROCK_VIDEO_FORMAT_ALIASES = { |
| 47 | + "3gp": "three_gp", |
| 48 | + "3g2": "three_gp", |
| 49 | + "3gpp": "three_gp", |
| 50 | +} |
| 51 | + |
46 | 52 | BEDROCK_CONTEXT_WINDOW_OVERFLOW_MESSAGES = [ |
47 | 53 | "Input is too long for requested model", |
48 | 54 | "input length and `max_tokens` exceed context limit", |
@@ -702,7 +708,8 @@ def _format_request_message_content(self, content: ContentBlock) -> dict[str, An |
702 | 708 | return None |
703 | 709 | elif "bytes" in source: |
704 | 710 | formatted_video_source = {"bytes": source["bytes"]} |
705 | | - result = {"format": video["format"], "source": formatted_video_source} |
| 711 | + video_format = _BEDROCK_VIDEO_FORMAT_ALIASES.get(video["format"], video["format"]) |
| 712 | + result = {"format": video_format, "source": formatted_video_source} |
706 | 713 | return {"video": result} |
707 | 714 |
|
708 | 715 | # https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_CitationsContentBlock.html |
@@ -852,13 +859,9 @@ async def count_tokens( |
852 | 859 | logger.debug("model_id=<%s>, total_tokens=<%d> | native token count", self.config["model_id"], total_tokens) |
853 | 860 | return total_tokens |
854 | 861 | except Exception as e: |
855 | | - if ( |
856 | | - isinstance(e, ClientError) |
857 | | - and e.response.get("Error", {}).get("Code") == "AccessDeniedException" |
858 | | - ): |
| 862 | + if isinstance(e, ClientError) and e.response.get("Error", {}).get("Code") == "AccessDeniedException": |
859 | 863 | logger.warning( |
860 | | - "model_id=<%s> | bedrock:CountTokens permission denied," |
861 | | - " falling back to heuristic estimation: %s", |
| 864 | + "model_id=<%s> | bedrock:CountTokens permission denied, falling back to heuristic estimation: %s", |
862 | 865 | model_id, |
863 | 866 | e, |
864 | 867 | ) |
|
0 commit comments