Dspy.Prediction (dspy v0.1.0)

View Source

Language model predictions with completion metadata.

Predictions represent the outputs from language model calls, including the generated content and metadata about the generation process.

Summary

Functions

Add completion metadata to the prediction.

Get all completions.

Delete an attribute from the prediction.

Get an attribute from the prediction.

Get all attribute keys.

Get the most recent completion.

Create a new Prediction with the given attributes.

Put an attribute in the prediction.

Convert prediction to a map.

Types

completion()

@type completion() :: %{
  text: String.t(),
  tokens: pos_integer() | nil,
  logprobs: map() | nil,
  finish_reason: String.t() | nil
}

t()

@type t() :: %Dspy.Prediction{
  attrs: map(),
  completions: [completion()],
  metadata: map()
}

Functions

add_completion(prediction, completion)

Add completion metadata to the prediction.

completions(prediction)

Get all completions.

delete(prediction, key)

Delete an attribute from the prediction.

get(prediction, key, default \\ nil)

Get an attribute from the prediction.

keys(prediction)

Get all attribute keys.

latest_completion(prediction)

Get the most recent completion.

new(attrs \\ %{}, completions \\ [], metadata \\ %{})

Create a new Prediction with the given attributes.

Examples

iex> pred = Dspy.Prediction.new(%{answer: "4"})
iex> pred.answer
"4"

iex> pred = Dspy.Prediction.new(answer: "4", reasoning: "2+2=4")
iex> pred.reasoning
"2+2=4"

put(prediction, key, value)

Put an attribute in the prediction.

to_map(prediction)

Convert prediction to a map.