Skip to content

Commit 5614648

Browse files
authored
Merge pull request #1964 from Kilo-Org/christiaan/costPerRequest
Show cost per request in addition to cost per M
2 parents 471ce3c + 6b0dfbf commit 5614648

File tree

25 files changed

+56
-57
lines changed

25 files changed

+56
-57
lines changed

.changeset/unlucky-knives-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"kilo-code": patch
3+
---
4+
5+
The Kilo Code API Provider settings now also shows the average cost per request in addition to the average cost per million tokens for a particular model.

webview-ui/src/components/kilocode/settings/KiloModelInfoView.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type ModelInfo, type ProviderSettings } from "@roo-code/types"
2-
import { formatPrice } from "@src/utils/formatPrice"
32
import { useAppTranslation } from "@src/i18n/TranslationContext"
43
import { ModelDescriptionMarkdown } from "../../settings/ModelDescriptionMarkdown"
54
import { ModelInfoSupportsItem } from "@/components/settings/ModelInfoView"
@@ -10,6 +9,21 @@ import { getKiloBaseUriFromToken } from "@roo/kilocode/token"
109
import { telemetryClient } from "@/utils/TelemetryClient"
1110
import { useModelProviders } from "@/components/ui/hooks/useSelectedModel"
1211

12+
type ModelStats = {
13+
model: string
14+
cost?: Intl.StringNumericLiteral
15+
costPerRequest?: Intl.StringNumericLiteral
16+
}
17+
18+
export const formatPrice = (price: number | Intl.StringNumericLiteral, digits: number = 2) => {
19+
return new Intl.NumberFormat("en-US", {
20+
style: "currency",
21+
currency: "USD",
22+
minimumFractionDigits: digits,
23+
maximumFractionDigits: digits,
24+
}).format(price)
25+
}
26+
1327
const PricingTable = ({ providers }: { providers: (ModelInfo & { label: string })[] }) => {
1428
const { t } = useAppTranslation()
1529
const thClass = "text-left px-3 py-2 font-medium text-vscode-foreground whitespace-nowrap"
@@ -75,7 +89,7 @@ export const KiloModelInfoView = ({
7589
}) => {
7690
const { t } = useAppTranslation()
7791
const providers = Object.values(useModelProviders(modelId, apiConfiguration).data ?? {})
78-
const { data: modelStats } = useQuery<{ model: string; cost: Intl.StringNumericLiteral | number }[]>({
92+
const { data: modelStats } = useQuery<ModelStats[]>({
7993
queryKey: ["modelstats"],
8094
queryFn: async () => {
8195
try {
@@ -90,7 +104,7 @@ export const KiloModelInfoView = ({
90104
}
91105
},
92106
})
93-
const averageCost = modelStats?.find((ms) => ms.model === modelId)?.cost
107+
const stats = modelStats?.find((ms) => ms.model === modelId)
94108

95109
return (
96110
<>
@@ -124,15 +138,17 @@ export const KiloModelInfoView = ({
124138
<span className="font-medium">{t("settings:modelInfo.maxOutput")}:</span>{" "}
125139
{model.maxTokens?.toLocaleString() ?? 0}
126140
</div>
127-
{typeof averageCost !== "undefined" && (
128-
<StandardTooltip content={t("kilocode:settings.modelInfo.averageKiloCodeCostDescription")}>
129-
<div>
130-
<span className="font-medium">{t("kilocode:settings.modelInfo.averageKiloCodeCost")}:</span>{" "}
131-
{formatPrice(averageCost)} / M tokens
132-
</div>
133-
</StandardTooltip>
134-
)}
135141
</div>
142+
{stats && stats.cost && stats.costPerRequest && model.inputPrice && model.outputPrice && (
143+
<StandardTooltip content={t("kilocode:settings.modelInfo.averageKiloCodeCost")}>
144+
<div className="text-sm text-vscode-descriptionForeground font-medium flex flex-wrap gap-2">
145+
<div className="rounded-full border px-2.5 py-1">{formatPrice(stats.cost)} / M tokens</div>
146+
<div className="rounded-full border px-2.5 py-1">
147+
{formatPrice(stats.costPerRequest, 4)} / request
148+
</div>
149+
</div>
150+
</StandardTooltip>
151+
)}
136152
<Collapsible open={isPricingExpanded} onOpenChange={setIsPricingExpanded}>
137153
<CollapsibleTrigger className="flex items-center gap-1 w-full cursor-pointer hover:opacity-80 mb-2">
138154
<span className={`codicon codicon-chevron-${isPricingExpanded ? "down" : "right"}`}></span>

webview-ui/src/i18n/locales/ar/kilocode.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/ca/kilocode.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/cs/kilocode.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/de/kilocode.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/en/kilocode.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
"modelInfo": {
5454
"contextWindow": "Context window",
5555
"providerBreakdown": "Provider Price and Capability Breakdown",
56-
"averageKiloCodeCost": "Average Kilo Code cost",
57-
"averageKiloCodeCostDescription": "This is the average actual spent for Kilo Code using this model over the last week. It may be lower than the listed price due to prompt cache utilization.",
56+
"averageKiloCodeCost": "This is the average actual spent for Kilo Code using this model over the last week. It may be lower than the listed price due to prompt cache utilization.",
5857
"table": {
5958
"provider": "Provider",
6059
"context": "The endpoint can process this number of tokens (input + output).",

webview-ui/src/i18n/locales/es/kilocode.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/fr/kilocode.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/hi/kilocode.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)