Configuration for extraction operations using NimbleOptions for validation.
Examples
iex> config = LeXtract.Config.new(prompt: "test", max_char_buffer: 2000)
iex> config.max_char_buffer
2000
iex> config = LeXtract.Config.default()
iex> config.batch_size
5
Summary
Functions
Returns default configuration.
Converts a keyword list to a Config struct with validation.
Converts a keyword list to a Config struct, raising on error.
Creates and validates configuration from keyword list.
Converts a Config struct to a keyword list.
Validates configuration keyword list or struct.
Validates configuration and raises on error.
Types
@type options() :: [ prompt: binary(), examples: [term()], template_file: binary(), format: term(), fence_output: boolean(), use_structured_output: boolean(), max_char_buffer: pos_integer(), chunk_overlap: non_neg_integer(), batch_size: pos_integer(), extraction_passes: pos_integer(), max_concurrency: pos_integer(), attribute_suffix: binary() ]
:prompt(String.t/0) - Extraction prompt/description:examples(list ofterm/0) - List of example extractions (maps with :text and :extractions keys) The default value is[].:template_file(String.t/0) - Path to template file (.json or .yaml):format- Output format for extractions The default value is:yaml.:fence_output(boolean/0) - Expect fenced code blocks in LLM response The default value isfalse.:use_structured_output(boolean/0) - Use structured output mode (generate_object) The default value isfalse.:max_char_buffer(pos_integer/0) - Maximum chunk size in characters The default value is1000.:chunk_overlap(non_neg_integer/0) - Character overlap between chunks (default: 20% of max_char_buffer):batch_size(pos_integer/0) - Number of chunks per LLM batch The default value is5.:extraction_passes(pos_integer/0) - Number of extraction passes for multi-pass extraction The default value is1.:max_concurrency(pos_integer/0) - Maximum concurrent LLM requests The default value is8.:attribute_suffix(String.t/0) - Suffix for attribute keys in structured output The default value is"_attributes".
@type t() :: %LeXtract.Config{ attribute_suffix: String.t(), batch_size: pos_integer(), chunk_overlap: non_neg_integer(), examples: [map()], extraction_passes: pos_integer(), fence_output: boolean(), format: :json | :yaml, max_char_buffer: pos_integer(), max_concurrency: pos_integer(), prompt: String.t() | nil, template_file: String.t() | nil, use_structured_output: boolean() }
Functions
@spec default() :: t()
Returns default configuration.
Examples
iex> config = LeXtract.Config.default()
iex> config.batch_size
5
@spec from_keyword(keyword()) :: {:ok, t()} | {:error, Exception.t()}
Converts a keyword list to a Config struct with validation.
This function is useful for maintaining backward compatibility with code that uses keyword lists. It validates the options and returns a Config struct.
Examples
iex> {:ok, config} = LeXtract.Config.from_keyword(prompt: "test")
iex> config.prompt
"test"
iex> {:error, _} = LeXtract.Config.from_keyword([])
Converts a keyword list to a Config struct, raising on error.
Examples
iex> config = LeXtract.Config.from_keyword!(prompt: "test")
iex> config.prompt
"test"
Creates and validates configuration from keyword list.
Validates options using NimbleOptions and raises NimbleOptions.ValidationError if invalid.
Examples
iex> config = LeXtract.Config.new(prompt: "test", max_char_buffer: 2000)
iex> config.max_char_buffer
2000
iex> LeXtract.Config.new(prompt: "test", max_char_buffer: -1)
** (NimbleOptions.ValidationError) invalid value for :max_char_buffer option: expected positive integer, got: -1
iex> LeXtract.Config.new(prompt: "test", format: :xml)
** (NimbleOptions.ValidationError) invalid value for :format option: expected one of [:json, :yaml], got: :xml
Converts a Config struct to a keyword list.
This is useful for backward compatibility when functions expect keyword lists.
Examples
iex> config = LeXtract.Config.new(prompt: "test")
iex> kw = LeXtract.Config.to_keyword(config)
iex> Keyword.get(kw, :prompt)
"test"
@spec validate(keyword() | t()) :: {:ok, t()} | {:error, Exception.t()}
Validates configuration keyword list or struct.
Returns {:ok, validated_config} on success or {:error, validation_error} on failure.
Examples
iex> {:ok, config} = LeXtract.Config.validate(max_char_buffer: 1000, prompt: "test")
iex> config.max_char_buffer
1000
iex> {:error, error} = LeXtract.Config.validate(max_char_buffer: -1, prompt: "test")
iex> String.contains?(Exception.message(error), "expected positive integer")
true
iex> {:error, error} = LeXtract.Config.validate(format: :xml, prompt: "test")
iex> String.contains?(Exception.message(error), "expected one of")
true
Validates configuration and raises on error.
Returns the validated config struct or raises LeXtract.Error.Invalid.Config.
Examples
iex> LeXtract.Config.validate!(max_char_buffer: 1000, prompt: "test")
%LeXtract.Config{max_char_buffer: 1000, prompt: "test"}
iex> LeXtract.Config.validate!(max_char_buffer: -1, prompt: "test")
** (LeXtract.Error.Invalid.Config) Configuration validation failed: invalid value for :max_char_buffer option: expected positive integer, got: -1