mirror of
https://github.com/zed-industries/zed.git
synced 2026-06-01 03:14:56 +07:00
acp_thread: Log token usage when receiving StopReason::MaxTokens (#49343)
Before you mark this PR as ready for review, make sure that you have: - [ ] Added a solid test coverage and/or screenshots from doing manual testing - [x] Done a self-review taking into account security and performance aspects - [x] Aligned any UI changes with the [UI checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) Release Notes: - N/A
This commit is contained in:
parent
6f8023530c
commit
af4ecae176
5 changed files with 10 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -22,6 +22,7 @@ dependencies = [
|
|||
"itertools 0.14.0",
|
||||
"language",
|
||||
"language_model",
|
||||
"log",
|
||||
"markdown",
|
||||
"multi_buffer",
|
||||
"parking_lot",
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ gpui.workspace = true
|
|||
itertools.workspace = true
|
||||
language.workspace = true
|
||||
language_model.workspace = true
|
||||
log.workspace = true
|
||||
markdown.workspace = true
|
||||
parking_lot = { workspace = true, optional = true }
|
||||
image = { workspace = true, optional = true }
|
||||
|
|
|
|||
|
|
@ -885,6 +885,7 @@ pub struct TokenUsage {
|
|||
pub used_tokens: u64,
|
||||
pub input_tokens: u64,
|
||||
pub output_tokens: u64,
|
||||
pub max_output_tokens: Option<u64>,
|
||||
}
|
||||
|
||||
impl TokenUsage {
|
||||
|
|
@ -1953,11 +1954,13 @@ impl AcpThread {
|
|||
Ok(Err(e)) => {
|
||||
this.send_task.take();
|
||||
cx.emit(AcpThreadEvent::Error);
|
||||
log::error!("Error in run turn: {:?}", e);
|
||||
Err(e)
|
||||
}
|
||||
Ok(Ok(r)) if r.stop_reason == acp::StopReason::MaxTokens => {
|
||||
this.send_task.take();
|
||||
cx.emit(AcpThreadEvent::Error);
|
||||
log::error!("Max tokens reached. Usage: {:?}", this.token_usage);
|
||||
Err(anyhow!("Max tokens reached"))
|
||||
}
|
||||
result => {
|
||||
|
|
|
|||
|
|
@ -2736,6 +2736,7 @@ async fn test_truncate_first_message(cx: &mut TestAppContext) {
|
|||
Some(acp_thread::TokenUsage {
|
||||
used_tokens: 32_000 + 16_000,
|
||||
max_tokens: 1_000_000,
|
||||
max_output_tokens: None,
|
||||
input_tokens: 32_000,
|
||||
output_tokens: 16_000,
|
||||
})
|
||||
|
|
@ -2797,6 +2798,7 @@ async fn test_truncate_first_message(cx: &mut TestAppContext) {
|
|||
Some(acp_thread::TokenUsage {
|
||||
used_tokens: 40_000 + 20_000,
|
||||
max_tokens: 1_000_000,
|
||||
max_output_tokens: None,
|
||||
input_tokens: 40_000,
|
||||
output_tokens: 20_000,
|
||||
})
|
||||
|
|
@ -2847,6 +2849,7 @@ async fn test_truncate_second_message(cx: &mut TestAppContext) {
|
|||
Some(acp_thread::TokenUsage {
|
||||
used_tokens: 32_000 + 16_000,
|
||||
max_tokens: 1_000_000,
|
||||
max_output_tokens: None,
|
||||
input_tokens: 32_000,
|
||||
output_tokens: 16_000,
|
||||
})
|
||||
|
|
@ -2903,6 +2906,7 @@ async fn test_truncate_second_message(cx: &mut TestAppContext) {
|
|||
Some(acp_thread::TokenUsage {
|
||||
used_tokens: 40_000 + 20_000,
|
||||
max_tokens: 1_000_000,
|
||||
max_output_tokens: None,
|
||||
input_tokens: 40_000,
|
||||
output_tokens: 20_000,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1507,6 +1507,7 @@ impl Thread {
|
|||
let model = self.model.clone()?;
|
||||
Some(acp_thread::TokenUsage {
|
||||
max_tokens: model.max_token_count(),
|
||||
max_output_tokens: model.max_output_tokens(),
|
||||
used_tokens: usage.total_tokens(),
|
||||
input_tokens: usage.input_tokens,
|
||||
output_tokens: usage.output_tokens,
|
||||
|
|
|
|||
Loading…
Reference in a new issue