Dspy.Example (dspy v0.1.0)

View Source

Training examples for DSPy programs.

Examples represent input-output pairs used for few-shot learning, optimization, and evaluation. They support flexible attribute access and can contain arbitrary fields.

Summary

Functions

Delete an attribute from the example.

Get an attribute from the example.

Get all attribute keys.

Merge two examples, with the second taking precedence.

Create a new Example with the given attributes.

Put an attribute in the example.

Convert example to a map.

Types

t()

@type t() :: %Dspy.Example{attrs: map(), metadata: map()}

Functions

delete(example, key)

Delete an attribute from the example.

get(example, key, default \\ nil)

Get an attribute from the example.

keys(example)

Get all attribute keys.

merge(example1, example2)

Merge two examples, with the second taking precedence.

new(attrs \\ %{}, metadata \\ %{})

Create a new Example with the given attributes.

Examples

iex> ex = Dspy.Example.new(%{question: "What is 2+2?", answer: "4"})
iex> ex.question
"What is 2+2?"

iex> ex = Dspy.Example.new(question: "What is 2+2?", answer: "4")
iex> ex.answer
"4"

put(example, key, value)

Put an attribute in the example.

to_map(example)

Convert example to a map.