Skip to content

Commit

Permalink
Merge pull request #24 from ytkg/add-debug-option
Browse files Browse the repository at this point in the history
Add debug option
  • Loading branch information
ytkg authored Jun 21, 2023
2 parents 7896333 + 2b763d9 commit bd95837
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions commands/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class MainCommand extends Command {
.env("OPENAI_API_KEY=<value:string>", "OPENAI API KEY")
.type("model-type", modelType)
.option("-m --model <model:model-type>", "Model name")
.option("-d, --debug", "Print debug log")
.action(async (options) => {
const config = await loadConfig();
const apiKey = options.openaiAccessToken || options.openaiApiKey ||
Expand All @@ -38,6 +39,7 @@ export class MainCommand extends Command {
apiKey,
diffText,
model,
options.debug,
);

console.log(commitMessageSuggestion);
Expand Down
3 changes: 2 additions & 1 deletion commands/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Deno.test("help command", () => {
Options:
-m, --model <model> - Model name (Values: "gpt-3.5-turbo", "gpt-4")
-m, --model <model> - Model name (Values: "gpt-3.5-turbo", "gpt-4")
-d, --debug - Print debug log
Commands:
Expand Down
9 changes: 9 additions & 0 deletions lib/get_commit_message_suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const getCommitMessageSuggestion = async (
openaiAccessToken: string,
diffText: string,
model: Model,
debug: boolean | undefined,
): Promise<string> => {
const openAI = new OpenAI(openaiAccessToken);

Expand Down Expand Up @@ -44,5 +45,13 @@ export const getCommitMessageSuggestion = async (
Deno.exit(1);
}

if (debug) {
const { prompt_tokens, completion_tokens, total_tokens } =
chatCompletion.usage;
console.log(
`prompt_tokens: ${prompt_tokens}, completion_tokens: ${completion_tokens}, total_tokens: ${total_tokens}\n`,
);
}

return chatCompletion.choices[0].message.content;
};

0 comments on commit bd95837

Please sign in to comment.