collab: Use a separate Anthropic API key for Zed staff (#16128)

This PR makes it so Zed staff can use a separate Anthropic API key for
the LLM service.

We also added an `is_staff` column to the `usages` table so that we can
exclude staff usage from the "active users" metrics that influence the
rate limits.

Release Notes:

- N/A

---------

Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Marshall Bowers
2024-08-12 15:20:34 -04:00
committed by GitHub
co-authored by Max
parent ebdde5994d
commit f3ec8d425f
8 changed files with 47 additions and 11 deletions
+14 -5
View File
@@ -171,11 +171,19 @@ async fn perform_completion(
let stream = match params.provider {
LanguageModelProvider::Anthropic => {
let api_key = state
.config
.anthropic_api_key
.as_ref()
.context("no Anthropic AI API key configured on the server")?;
let api_key = if claims.is_staff {
state
.config
.anthropic_staff_api_key
.as_ref()
.context("no Anthropic AI staff API key configured on the server")?
} else {
state
.config
.anthropic_api_key
.as_ref()
.context("no Anthropic AI API key configured on the server")?
};
let mut request: anthropic::Request =
serde_json::from_str(&params.provider_request.get())?;
@@ -473,6 +481,7 @@ impl<S> Drop for TokenCountingStream<S> {
.db
.record_usage(
claims.user_id as i32,
claims.is_staff,
provider,
&model,
input_token_count,