LemonAi. PromptDiagnostics
(lemon_ai v0.1.0)
View Source
Lightweight, opt-in diagnostics for prompt size + token usage.
This module is intentionally conservative about what it records: it captures sizes, counts, and hashes (no raw prompt text).
Enable with:
export LEMON_AI_PROMPT_DIAGNOSTICS=1Optionally set:
export LEMON_AI_PROMPT_DIAGNOSTICS_LOG_LEVEL=info
export LEMON_AI_PROMPT_DIAGNOSTICS_TOP_N=5Recorded introspection event type:
:ai_llm_call
Summary
Functions
Return true if diagnostics are enabled via env var.
Record a combined prompt+usage snapshot for non-streaming calls.
Record a combined prompt+usage snapshot for a completed LLM call.
Compute a conservative size breakdown for an LLM context.
Functions
@spec enabled?() :: boolean()
Return true if diagnostics are enabled via env var.
@spec record_complete_call( LemonAi.Types.Model.t(), LemonAi.Types.Context.t(), LemonAi.Types.StreamOptions.t() | map(), LemonAi.Types.AssistantMessage.t() ) :: :ok
Record a combined prompt+usage snapshot for non-streaming calls.
@spec record_llm_call( LemonAi.Types.Model.t(), LemonAi.Types.Context.t(), LemonAi.Types.StreamOptions.t(), LemonAi.Types.AssistantMessage.t() ) :: :ok
Record a combined prompt+usage snapshot for a completed LLM call.
This records a single introspection event (:ai_llm_call) containing:
- request sizing (bytes + hashes)
- response usage (tokens, including cache read/write when available)
@spec stats(LemonAi.Types.Context.t()) :: map()
Compute a conservative size breakdown for an LLM context.