Anvil.ForgeBridge.SampleDTO (Anvil v0.1.1)

View Source

Data Transfer Object for samples fetched from Forge.

Isolates Anvil from Forge's internal schema details, allowing independent evolution of both systems.

Fields

  • id - Sample UUID
  • content - Primary sample content (text, JSON, etc.)
  • version - Version tag from Forge (e.g., "v2024-12-01" or content hash)
  • metadata - Optional metadata map
  • asset_urls - Pre-signed URLs for media assets
  • source - Source system identifier (e.g., "gsm8k", "human_eval")
  • created_at - Sample creation timestamp

Example

%SampleDTO{
  id: "550e8400-e29b-41d4-a716-446655440000",
  content: %{"text" => "What is 2+2?", "answer" => "4"},
  version: "v2024-12-01-abc123",
  metadata: %{"difficulty" => "easy"},
  asset_urls: [],
  source: "gsm8k",
  created_at: ~U[2024-12-01 10:00:00Z]
}

Summary

Functions

Creates a SampleDTO from a map with atom or string keys.

Validates a SampleDTO struct.

Types

t()

@type t() :: %Anvil.ForgeBridge.SampleDTO{
  asset_urls: [String.t()] | nil,
  content: map() | String.t(),
  created_at: DateTime.t() | nil,
  id: binary(),
  metadata: map() | nil,
  source: String.t() | nil,
  version: String.t()
}

Functions

from_map(map)

@spec from_map(map()) :: {:ok, t()} | {:error, atom()}

Creates a SampleDTO from a map with atom or string keys.

Examples

iex> SampleDTO.from_map(%{
...>   "id" => "abc",
...>   "content" => "test",
...>   "version" => "v1"
...> })
{:ok, %SampleDTO{id: "abc", content: "test", version: "v1"}}

iex> SampleDTO.from_map(%{id: "missing content"})
{:error, :invalid_dto}

validate(dto)

@spec validate(t()) :: {:ok, t()} | {:error, atom()}

Validates a SampleDTO struct.

Returns {:ok, dto} if valid, {:error, reason} otherwise.

Examples

iex> dto = %SampleDTO{id: "abc", content: "test", version: "v1"}
iex> SampleDTO.validate(dto)
{:ok, %SampleDTO{}}

iex> invalid = %SampleDTO{id: nil, content: "test", version: "v1"}
iex> SampleDTO.validate(invalid)
{:error, :missing_id}