@grafctory/llms
    Preparing search index...

    Type Alias Quota

    Model rate quota.

    Submits requests to a single model, paced against an adaptive throttle shared by all of them, so that concurrent consumers of the model keep within its rate quota. Attempts are logged under the model name.

    Until the provider advertises the request limit of the model, the pace is set by the throttle alone, slowing down on rejections and speeding up on successes; once advertised, the limit caps how fast the throttle may go.

    type Quota = {
        submit<V>(
            request: () => Promise<V>,
            recover: (error: unknown) => Optional<number>,
        ): Promise<V>;
        limit(limit: Optional<number>): void;
    }
    Index
    • Submits a request to the model.

      Type Parameters

      • V

        The type of the value the request resolves to

      Parameters

      • request: () => Promise<V>

        The request to submit, issued anew on every attempt

      • recover: (error: unknown) => Optional<number>

        The recovery deciding whether a rejection is retried: returns the delay in ms the request is to be retried after, 0 leaving the pace to the throttle, or undefined to give up with the rejection

      Returns Promise<V>

      The value request resolves to, once an attempt succeeds

      The rejection of the last attempt, if recover gives up on it

    • Caps the pace of the model at the request limit the provider advertises for it.

      Meant to be called with whatever each response or rejection advertises, as often as the provider replies: requests already waiting keep the pace they were submitted at, so a change of limit takes effect from the next request on.

      Parameters

      • limit: Optional<number>

        The number of requests per minute the provider accepts for the model, or undefined if the provider advertises none, leaving the pace as it stands until a later call states a limit

      Returns void

      TypeError If limit is neither undefined nor a positive finite number