From 0f22ef9bf5e5b37423aaa4f9b913ac5519b27566 Mon Sep 17 00:00:00 2001 From: liblaf Date: Sat, 18 Nov 2023 17:14:37 +0800 Subject: [PATCH] feat(cmd): add token usage information to commit message prompt Add code to display the number of tokens used in the commit message prompt. This information includes the number of tokens used for the prompt and completion, as well as the total number of tokens used. This helps users understand the impact of their commit message on token usage. --- src/cmd/commit.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cmd/commit.rs b/src/cmd/commit.rs index 07cf8977..633e949b 100644 --- a/src/cmd/commit.rs +++ b/src/cmd/commit.rs @@ -87,6 +87,14 @@ impl Run for Cmd { .build() .log()?; let response = client.chat().create(request).await.log()?; + if let Some(usage) = response.usage { + println!( + "Tokens: {} (prompt) + {} (completion) = {} (total)", + usage.prompt_tokens.to_string().bold().cyan(), + usage.completion_tokens.to_string().bold().cyan(), + usage.total_tokens.to_string().bold().cyan() + ); + } let select = Select::new( &format!( "Pick a commit message to use: {}",