file_attachment
langroid/parsing/file_attachment.py
FileAttachment(**data)
¶
Bases: BaseModel
Represents a file attachment to be sent to an LLM API.
Source code in langroid/parsing/file_attachment.py
from_path(path, detail=None)
classmethod
¶
Create a FileAttachment from either a local file path or a URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_or_url
|
Path to the file or URL to fetch |
required |
Returns:
Type | Description |
---|---|
FileAttachment
|
FileAttachment instance |
Source code in langroid/parsing/file_attachment.py
from_bytes(content, filename=None, mime_type=None)
classmethod
¶
Create a FileAttachment from bytes content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
bytes
|
Raw bytes content |
required |
filename
|
Optional[str]
|
Optional name to use for the file |
None
|
mime_type
|
Optional[str]
|
MIME type of the content, guessed from filename if provided |
None
|
Returns:
Type | Description |
---|---|
FileAttachment
|
FileAttachment instance |
Source code in langroid/parsing/file_attachment.py
from_io(file_obj, filename=None, mime_type=None)
classmethod
¶
Create a FileAttachment from a file-like object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_obj
|
BinaryIO
|
File-like object with binary content |
required |
filename
|
Optional[str]
|
Optional name to use for the file |
None
|
mime_type
|
Optional[str]
|
MIME type of the content, guessed from filename if provided |
None
|
Returns:
Type | Description |
---|---|
FileAttachment
|
FileAttachment instance |
Source code in langroid/parsing/file_attachment.py
from_text(text, filename=None, mime_type='text/plain', encoding='utf-8')
classmethod
¶
Create a FileAttachment from text content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
Text content to include |
required |
filename
|
Optional[str]
|
Optional name to use for the file |
None
|
mime_type
|
str
|
MIME type of the content |
'text/plain'
|
encoding
|
str
|
Text encoding to use |
'utf-8'
|
Returns:
Type | Description |
---|---|
FileAttachment
|
FileAttachment instance |
Source code in langroid/parsing/file_attachment.py
to_base64()
¶
Convert content to base64 encoding.
Returns:
Type | Description |
---|---|
str
|
Base64 encoded string |
to_data_uri()
¶
Convert content to a data URI.
Returns:
Type | Description |
---|---|
str
|
A data URI string containing the base64-encoded content with MIME type |
Source code in langroid/parsing/file_attachment.py
to_dict(model)
¶
Convert to a dictionary suitable for API requests. Tested only for PDF files.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dictionary with file data |