collab: Unconditionally execute billing checks (#19432)

This PR removes the conditional checks around the billing-related
enforcement for LLM completions.

These were just in place to prevent executing any billing code before we
had rolled it out. Now that it is rolled out, we don't need this
conditional execution anymore.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-10-18 15:55:28 -04:00 committed by GitHub
parent 11a82e3347
commit b44bed0115
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 35 deletions

View file

@ -198,10 +198,6 @@ impl Config {
} }
} }
pub fn is_llm_billing_enabled(&self) -> bool {
self.stripe_api_key.is_some()
}
#[cfg(test)] #[cfg(test)]
pub fn test() -> Self { pub fn test() -> Self {
Self { Self {

View file

@ -460,7 +460,6 @@ async fn check_usage_limit(
) )
.await?; .await?;
if state.config.is_llm_billing_enabled() {
if usage.spending_this_month >= FREE_TIER_MONTHLY_SPENDING_LIMIT { if usage.spending_this_month >= FREE_TIER_MONTHLY_SPENDING_LIMIT {
if !claims.has_llm_subscription { if !claims.has_llm_subscription {
return Err(Error::http( return Err(Error::http(
@ -484,7 +483,6 @@ async fn check_usage_limit(
)); ));
} }
} }
}
let active_users = state.get_active_user_count(provider, model_name).await?; let active_users = state.get_active_user_count(provider, model_name).await?;
@ -627,7 +625,6 @@ where
impl<S> Drop for TokenCountingStream<S> { impl<S> Drop for TokenCountingStream<S> {
fn drop(&mut self) { fn drop(&mut self) {
let state = self.state.clone(); let state = self.state.clone();
let is_llm_billing_enabled = state.config.is_llm_billing_enabled();
let claims = self.claims.clone(); let claims = self.claims.clone();
let provider = self.provider; let provider = self.provider;
let model = std::mem::take(&mut self.model); let model = std::mem::take(&mut self.model);
@ -641,14 +638,7 @@ impl<S> Drop for TokenCountingStream<S> {
provider, provider,
&model, &model,
tokens, tokens,
// We're passing `false` here if LLM billing is not enabled claims.has_llm_subscription,
// so that we don't write any records to the
// `billing_events` table until we're ready to bill users.
if is_llm_billing_enabled {
claims.has_llm_subscription
} else {
false
},
Cents(claims.max_monthly_spend_in_cents), Cents(claims.max_monthly_spend_in_cents),
Utc::now(), Utc::now(),
) )