Skip to content

Commit

Permalink
Bedrock document processing fixes (#8005)
Browse files Browse the repository at this point in the history
* refactor(factory.py): refactor async bedrock message transformation to use async get request for image url conversion

improve latency of bedrock call

* test(test_bedrock_completion.py): add unit testing to ensure async image url get called for async bedrock call

* refactor(factory.py): refactor bedrock translation to use BedrockImageProcessor

reduces duplicate code

* fix(factory.py): fix bug not allowing pdf's to be processed

* fix(factory.py): fix bedrock converse document understanding with image url

* docs(bedrock.md): clarify all bedrock document types are supported

* refactor: cleanup redundant test + unused imports

* perf: improve perf with reusable clients

* test: fix test
  • Loading branch information
krrishdholakia authored Jan 29, 2025
1 parent c2e3986 commit 8eaa5dc
Show file tree
Hide file tree
Showing 13 changed files with 577 additions and 85 deletions.
10 changes: 10 additions & 0 deletions docs/my-website/docs/providers/bedrock.md
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,16 @@ curl -X POST 'http://0.0.0.0:4000/chat/completions' \

LiteLLM supports Document Understanding for Bedrock models - [AWS Bedrock Docs](https://docs.aws.amazon.com/nova/latest/userguide/modalities-document.html).

:::info

LiteLLM supports ALL Bedrock document types -

E.g.: "pdf", "csv", "doc", "docx", "xls", "xlsx", "html", "txt", "md"

You can also pass these as either `image_url` or `base64`

:::

### url

<Tabs>
Expand Down
2 changes: 1 addition & 1 deletion litellm/litellm_core_utils/exception_mapping_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def exception_type( # type: ignore # noqa: PLR0915
"\033[1;31mGive Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new\033[0m" # noqa
) # noqa
print( # noqa
"LiteLLM.Info: If you need to debug this error, use `litellm.set_verbose=True'." # noqa
"LiteLLM.Info: If you need to debug this error, use `litellm._turn_on_debug()'." # noqa
) # noqa
print() # noqa

Expand Down
4 changes: 0 additions & 4 deletions litellm/litellm_core_utils/litellm_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,6 @@ def _print_llm_call_debugging_log(
masked_api_base = api_base
self.model_call_details["litellm_params"]["api_base"] = masked_api_base

verbose_logger.debug(
"PRE-API-CALL ADDITIONAL ARGS: %s", additional_args
)

curl_command = self._get_request_curl_command(
api_base=api_base,
headers=headers,
Expand Down
401 changes: 354 additions & 47 deletions litellm/litellm_core_utils/prompt_templates/factory.py

Large diffs are not rendered by default.

28 changes: 20 additions & 8 deletions litellm/llms/bedrock/chat/converse_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import httpx

import litellm
from litellm.litellm_core_utils.asyncify import asyncify
from litellm.litellm_core_utils.core_helpers import map_finish_reason
from litellm.litellm_core_utils.litellm_logging import Logging
from litellm.litellm_core_utils.prompt_templates.factory import (
BedrockConverseMessagesProcessor,
_bedrock_converse_messages_pt,
_bedrock_tools_pt,
)
Expand Down Expand Up @@ -154,6 +154,9 @@ def get_supported_image_types(self) -> List[str]:
def get_supported_document_types(self) -> List[str]:
return ["pdf", "csv", "doc", "docx", "xls", "xlsx", "html", "txt", "md"]

def get_all_supported_content_types(self) -> List[str]:
return self.get_supported_image_types() + self.get_supported_document_types()

def _create_json_tool_call_for_response_format(
self,
json_schema: Optional[dict] = None,
Expand Down Expand Up @@ -426,13 +429,22 @@ async def _async_transform_request(
) -> RequestObject:
messages, system_content_blocks = self._transform_system_message(messages)
## TRANSFORMATION ##
bedrock_messages: List[MessageBlock] = await asyncify(
_bedrock_converse_messages_pt
)(
messages=messages,
model=model,
llm_provider="bedrock_converse",
user_continue_message=litellm_params.pop("user_continue_message", None),
# bedrock_messages: List[MessageBlock] = await asyncify(
# _bedrock_converse_messages_pt
# )(
# messages=messages,
# model=model,
# llm_provider="bedrock_converse",
# user_continue_message=litellm_params.pop("user_continue_message", None),
# )

bedrock_messages = (
await BedrockConverseMessagesProcessor._bedrock_converse_messages_pt_async(
messages=messages,
model=model,
llm_provider="bedrock_converse",
user_continue_message=litellm_params.pop("user_continue_message", None),
)
)

_data: CommonRequestObject = self._transform_request_helper(
Expand Down
1 change: 0 additions & 1 deletion litellm/proxy/_experimental/out/404.html

This file was deleted.

1 change: 0 additions & 1 deletion litellm/proxy/_experimental/out/model_hub.html

This file was deleted.

Loading

0 comments on commit 8eaa5dc

Please sign in to comment.