create_file_block() — langchain Function Reference
Architecture documentation for the create_file_block() function in content.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 856e9908_183d_38df_fdfa_7e7e4284cc0c["create_file_block()"] c7f11daf_e104_efbe_7225_f1d6da8e8630["content.py"] 856e9908_183d_38df_fdfa_7e7e4284cc0c -->|defined in| c7f11daf_e104_efbe_7225_f1d6da8e8630 style 856e9908_183d_38df_fdfa_7e7e4284cc0c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/messages/content.py lines 1189–1252
def create_file_block(
*,
url: str | None = None,
base64: str | None = None,
file_id: str | None = None,
mime_type: str | None = None,
id: str | None = None,
index: int | str | None = None,
**kwargs: Any,
) -> FileContentBlock:
"""Create a `FileContentBlock`.
Args:
url: URL of the file.
base64: Base64-encoded file data.
file_id: ID of the file from a file storage system.
mime_type: MIME type of the file.
Required for base64 data.
id: Content block identifier.
Generated automatically if not provided.
index: Index of block in aggregate response.
Used during streaming.
Returns:
A properly formatted `FileContentBlock`.
Raises:
ValueError: If no file source is provided or if `base64` is used without
`mime_type`.
!!! note
The `id` is generated automatically if not provided, using a UUID4 format
prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
"""
if not any([url, base64, file_id]):
msg = "Must provide one of: url, base64, or file_id"
raise ValueError(msg)
if base64 and not mime_type:
msg = "mime_type is required when using base64 data"
raise ValueError(msg)
block = FileContentBlock(type="file", id=ensure_id(id))
if url is not None:
block["url"] = url
if base64 is not None:
block["base64"] = base64
if file_id is not None:
block["file_id"] = file_id
if mime_type is not None:
block["mime_type"] = mime_type
if index is not None:
block["index"] = index
extras = {k: v for k, v in kwargs.items() if v is not None}
if extras:
block["extras"] = extras
return block
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does create_file_block() do?
create_file_block() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/content.py.
Where is create_file_block() defined?
create_file_block() is defined in libs/core/langchain_core/messages/content.py at line 1189.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free