Skip to content

Commit d39d995

Browse files
committed
Remove cost estimates from token usage helper
1 parent eb0873d commit d39d995

3 files changed

Lines changed: 9 additions & 43 deletions

File tree

tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/TokenUsageHelper.cs

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,23 @@ namespace Azure.Sdk.Tools.Cli.Helpers;
22

33
public class TokenUsageHelper(IOutputHelper outputHelper)
44
{
5-
private static Dictionary<string, (double inputPrice, double outputPrice)> modelPrices = new()
6-
{
7-
// Global pricing via https://platform.openai.com/docs/pricing
8-
{ "gpt-5", (1.25, 10) },
9-
{ "gpt-5-mini", (0.25, 2) },
10-
{ "gpt-4.1", (2, 8) },
11-
{ "gpt-4.1-mini", (0.40, 1.60) },
12-
{ "gpt-4.1-nano", (0.10, 0.40) },
13-
{ "gpt-4o", (2.50, 10) },
14-
{ "gpt-4o-mini", (0.15, 0.60) },
15-
{ "o3-mini", (1.10, 4.40) },
16-
};
17-
185
protected double PromptTokens { get; set; } = 0;
196
protected double CompletionTokens { get; set; } = 0;
20-
protected double InputCost { get; set; } = 0;
21-
protected double OutputCost { get; set; } = 0;
22-
protected double TotalCost { get; set; } = 0;
237
protected IEnumerable<string> ModelsUsed { get; set; } = [];
248

259
public void Add(string model, long inputTokens, long outputTokens)
2610
{
2711
ModelsUsed = ModelsUsed.Union([model]);
2812
PromptTokens += inputTokens;
2913
CompletionTokens += outputTokens;
30-
SetCost(model);
3114
}
3215

33-
private void SetCost(string model)
16+
public void LogUsage()
3417
{
35-
var oneMillion = 1_000_000;
36-
if (!modelPrices.TryGetValue(model, out (double inputPrice, double outputPrice) value))
37-
{
38-
throw new ArgumentException($"No pricing information found for model '{model}'.");
39-
}
40-
41-
InputCost = PromptTokens / oneMillion * value.inputPrice;
42-
OutputCost = CompletionTokens / oneMillion * value.outputPrice;
43-
}
44-
45-
public void LogCost()
46-
{
47-
var _inputCost = InputCost == 0 ? "?" : InputCost.ToString("F3");
48-
var _outputCost = OutputCost == 0 ? "?" : OutputCost.ToString("F3");
49-
var _totalCost = (InputCost + OutputCost) == 0 ? "?" : (InputCost + OutputCost).ToString("F3");
5018
var models = string.Join(", ", ModelsUsed);
5119

52-
outputHelper.OutputConsole($"[{models}] Usage (cost / tokens):");
53-
outputHelper.OutputConsole($" Input: ${_inputCost} / {PromptTokens}");
54-
outputHelper.OutputConsole($" Output: ${_outputCost} / {CompletionTokens}");
55-
outputHelper.OutputConsole($" Total: ${_totalCost} / {PromptTokens + CompletionTokens}");
20+
outputHelper.OutputConsole("--------------------------------------------------------------------------------");
21+
outputHelper.OutputConsole($"[token usage][{models}] input: {PromptTokens}, output: {CompletionTokens}, total: {PromptTokens + CompletionTokens}");
5622
outputHelper.OutputConsole("--------------------------------------------------------------------------------");
5723
}
5824
}

tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Example/ExampleTool.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public async Task<ExampleServiceResponse> DemonstrateAIService(string userPrompt
315315

316316
var response = await chatClient.CompleteChatAsync(messages, cancellationToken: ct);
317317
tokenUsageHelper.Add(model, response.Value.Usage.InputTokenCount, response.Value.Usage.OutputTokenCount);
318-
tokenUsageHelper.LogCost();
318+
tokenUsageHelper.LogUsage();
319319

320320
return new ExampleServiceResponse
321321
{
@@ -519,7 +519,7 @@ public async Task<DefaultCommandResponse> DemonstrateMicroagentFibonacci(int n,
519519
if (n < 2)
520520
{
521521
SetFailure();
522-
return new DefaultCommandResponse { ResponseError = "--fibonacci must be >= 2 to exercise the micro-agent (trivial cases are disallowed)" };
522+
return new DefaultCommandResponse { ResponseError = "--fibonacci must be >= 2 to run the micro-agent" };
523523
}
524524

525525
var advanceTool = AgentTool<Fibonacci, Fibonacci>.FromFunc(
@@ -551,12 +551,12 @@ public async Task<DefaultCommandResponse> DemonstrateMicroagentFibonacci(int n,
551551

552552
var resultValue = await microagentHostService.RunAgentToCompletion(agent, ct);
553553

554-
tokenUsageHelper.LogCost();
554+
tokenUsageHelper.LogUsage();
555555
return new DefaultCommandResponse { Result = $"Fibonacci({n}) = {resultValue}" };
556556
}
557557
catch (Exception ex)
558558
{
559-
tokenUsageHelper.LogCost();
559+
tokenUsageHelper.LogUsage();
560560
logger.LogError(ex, "Error demonstrating micro-agent Fibonacci for n={n}", n);
561561
SetFailure();
562562
return new DefaultCommandResponse { ResponseError = $"Failed to compute Fibonacci({n}): {ex.Message}" };

tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Pipeline/PipelineAnalysisTool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ public override async Task HandleCommand(InvocationContext ctx, CancellationToke
118118
{
119119
var result = await AnalyzePipelineFailureLogs(project ?? projectFromLink, buildId, [logId], analyzeWithAgent, ct);
120120
ctx.ExitCode = ExitCode;
121-
tokenUsageHelper.LogCost();
121+
tokenUsageHelper.LogUsage();
122122
output.Output(result);
123123
}
124124
else
125125
{
126126
var result = await AnalyzePipeline(project ?? projectFromLink, buildId, analyzeWithAgent, ct);
127127
ctx.ExitCode = ExitCode;
128-
tokenUsageHelper.LogCost();
128+
tokenUsageHelper.LogUsage();
129129
output.Output(result);
130130
}
131131
}

0 commit comments

Comments
 (0)