Skip to content

Commit

Permalink
collab: Count active users based on the tokens per minute measure (#1…
Browse files Browse the repository at this point in the history
…6911)

This PR fixes an issue where active user counts were being computed
across _all_ measures instead of the per-minute measures.

We now compute them using the tokens per minute measure, as we're
concerned with usage in recent minutes.

Release Notes:

- N/A
  • Loading branch information
maxdeviant authored Aug 26, 2024
1 parent 3ddec48 commit 93a7682
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/collab/src/llm/db/queries/usages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,13 @@ impl LlmDatabase {
.get(&(provider, model_name.to_string()))
.ok_or_else(|| anyhow!("unknown model {provider}:{model_name}"))?;

let tokens_per_minute = self.usage_measure_ids[&UsageMeasure::TokensPerMinute];

let users_in_recent_minutes = usage::Entity::find()
.filter(
usage::Column::ModelId
.eq(model.id)
.and(usage::Column::MeasureId.eq(tokens_per_minute))
.and(usage::Column::Timestamp.gte(minute_since.naive_utc()))
.and(usage::Column::IsStaff.eq(false)),
)
Expand All @@ -376,6 +379,7 @@ impl LlmDatabase {
.filter(
usage::Column::ModelId
.eq(model.id)
.and(usage::Column::MeasureId.eq(tokens_per_minute))
.and(usage::Column::Timestamp.gte(day_since.naive_utc()))
.and(usage::Column::IsStaff.eq(false)),
)
Expand Down

0 comments on commit 93a7682

Please sign in to comment.