DotPrompt (anantha_dot_prompt v1.1.0)

Copy Markdown

Main API for dot-prompt.

Summary

Functions

Returns statistics about the current cache usage.

Compiles a prompt for given params. Returns {:ok, %DotPrompt.Result{}} or {:error, map()}

Internal compile that returns iodata for maximum efficiency when nesting fragments.

Invalidates all caches (structural, fragment, and vary).

Invalidates the cache for a specific prompt.

Lists only fragment prompts.

Lists all available prompts including fragments.

Lists only root-level prompts (excluding fragments).

Renders a prompt by compiling it and injecting runtime data.

Extracts the schema and metadata for a given prompt.

Validates an LLM response against a response contract.

Types

compile_opts()

@type compile_opts() :: [indent: integer(), seed: integer()]

params()

@type params() :: map()

prompt_name()

@type prompt_name() :: String.t()

runtime()

@type runtime() :: map()

schema_info()

@type schema_info() :: %{
  name: prompt_name(),
  version: integer(),
  description: String.t() | nil,
  mode: String.t() | nil,
  docs: String.t() | nil,
  params: map(),
  fragments: map()
}

Functions

cache_stats()

@spec cache_stats() :: %{structural: integer(), fragment: integer(), vary: integer()}

Returns statistics about the current cache usage.

compile(prompt_name_or_content, params, opts \\ [])

@spec compile(prompt_name() | String.t(), params(), compile_opts()) ::
  {:ok, DotPrompt.Result.t()} | {:error, map()}

Compiles a prompt for given params. Returns {:ok, %DotPrompt.Result{}} or {:error, map()}

compile_string(content, params, opts \\ [])

compile_to_iodata(prompt_name_or_content, params, opts \\ [])

@spec compile_to_iodata(prompt_name() | String.t(), params(), compile_opts()) ::
  {:ok, iodata(), map(), MapSet.t(), map(), boolean(), [String.t()],
   map() | nil, integer(), integer() | String.t(), map()}
  | {:error, map()}

Internal compile that returns iodata for maximum efficiency when nesting fragments.

inject(template, runtime)

invalidate_all_cache()

@spec invalidate_all_cache() :: :ok

Invalidates all caches (structural, fragment, and vary).

invalidate_cache(prompt_name)

@spec invalidate_cache(prompt_name()) :: :ok

Invalidates the cache for a specific prompt.

list_collections(opts \\ [])

list_fragment_prompts()

@spec list_fragment_prompts() :: [prompt_name()]

Lists only fragment prompts.

list_prompts(opts \\ [])

@spec list_prompts(keyword()) :: [prompt_name()]

Lists all available prompts including fragments.

list_root_prompts()

@spec list_root_prompts() :: [prompt_name()]

Lists only root-level prompts (excluding fragments).

render(prompt_name_or_content, params, runtime, opts \\ [])

@spec render(prompt_name() | String.t(), params(), runtime(), compile_opts()) ::
  {:ok, DotPrompt.Result.t()} | {:error, map()}

Renders a prompt by compiling it and injecting runtime data.

schema(prompt_name, major \\ nil, opts \\ [])

@spec schema(prompt_name(), integer() | nil, keyword()) ::
  {:ok, schema_info()} | {:error, map()}

Extracts the schema and metadata for a given prompt.

validate_output(response_json, contract, opts \\ [])

@spec validate_output(String.t(), map(), keyword()) :: :ok | {:error, String.t()}

Validates an LLM response against a response contract.