java.lang.Object
de.seggebaeing.sqlanalyzer.logic.promptable.util.PromptAuthorizer

public class PromptAuthorizer extends Object
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 Details

    • getInstance

      public static PromptAuthorizer getInstance()
    • waitUntilAuthorized

      public void waitUntilAuthorized(LLM llm)
      Blocks the current thread until prompting the given LLM 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

      public void registerInstant(LLM llm, Instant waitUntil)
      Registers or extends the rate-limit deadline for the given LLM.

      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-limit
      waitUntil - the time after which prompting is allowed again
      Throws:
      NullPointerException - if llm is null or waitUntil is null