View Source Lightning.Extensions.UsageLimiting behaviour (Lightning v2.10.4)
Rate limiting for Lightning workloads that depends on Runtime.
Summary
Callbacks
Checks the usage limits for a given project and user context, returning an error message if the limits are exceeded.
Returns run options based on the given project context. The run options include a timeout value and a flag for saving dataclips.
Increments the AI query count for a given chat session.
Limits specific actions based on an Action
and Context
.
Types
@type error() :: {:error, error_reason(), message()}
@type error_reason() ::
:too_many_runs | :too_many_queries | :runs_hard_limit | :unknown_project
@type message() :: Lightning.Extensions.Message.t()
Callbacks
@callback check_limits(context :: Lightning.Extensions.UsageLimiting.Context.t()) :: :ok | error()
Checks the usage limits for a given project and user context, returning an error message if the limits are exceeded.
Requires a Context
struct containing the project_id
and user_id
.
Returns
{:ok}
if the limits are within bounds.{:error, reason, message}
if the limits are exceeded.
@callback get_data_retention_message( context :: Lightning.Extensions.UsageLimiting.Context.t() ) :: message() | nil
@callback get_data_retention_periods( context :: Lightning.Extensions.UsageLimiting.Context.t() ) :: [ pos_integer(), ... ]
@callback get_run_options(context :: Lightning.Extensions.UsageLimiting.Context.t()) :: Lightning.Runs.RunOptions.keyword_list()
Returns run options based on the given project context. The run options include a timeout value and a flag for saving dataclips.
Requires a Context
struct containing the project_id
.
Returns
- A keyword list of run options including:
:run_timeout_ms
: The run timeout in milliseconds.:save_dataclips
: A boolean indicating whether to save dataclips.
@callback increment_ai_queries(Lightning.AiAssistant.ChatSession.t()) :: Ecto.Multi.t()
Increments the AI query count for a given chat session.
Requires a Lightning.AiAssistant.ChatSession
struct.
Returns
- An Ecto.Multi struct representing the transaction to increment AI queries.
@callback limit_action( action :: Lightning.Extensions.UsageLimiting.Action.t(), context :: Lightning.Extensions.UsageLimiting.Context.t() ) :: :ok | error()
Limits specific actions based on an Action
and Context
.
Returns
:ok
if the action is allowed.{:error, reason, message}
if the action is not allowed.