collab: Add usages table to LLM database (#15884)

This PR adds a `usages` table to the LLM database.

We'll use this to track usage for rate-limiting purposes.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-08-06 18:40:10 -04:00 committed by GitHub
parent 4f69336024
commit a54e16b7ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 165 additions and 1 deletions

View file

@ -0,0 +1,15 @@
create table if not exists usages (
id serial primary key,
user_id integer not null,
model_id integer not null references models (id) on delete cascade,
requests_this_minute integer not null default 0,
tokens_this_minute bigint not null default 0,
requests_this_day integer not null default 0,
tokens_this_day bigint not null default 0,
requests_this_month integer not null default 0,
tokens_this_month bigint not null default 0
);
create index ix_usages_on_user_id on usages (user_id);
create index ix_usages_on_model_id on usages (model_id);
create unique index uix_usages_on_user_id_model_id on usages (user_id, model_id);