mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
fix(anthropic): build document blocks directly from the data URI
This commit is contained in:
parent
35912a2fb8
commit
5f6d07ff32
1 changed files with 14 additions and 10 deletions
|
|
@ -2422,17 +2422,21 @@ def anthropic_messages_pt(
|
|||
image_url_value.get("url") if isinstance(image_url_value, dict) else image_url_value
|
||||
)
|
||||
if isinstance(url_str, str) and _is_anthropic_document_data_uri(url_str):
|
||||
synth_file_message: ChatCompletionFileObject = {
|
||||
"type": "file",
|
||||
"file": {"file_data": url_str},
|
||||
}
|
||||
_document_content_element = anthropic_process_openai_file_message(synth_file_message)
|
||||
_document_content_element = add_cache_control_to_content(
|
||||
anthropic_content_element=cast(
|
||||
AnthropicMessagesDocumentParam,
|
||||
_document_content_element,
|
||||
image_chunk: Final = convert_to_anthropic_image_obj(
|
||||
openai_image_url=url_str,
|
||||
format=None,
|
||||
)
|
||||
_document_content_element: Final = AnthropicMessagesDocumentParam(
|
||||
type="document",
|
||||
source=AnthropicContentParamSource(
|
||||
type="base64",
|
||||
media_type=image_chunk["media_type"],
|
||||
data=image_chunk["data"],
|
||||
),
|
||||
original_content_element=dict(m),
|
||||
)
|
||||
add_cache_control_to_content(
|
||||
anthropic_content_element=_document_content_element,
|
||||
original_content_element=m,
|
||||
)
|
||||
user_content.append(cast(AnthropicMessagesDocumentParam, _document_content_element))
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue