Introduce AiQuotaException

Created on 8 July 2024, 2 months ago
Updated 8 August 2024, about 1 month ago

Problem/Motivation

With many (all?) AI providers, free tier for API tokens either doesn't exist or is very limited.
That means, that after obtaining an API key, site user cannot send queries to provider, getting an error instead.

Currently, generic exception is thrown, and there is helpful enough message, which unfortunately is buried in the message log. It would be easier to debug/fix, if in such case provider throws designated exception. Handling such an exception could result in error messages in status report (or other places, like AI settings page)

Steps to reproduce

  • Create a free account with Open AI, and create a secret key in default project.
  • Configure AI to use Open AI for chat, using the newly created key.
  • Try to perform any AI operation

Proposed resolution

  • Create Drupal\ai\Exception\AiQuotaException, that is thrown when quota is exceeded.
  • When this exception is thrown, set a flag (in State?) marking the whole provider unusable.
  • Provide a way to clear the flag (on cron? button in AI settings?)
  • Implement provider-specific checks for the quota. This does not have to be done for all providers at once, since not having AiQuotaException for specific provider will only leave it with the current DX (no regression)

Remaining tasks

  • Decide where to display information about quota limit
  • Decide how to clear the flag about over-quota

User interface changes

None or manual clearance of over-quota flag

API changes

No API changes

Data model changes

No data model changes

Feature request
Status

Fixed

Version

1.0

Component

AI Core module

Created by

🇧🇬Bulgaria valthebald Sofia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024