Skip to content

Commit 51c6704

Browse files
authored
Merge pull request #115 from adeeshperera/main
Fix #113 : add token count, cost estimation, and processing time to dry run mode
2 parents 3d2e536 + 4a824ad commit 51c6704

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

cmd/cli/createMsg.go

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,26 @@ func displayDryRunInfo(provider types.LLMProvider, config *types.Config, changes
548548
pterm.DefaultSection.Println("Changes Summary")
549549
linesCount := len(strings.Split(changes, "\n"))
550550
charsCount := len(changes)
551+
inputTokens := estimateTokens(prompt)
552+
// Estimate output tokens (typically 50-200 for commit messages)
553+
outputTokens := 100
554+
estimatedCost := estimateCost(provider, inputTokens, outputTokens)
555+
minTime, maxTime := estimateProcessingTime(provider)
551556

552557
statsData := [][]string{
553558
{"Total Lines", fmt.Sprintf("%d", linesCount)},
554559
{"Total Characters", fmt.Sprintf("%d", charsCount)},
555-
{"Prompt Size (approx)", fmt.Sprintf("%d tokens", estimateTokens(prompt))},
560+
{"Estimated Input Tokens", fmt.Sprintf("%d", inputTokens)},
561+
{"Estimated Output Tokens", fmt.Sprintf("%d", outputTokens)},
562+
{"Estimated Total Tokens", fmt.Sprintf("%d", inputTokens+outputTokens)},
556563
}
564+
565+
if provider != types.ProviderOllama {
566+
statsData = append(statsData, []string{"Estimated Cost", fmt.Sprintf("$%.4f", estimatedCost)})
567+
}
568+
569+
statsData = append(statsData, []string{"Estimated Processing Time", fmt.Sprintf("%d-%d seconds", minTime, maxTime)})
570+
557571
pterm.DefaultTable.WithHasHeader(false).WithData(statsData).Render()
558572

559573
pterm.Println()
@@ -581,6 +595,47 @@ func estimateTokens(text string) int {
581595
return len(text) / 4
582596
}
583597

598+
// estimateCost calculates the estimated cost for a given provider and token count
599+
func estimateCost(provider types.LLMProvider, inputTokens, outputTokens int) float64 {
600+
// Pricing per 1M tokens (as of 2024, approximate)
601+
switch provider {
602+
case types.ProviderOpenAI:
603+
// GPT-4o pricing: ~$2.50/M input, ~$10/M output
604+
return float64(inputTokens)*2.50/1000000 + float64(outputTokens)*10.00/1000000
605+
case types.ProviderClaude:
606+
// Claude pricing: ~$3/M input, ~$15/M output
607+
return float64(inputTokens)*3.00/1000000 + float64(outputTokens)*15.00/1000000
608+
case types.ProviderGemini:
609+
// Gemini pricing: ~$0.15/M input, ~$0.60/M output
610+
return float64(inputTokens)*0.15/1000000 + float64(outputTokens)*0.60/1000000
611+
case types.ProviderGrok:
612+
// Grok pricing: ~$5/M input, ~$15/M output
613+
return float64(inputTokens)*5.00/1000000 + float64(outputTokens)*15.00/1000000
614+
case types.ProviderGroq:
615+
// Groq pricing: similar to OpenAI ~$2.50/M input, ~$10/M output
616+
return float64(inputTokens)*2.50/1000000 + float64(outputTokens)*10.00/1000000
617+
case types.ProviderOllama:
618+
// Local model - no cost
619+
return 0.0
620+
default:
621+
return 0.0
622+
}
623+
}
624+
625+
// estimateProcessingTime returns estimated processing time in seconds for a provider
626+
func estimateProcessingTime(provider types.LLMProvider) (minTime, maxTime int) {
627+
switch provider {
628+
case types.ProviderOllama:
629+
// Local models take longer
630+
return 10, 30
631+
case types.ProviderOpenAI, types.ProviderClaude, types.ProviderGemini, types.ProviderGrok, types.ProviderGroq:
632+
// Cloud providers are faster
633+
return 5, 15
634+
default:
635+
return 5, 15
636+
}
637+
}
638+
584639
// validateCommitMessageLength checks if the commit message exceeds recommended length limits
585640
// and displays appropriate warnings
586641
func validateCommitMessageLength(message string) {

0 commit comments

Comments
 (0)