Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions docs/sdk/data_types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,34 @@ def to_serializable(self) -> tuple[t.Any, dict[str, t.Any]]:
```


</Accordion>

Code
----

```python
Code(text: str, language: str = '')
```

Hint type for code-formatted text.

This is a subclass of Text with format set to "code".

Example

```python
log_output("code_snippet", Code("print('Hello, World!')", language="python"))
```


<Accordion title="Source code in dreadnode/data_types/text.py" icon="code">
```python
def __init__(self, text: str, language: str = ""):
super().__init__(text, format="code")
self._language = language
```


</Accordion>

Image
Expand Down Expand Up @@ -220,6 +248,33 @@ def to_serializable(self) -> tuple[t.Any, dict[str, t.Any]]:
```


</Accordion>

Markdown
--------

```python
Markdown(text: str)
```

Hint type for markdown-formatted text.

This is a subclass of Text with format set to "markdown".

Example

```python
log_output("report", Markdown("..."))
```


<Accordion title="Source code in dreadnode/data_types/text.py" icon="code">
```python
def __init__(self, text: str):
super().__init__(text, format="markdown")
```


</Accordion>

Object3D
Expand Down Expand Up @@ -434,6 +489,43 @@ def to_serializable(self) -> tuple[bytes, dict[str, t.Any]]:
```


</Accordion>

Text
----

```python
Text(text: str, format: str)
```

Text data type for Dreadnode logging.

Initialize a Text object.

**Parameters:**

* **`text`**
(`str`)
–The text content to log
* **`format`**
(`str`)
–The format hint of the text

<Accordion title="Source code in dreadnode/data_types/text.py" icon="code">
```python
def __init__(self, text: str, format: str):
"""
Initialize a Text object.

Args:
text: The text content to log
format: The format hint of the text
"""
self._text = text
self._format = format
```


</Accordion>

Video
Expand Down Expand Up @@ -575,4 +667,75 @@ def to_serializable(self) -> tuple[bytes, dict[str, t.Any]]:
```


</Accordion>

WithMeta
--------

```python
WithMeta(obj: Any, metadata: dict[str, Any])
```

Helper data type to add additional metadata to the schema for logged data.

Example

```python
log_output("my_data", WithMeta(data, {"format": "custom-data"}))
```

Initialize a data type with associated metadata.

**Parameters:**

* **`metadata`**
(`dict[str, Any]`)
–The metadata for this data type

<Accordion title="Source code in dreadnode/data_types/base.py" icon="code">
```python
def __init__(self, obj: t.Any, metadata: dict[str, t.Any]):
"""
Initialize a data type with associated metadata.

Args:
metadata: The metadata for this data type
"""
self._obj = obj
self._metadata = metadata
```


</Accordion>

### to\_serializable

```python
to_serializable() -> tuple[t.Any, dict[str, t.Any]]
```

Convert the media type to a serializable format.

**Returns:**

* `tuple[Any, dict[str, Any]]`
–Tuple of (data, metadata) where:
- data: The serialized data
- metadata: Additional metadata for this data type

<Accordion title="Source code in dreadnode/data_types/base.py" icon="code">
```python
def to_serializable(self) -> tuple[t.Any, dict[str, t.Any]]:
"""
Convert the media type to a serializable format.

Returns:
Tuple of (data, metadata) where:
- data: The serialized data
- metadata: Additional metadata for this data type
"""
return self._obj, self._metadata
```


</Accordion>
15 changes: 13 additions & 2 deletions docs/sdk/serialization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ serialize
---------

```python
serialize(obj: Any) -> Serialized
serialize(
obj: Any, *, schema_extras: JsonDict | None = None
) -> Serialized
```

Serializes a Python object into a JSON-compatible structure and
Expand All @@ -69,6 +71,11 @@ the serialization format and the schema.
* **`obj`**
(`Any`)
–The Python object to process.
* **`schema_extras`**
(`JsonDict | None`, default:
`None`
)
–Additional JSON Schema properties to include.

**Returns:**

Expand All @@ -77,14 +84,15 @@ the serialization format and the schema.

