-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add telemetry for LLM usage (#16049)
Release Notes: - N/A Co-authored-by: Marshall <marshall@zed.dev>
- Loading branch information
1 parent
423c7b9
commit 8688b2a
Showing
3 changed files
with
137 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use anyhow::Result; | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize, Debug, clickhouse::Row)] | ||
pub struct LlmUsageEventRow { | ||
pub time: i64, | ||
pub user_id: i32, | ||
pub is_staff: bool, | ||
pub plan: String, | ||
pub model: String, | ||
pub provider: String, | ||
pub input_token_count: u64, | ||
pub output_token_count: u64, | ||
pub requests_this_minute: u64, | ||
pub tokens_this_minute: u64, | ||
pub tokens_this_day: u64, | ||
pub tokens_this_month: u64, | ||
} | ||
|
||
pub async fn report_llm_usage(client: &clickhouse::Client, row: LlmUsageEventRow) -> Result<()> { | ||
let mut insert = client.insert("llm_usage_events")?; | ||
insert.write(&row).await?; | ||
insert.end().await?; | ||
Ok(()) | ||
} |