# Generated by SnakeBridge v0.16.0 - DO NOT EDIT MANUALLY # Regenerate with: mix compile # Library: dspy 3.2.0 # Python module: dspy.evaluate # Python class: EvaluationResult defmodule Dspy.Evaluate.EvaluationResult do @moduledoc """ A class that represents the result of an evaluation. It is a subclass of `dspy.Prediction` that contains the following fields - score: An float value (e.g., 67.30) representing the overall performance - results: a list of (example, prediction, score) tuples for each example in devset """ def __snakebridge_python_name__, do: "dspy.evaluate" def __snakebridge_python_class__, do: "EvaluationResult" def __snakebridge_library__, do: "dspy" @opaque t :: SnakeBridge.Ref.t() @doc """ Create an `Example` from fields or from an existing record. In the common case, pass fields as keyword arguments, like `dspy.Example(question="...", answer="...")`. Use `base` when you already have a dictionary or another `Example` and want to copy its fields before adding or overriding a few values. ## Parameters - `base` - A dictionary or `Example` to copy fields from before applying `**kwargs`. When `None`, starts with no fields. **kwargs: Field names and values to store on the example. If a field appears in both `base` and `**kwargs`, the value from `**kwargs` wins. """ @spec new(float(), list({term(), term(), term()}), keyword()) :: {:ok, SnakeBridge.Ref.t()} | {:error, Snakepit.Error.t()} def new(score, results, opts \\ []) do SnakeBridge.Runtime.call_class(__MODULE__, :__init__, [score, results], opts) end @doc """ Return a shallow copy, optionally overriding fields. ## Examples iex> import dspy iex> ex = dspy.Example(question="Why?", answer="Because.") iex> ex.copy(answer="No reason.") Example({'question': 'Why?', 'answer': 'No reason.'}) (input_keys=None) ## Parameters - `kwargs` (term()) ## Returns - `term()` """ @spec copy(SnakeBridge.Ref.t(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def copy(ref, opts \\ []) do SnakeBridge.Runtime.call_method(ref, :copy, [], opts) end @doc """ Python method `EvaluationResult.from_completions`. ## Parameters - `list_or_dict` (term()) - `signature` (term() default: None) ## Returns - `term()` """ @spec from_completions(SnakeBridge.Ref.t(), term(), list(term()), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def from_completions(ref, list_or_dict, args, opts \\ []) do {args, opts} = SnakeBridge.Runtime.normalize_args_opts(args, opts) SnakeBridge.Runtime.call_method( ref, :from_completions, [list_or_dict] ++ List.wrap(args), opts ) end @doc """ Return the value for `key`, or `default` if the field doesn't exist. ## Parameters - `key` - Field name to look up. - `default` - Value to return when `key` is missing. ## Examples iex> import dspy iex> ex = dspy.Example(name="Alice") iex> ex.get("name") 'Alice' iex> ex.get("city", "Unknown") 'Unknown' ## Returns - `term()` """ @spec get(SnakeBridge.Ref.t(), term(), list(term()), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def get(ref, key, args, opts \\ []) do {args, opts} = SnakeBridge.Runtime.normalize_args_opts(args, opts) SnakeBridge.Runtime.call_method(ref, :get, [key] ++ List.wrap(args), opts) end @doc """ Python method `EvaluationResult.get_lm_usage`. ## Returns - `term()` """ @spec get_lm_usage(SnakeBridge.Ref.t(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def get_lm_usage(ref, opts \\ []) do SnakeBridge.Runtime.call_method(ref, :get_lm_usage, [], opts) end @doc """ Return a new `Example` containing only the input fields. Requires `with_inputs` to have been called first. ## Raises - `ArgumentError` - If `with_inputs` was not called on this example. ## Examples iex> import dspy iex> ex = dspy.Example(question="Why?", answer="Because.").with_inputs("question") iex> ex.inputs() Example({'question': 'Why?'}) (input_keys={'question'}) ## Returns - `term()` """ @spec inputs(SnakeBridge.Ref.t(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def inputs(ref, opts \\ []) do SnakeBridge.Runtime.call_method(ref, :inputs, [], opts) end @doc """ Return `(field_name, value)` pairs, like `dict.items()`. ## Parameters - `include_dspy` - If `True`, include internal fields prefixed with `dspy_`. ## Examples iex> import dspy iex> dspy.Example(question="Why?", answer="Because.").items() [('question', 'Why?'), ('answer', 'Because.')] ## Returns - `term()` """ @spec items(SnakeBridge.Ref.t(), list(term()), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def items(ref, args, opts \\ []) do {args, opts} = SnakeBridge.Runtime.normalize_args_opts(args, opts) SnakeBridge.Runtime.call_method(ref, :items, [] ++ List.wrap(args), opts) end @doc """ Return field names, like `dict.keys()`. ## Parameters - `include_dspy` - If `True`, include internal fields prefixed with `dspy_`. Normally you can ignore these. ## Examples iex> import dspy iex> dspy.Example(question="Why?", answer="Because.").keys() ['question', 'answer'] ## Returns - `term()` """ @spec keys(SnakeBridge.Ref.t(), list(term()), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def keys(ref, args, opts \\ []) do {args, opts} = SnakeBridge.Runtime.normalize_args_opts(args, opts) SnakeBridge.Runtime.call_method(ref, :keys, [] ++ List.wrap(args), opts) end @doc """ Return a new `Example` containing only the label (non-input) fields. Requires `with_inputs` to have been called first, since labels are everything that is *not* an input. ## Examples iex> import dspy iex> ex = dspy.Example(question="Why?", answer="Because.").with_inputs("question") iex> ex.labels() Example({'answer': 'Because.'}) (input_keys=None) ## Returns - `term()` """ @spec labels(SnakeBridge.Ref.t(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def labels(ref, opts \\ []) do SnakeBridge.Runtime.call_method(ref, :labels, [], opts) end @doc """ Python method `EvaluationResult.set_lm_usage`. ## Parameters - `value` (term()) ## Returns - `term()` """ @spec set_lm_usage(SnakeBridge.Ref.t(), term(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def set_lm_usage(ref, value, opts \\ []) do SnakeBridge.Runtime.call_method(ref, :set_lm_usage, [value], opts) end @doc """ Convert to a plain dictionary, recursively serializing nested objects. Nested `Example` objects, Pydantic models, lists, and dicts are converted so the result is JSON-friendly. ## Examples iex> import dspy iex> dspy.Example(question="Why?", answer="Because.").toDict() {'question': 'Why?', 'answer': 'Because.'} ## Returns - `term()` """ @spec to_dict(SnakeBridge.Ref.t(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def to_dict(ref, opts \\ []) do SnakeBridge.Runtime.call_method(ref, "toDict", [], opts) end @doc """ Return field values, like `dict.values()`. ## Parameters - `include_dspy` - If `True`, include internal fields prefixed with `dspy_`. ## Examples iex> import dspy iex> dspy.Example(question="Why?", answer="Because.").values() ['Why?', 'Because.'] ## Returns - `term()` """ @spec values(SnakeBridge.Ref.t(), list(term()), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def values(ref, args, opts \\ []) do {args, opts} = SnakeBridge.Runtime.normalize_args_opts(args, opts) SnakeBridge.Runtime.call_method(ref, :values, [] ++ List.wrap(args), opts) end @doc """ Mark which fields are inputs and return a new `Example`. Fields not listed here are treated as labels (expected outputs). DSPy optimizers and evaluators use this split: they pass `example.inputs()` to your program and compare the output against `example.labels()`. ## Examples iex> import dspy iex> ex = dspy.Example(question="Why?", answer="Because.").with_inputs("question") iex> ex.inputs().keys() ['question'] iex> ex.labels().keys() ['answer'] ## Parameters - `keys` (term()) ## Returns - `term()` """ @spec with_inputs(SnakeBridge.Ref.t(), list(term()), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def with_inputs(ref, args, opts \\ []) do {args, opts} = SnakeBridge.Runtime.normalize_args_opts(args, opts) SnakeBridge.Runtime.call_method(ref, :with_inputs, [] ++ List.wrap(args), opts) end @doc """ Return a copy with the specified fields removed. ## Examples iex> import dspy iex> ex = dspy.Example(question="Why?", answer="Because.", source="web") iex> ex.without("source") Example({'question': 'Why?', 'answer': 'Because.'}) (input_keys=None) ## Parameters - `keys` (term()) ## Returns - `term()` """ @spec without(SnakeBridge.Ref.t(), list(term()), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def without(ref, args, opts \\ []) do {args, opts} = SnakeBridge.Runtime.normalize_args_opts(args, opts) SnakeBridge.Runtime.call_method(ref, :without, [] ++ List.wrap(args), opts) end @spec completions(SnakeBridge.Ref.t()) :: {:ok, term()} | {:error, Snakepit.Error.t()} def completions(ref) do SnakeBridge.Runtime.get_attr(ref, :completions) end end