<Accordion title="Source code in dreadnode/serialization.py" icon="code">
```python
def serialize(obj: t.Any) -> Serialized:
def serialize(obj: t.Any, *, schema_extras: JsonDict | None = None) -> Serialized:
"""
Serializes a Python object into a JSON-compatible structure and
generates a corresponding JSON Schema, ensuring consistency between
the serialization format and the schema.

Args:
obj: The Python object to process.
schema_extras: Additional JSON Schema properties to include.

Returns:
An object containing the serialized data, schema, and their hashes.
Expand All @@ -96,6 +104,9 @@ def serialize(obj: t.Any) -> Serialized:
else:
serialized_bytes = json.dumps(serialized, separators=(",", ":")).encode()

if schema_extras:
schema = {**schema, **schema_extras}

schema_str = json.dumps(schema, separators=(",", ":"))

data_hash = EMPTY_HASH
Expand Down
2 changes: 2 additions & 0 deletions docs/usage/data-tracking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ with dn.run("text-generation"):
Strikes maintains a rich serialization layer to support many different kinds of Python objects:
- Dictionaries, lists, and other JSON-serializable objects
- NumPy arrays and Pandas DataFrames
- Rich media types (images, audio, video, 3D objects, tables)
- Formatted text (markdown, code with syntax highlighting)
- Custom objects (serialized with pickle)
- Large datasets (automatically stored efficiently)

Expand Down
55 changes: 53 additions & 2 deletions docs/usage/rich-objects.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: 'Rich Objects'
description: 'Store data types like images, audio, video, and 3D objects in your runs.'
description: 'Store data types like images, audio, video, text with formatting, and 3D objects in your runs.'
public: true
---

Strikes extends its data tracking capabilities to handle complex, non-JSON serializable data types. This allows you to store rich media and other complex objects directly within your runs, making it easy to track and analyze all aspects of your data-driven workflows.
Strikes extends its data tracking capabilities to handle complex, non-JSON serializable data types. This allows you to store rich media, formatted text, and other complex objects directly within your runs, making it easy to track and analyze all aspects of your data-driven workflows.

## Images

Expand Down Expand Up @@ -173,6 +173,57 @@ with dn.run("3d-formats-example"):
```
</CodeGroup>

## Text with Formatting Hints

For text data that needs special rendering in the UI, you can use text hint types. These provide better visualization and formatting for different types of text content.

<CodeGroup>
```python Markdown Text
import dreadnode as dn

markdown_content = """
# Results Summary

## Model Performance
- **Accuracy**: 94.2%
- **Loss**: 0.156

### Key Findings
The model shows excellent performance on validation data.
"""

with dn.run("markdown-example"):
dn.log_output("report", dn.Markdown(markdown_content))
```

```python Code Snippets
import dreadnode as dn

python_code = """
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)

result = fibonacci(10)
print(f"Fibonacci(10) = {result}")
"""

with dn.run("code-example"):
dn.log_output("generated_code", dn.Code(python_code, language="python"))
```

```python Generic Text with Format
import dreadnode as dn

# For custom text formatting
formatted_text = "This is custom formatted text"

with dn.run("text-example"):
dn.log_output("custom", dn.Text(formatted_text, format="custom"))
```
</CodeGroup>

## Tables

For structured data, you can use the `dn.Table` data type. It can be created from various data formats and provides flexible data organization.
Expand Down
4 changes: 3 additions & 1 deletion dreadnode/data_types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .audio import Audio
from .base import WithMeta
from .image import Image
from .object_3d import Object3D
from .table import Table
from .text import Code, Markdown, Text
from .video import Video

__all__ = ["Audio", "Image", "Object3D", "Table", "Video"]
__all__ = ["Audio", "Code", "Image", "Markdown", "Object3D", "Table", "Text", "Video", "WithMeta"]
4 changes: 2 additions & 2 deletions dreadnode/data_types/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
except ImportError:
sf = None

from dreadnode.data_types.base_data_type import BaseDataType
from dreadnode.data_types.base import DataType

AudioDataType: t.TypeAlias = str | Path | np.ndarray[t.Any, t.Any] | bytes


class Audio(BaseDataType):
class Audio(DataType):
"""
Audio media type for Dreadnode logging.

Expand Down
49 changes: 49 additions & 0 deletions dreadnode/data_types/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import typing as t
from abc import ABC, abstractmethod


class DataType(ABC):
"""Base class for dedicated data types that can be logged with Dreadnode."""

@abstractmethod
def to_serializable(self) -> tuple[t.Any, dict[str, t.Any]]:
"""
Convert the media type to a serializable format.

Returns:
Tuple of (data, metadata) where:
- data: The serialized data
- metadata: Additional metadata for this data type
"""


class WithMeta(DataType):
"""
Helper data type to add additional metadata to the schema for logged data.

Example:
```
log_output("my_data", WithMeta(data, {"format": "custom-data"}))
```
"""

def __init__(self, obj: t.Any, metadata: dict[str, t.Any]):
"""
Initialize a data type with associated metadata.

Args:
metadata: The metadata for this data type
"""
self._obj = obj
self._metadata = metadata

def to_serializable(self) -> tuple[t.Any, dict[str, t.Any]]:
"""
Convert the media type to a serializable format.

Returns:
Tuple of (data, metadata) where:
- data: The serialized data
- metadata: Additional metadata for this data type
"""
return self._obj, self._metadata
Loading
Loading