Module de.seggebaeing.sqlanalyzer
Class PromptAuthorizer
java.lang.Object
de.seggebaeing.sqlanalyzer.logic.promptable.util.PromptAuthorizer
Centralized utility to handle authorization for sending prompts to LLMs by
respecting rate limits.
Each LLM
can be associated with a retry time until which calls should
be delayed. This class ensures that threads wait appropriately before allowing
further requests.
Usage: Access the singleton instance via getInstance()
.
-
Method Summary
Modifier and TypeMethodDescriptionstatic PromptAuthorizer
void
registerInstant
(LLM llm, Instant waitUntil) Registers or extends the rate-limit deadline for the givenLLM
.void
waitUntilAuthorized
(LLM llm) Blocks the current thread until prompting the givenLLM
is permitted.
-
Method Details
-
getInstance
-
waitUntilAuthorized
Blocks the current thread until prompting the givenLLM
is permitted.If no retry deadline is registered, returns immediately. Otherwise, sleeps until the recorded
Instant
; if interrupted, logs a warning and returns early. If the deadline is updated while waiting, the method adapts to the newest value.- Parameters:
llm
- non-null LLM whose rate-limit deadline should be respected- Implementation Note:
- Uses a sleep-based loop by design; do not call from the JavaFX Application Thread or other latency-sensitive threads.
-
registerInstant
Registers or extends the rate-limit deadline for the givenLLM
.Stores
waitUntil
if no deadline exists or if it is later than the currently stored one (monotonic extension). Synchronized for thread safety.- Parameters:
llm
- the LLM to rate-limitwaitUntil
- the time after which prompting is allowed again- Throws:
NullPointerException
- ifllm
isnull
orwaitUntil
isnull
-