rg.markdown
¶
To support the usage of Markdown within Argilla, we've created some helper functions to easy the usage of DataURL conversions and chat message visualizations.
media
¶
video_to_html(file_source, file_type=None, width=None, height=None, autoplay=False, loop=False)
¶
Convert a video file to an HTML tag with embedded base64 data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_source |
Union[str, bytes]
|
The path to the media file or a non-b64 encoded byte string. |
required |
file_type |
Optional[str]
|
The type of the video file. If not provided, it will be inferred from the file extension. |
None
|
width |
Optional[str]
|
Display width in HTML. Defaults to None. |
None
|
height |
Optional[str]
|
Display height in HTML. Defaults to None. |
None
|
autoplay |
bool
|
True to autoplay media. Defaults to False. |
False
|
loop |
bool
|
True to loop media. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
str
|
The HTML tag with embedded base64 data. |
Examples:
from argilla.markdown import video_to_html
html = video_to_html("my_video.mp4", width="300px", height="300px", autoplay=True, loop=True)
Source code in src/argilla/markdown/media.py
audio_to_html(file_source, file_type=None, width=None, height=None, autoplay=False, loop=False)
¶
Convert an audio file to an HTML tag with embedded base64 data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_source |
Union[str, bytes]
|
The path to the media file or a non-b64 encoded byte string. |
required |
file_type |
Optional[str]
|
The type of the audio file. If not provided, it will be inferred from the file extension. |
None
|
width |
Optional[str]
|
Display width in HTML. Defaults to None. |
None
|
height |
Optional[str]
|
Display height in HTML. Defaults to None. |
None
|
autoplay |
bool
|
True to autoplay media. Defaults to False. |
False
|
loop |
bool
|
True to loop media. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
str
|
The HTML tag with embedded base64 data. |
Examples:
from argilla.markdown import audio_to_html
html = audio_to_html("my_audio.mp3", width="300px", height="300px", autoplay=True, loop=True)
Source code in src/argilla/markdown/media.py
image_to_html(file_source, file_type=None, width=None, height=None)
¶
Convert an image file to an HTML tag with embedded base64 data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_source |
Union[str, bytes]
|
The path to the media file or a non-b64 encoded byte string. |
required |
file_type |
Optional[str]
|
The type of the image file. If not provided, it will be inferred from the file extension. |
None
|
width |
Optional[str]
|
Display width in HTML. Defaults to None. |
None
|
height |
Optional[str]
|
Display height in HTML. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
str
|
The HTML tag with embedded base64 data. |
Examples:
from argilla.markdown import image_to_html
html = image_to_html("my_image.png", width="300px", height="300px")
Source code in src/argilla/markdown/media.py
pdf_to_html(file_source, width='1000px', height='1000px')
¶
Convert a pdf file to an HTML tag with embedded data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_source |
Union[str, bytes]
|
The path to the PDF file, a bytes object with PDF data, or a URL. |
required |
width |
Optional[str]
|
Display width in HTML. Defaults to "1000px". |
'1000px'
|
height |
Optional[str]
|
Display height in HTML. Defaults to "1000px". |
'1000px'
|
Returns:
Type | Description |
---|---|
str
|
HTML string embedding the PDF. |
Raises:
Type | Description |
---|---|
ValueError
|
If the width and height are not pixel or percentage. |
Examples:
from argilla.markdown import pdf_to_html
html = pdf_to_html("my_pdf.pdf", width="300px", height="300px")
Source code in src/argilla/markdown/media.py
chat
¶
chat_to_html(messages)
¶
Converts a list of chat messages in the OpenAI format to HTML.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages |
List[Dict[str, str]]
|
A list of dictionaries where each dictionary represents a chat message. Each dictionary should have the keys: - "role": A string indicating the role of the sender (e.g., "user", "model", "assistant", "system"). - "content": The content of the message. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
An HTML string that represents the chat conversation. |
Raises:
Type | Description |
---|---|
ValueError
|
If the an invalid role is passed. |
Examples:
from argilla.markdown import chat_to_html
html = chat_to_html([
{"role": "user", "content": "hello"},
{"role": "assistant", "content": "goodbye"}
])