Skip to content

Commit

Permalink
feat(cmd): add token usage information to commit message prompt
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
liblaf committed Nov 18, 2023
1 parent 1c2b357 commit 0f22ef9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cmd/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}",
Expand Down

0 comments on commit 0f22ef9

Please sign in to comment.