Lotus.AI.QueryGenerator (Lotus v1.0.0)

Copy Markdown View Source

Generates query statements from natural language using ReqLLM.

Handles tool building, message handling, and response extraction. Any provider supported by ReqLLM can be used by passing a model string like "openai:gpt-4o" or "anthropic:claude-opus-4".

Summary

Functions

Generate a query statement using the given model string and options.

Validate that a config contains a non-empty API key string.

Types

statement_response()

@type statement_response() :: %{
  content: String.t(),
  model: String.t(),
  variables: [map()],
  usage: %{
    prompt_tokens: non_neg_integer(),
    completion_tokens: non_neg_integer(),
    total_tokens: non_neg_integer()
  }
}

Functions

generate_statement(model_string, opts)

@spec generate_statement(
  String.t(),
  keyword()
) :: {:ok, statement_response()} | {:error, term()}

Generate a query statement using the given model string and options.

The model string should be in ReqLLM format, e.g. "openai:gpt-4o", "anthropic:claude-opus-4", "google:gemini-2.0-flash".

Options

  • :prompt (required) - Natural language query
  • :data_source (required) - Name of the data source
  • :api_key (required) - API key for the provider
  • :conversation - Conversation struct for multi-turn
  • :query_context - Additional context for the query
  • :read_only - Whether to restrict to read-only statements (default: true)
  • :temperature - LLM temperature (default: 0.1)
  • :context - Caller-supplied actor context, threaded into every query and introspection call the AI makes
  • :scope - Caller-supplied visibility scope, threaded the same way

validate_key(config)

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

Validate that a config contains a non-empty API key string.