mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-17 15:35:14 +00:00
Merge branch 'wip-v1.0' into mdrxy/genai
This commit is contained in:
@@ -67,7 +67,7 @@ def convert_to_openai_data_block(
|
||||
elif block["type"] == "file":
|
||||
if block.get("source_type") == "base64" or "base64" in block:
|
||||
# Handle v0 format (Base64CB): {"source_type": "base64", "data": "...", ...}
|
||||
# Handle v1 format (FileCB): {"base64": "...", ...}
|
||||
# Handle v1 format (IDCB): {"base64": "...", ...}
|
||||
base64_data = block["data"] if "source_type" in block else block["base64"]
|
||||
file = {"file_data": f"data:{block['mime_type']};base64,{base64_data}"}
|
||||
if filename := block.get("filename"):
|
||||
@@ -90,7 +90,7 @@ def convert_to_openai_data_block(
|
||||
formatted_block = {"type": "input_file", **formatted_block["file"]}
|
||||
elif block.get("source_type") == "id" or "file_id" in block:
|
||||
# Handle v0 format (IDContentBlock): {"source_type": "id", "id": "...", ...}
|
||||
# Handle v1 format (FileCB): {"file_id": "...", ...}
|
||||
# Handle v1 format (IDCB): {"file_id": "...", ...}
|
||||
file_id = block["id"] if "source_type" in block else block["file_id"]
|
||||
formatted_block = {"type": "file", "file": {"file_id": file_id}}
|
||||
if api == "responses":
|
||||
|
@@ -939,7 +939,9 @@ def _get_data_content_block_types() -> tuple[str, ...]:
|
||||
|
||||
|
||||
def is_data_content_block(block: dict) -> bool:
|
||||
"""Check if the provided content block is a standard v1 data content block.
|
||||
"""Check if the provided content block is a data content block.
|
||||
|
||||
Returns for both v0 (old-style) and v1 (new-style) multimodal data blocks.
|
||||
|
||||
Args:
|
||||
block: The content block to check.
|
||||
@@ -951,7 +953,9 @@ def is_data_content_block(block: dict) -> bool:
|
||||
if block.get("type") not in _get_data_content_block_types():
|
||||
return False
|
||||
|
||||
if any(key in block for key in ("url", "base64", "file_id", "text")):
|
||||
if any(key in block for key in ("url", "base64", "file_id")):
|
||||
# Type is valid and at least one data field is present
|
||||
# (Accepts old-style image and audio URLContentBlock)
|
||||
return True
|
||||
|
||||
# Verify data presence based on source type
|
||||
@@ -966,6 +970,8 @@ def is_data_content_block(block: dict) -> bool:
|
||||
):
|
||||
return True
|
||||
|
||||
# Type may be valid, but no data fields are present
|
||||
# (required case since each is optional and we have no validation)
|
||||
return False
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user