Skip to content

Commit 59538d1

Browse files
Improve logic for Gemini free request limits
Refactor the handling of Gemini free request limits (RPM) to be data-driven instead of hardcoded in the UI. Limits are now defined per-model within `geminiModels` in `src/shared/api.ts` using the new `freeRequestsRpm` property in the `ModelInfo` schema. This centralizes the configuration logic, enhancing maintainability and flexibility to support varying limits across different Gemini models, resolving the previous inflexibility where limits were determined by string matching in `ModelInfoView`.
1 parent 44ad7b6 commit 59538d1

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

src/exports/roo-code.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type ProviderSettings = {
3737
outputPrice?: number | undefined
3838
cacheWritesPrice?: number | undefined
3939
cacheReadsPrice?: number | undefined
40+
freeRequestsRpm?: number | undefined
4041
description?: string | undefined
4142
reasoningEffort?: ("low" | "medium" | "high") | undefined
4243
thinking?: boolean | undefined
@@ -59,6 +60,7 @@ type ProviderSettings = {
5960
outputPrice?: number | undefined
6061
cacheWritesPrice?: number | undefined
6162
cacheReadsPrice?: number | undefined
63+
freeRequestsRpm?: number | undefined
6264
description?: string | undefined
6365
reasoningEffort?: ("low" | "medium" | "high") | undefined
6466
thinking?: boolean | undefined
@@ -99,6 +101,7 @@ type ProviderSettings = {
99101
outputPrice?: number | undefined
100102
cacheWritesPrice?: number | undefined
101103
cacheReadsPrice?: number | undefined
104+
freeRequestsRpm?: number | undefined
102105
description?: string | undefined
103106
reasoningEffort?: ("low" | "medium" | "high") | undefined
104107
thinking?: boolean | undefined
@@ -144,6 +147,7 @@ type ProviderSettings = {
144147
outputPrice?: number | undefined
145148
cacheWritesPrice?: number | undefined
146149
cacheReadsPrice?: number | undefined
150+
freeRequestsRpm?: number | undefined
147151
description?: string | undefined
148152
reasoningEffort?: ("low" | "medium" | "high") | undefined
149153
thinking?: boolean | undefined
@@ -165,6 +169,7 @@ type ProviderSettings = {
165169
outputPrice?: number | undefined
166170
cacheWritesPrice?: number | undefined
167171
cacheReadsPrice?: number | undefined
172+
freeRequestsRpm?: number | undefined
168173
description?: string | undefined
169174
reasoningEffort?: ("low" | "medium" | "high") | undefined
170175
thinking?: boolean | undefined

src/exports/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type ProviderSettings = {
3838
outputPrice?: number | undefined
3939
cacheWritesPrice?: number | undefined
4040
cacheReadsPrice?: number | undefined
41+
freeRequestsRpm?: number | undefined
4142
description?: string | undefined
4243
reasoningEffort?: ("low" | "medium" | "high") | undefined
4344
thinking?: boolean | undefined
@@ -60,6 +61,7 @@ type ProviderSettings = {
6061
outputPrice?: number | undefined
6162
cacheWritesPrice?: number | undefined
6263
cacheReadsPrice?: number | undefined
64+
freeRequestsRpm?: number | undefined
6365
description?: string | undefined
6466
reasoningEffort?: ("low" | "medium" | "high") | undefined
6567
thinking?: boolean | undefined
@@ -100,6 +102,7 @@ type ProviderSettings = {
100102
outputPrice?: number | undefined
101103
cacheWritesPrice?: number | undefined
102104
cacheReadsPrice?: number | undefined
105+
freeRequestsRpm?: number | undefined
103106
description?: string | undefined
104107
reasoningEffort?: ("low" | "medium" | "high") | undefined
105108
thinking?: boolean | undefined
@@ -145,6 +148,7 @@ type ProviderSettings = {
145148
outputPrice?: number | undefined
146149
cacheWritesPrice?: number | undefined
147150
cacheReadsPrice?: number | undefined
151+
freeRequestsRpm?: number | undefined
148152
description?: string | undefined
149153
reasoningEffort?: ("low" | "medium" | "high") | undefined
150154
thinking?: boolean | undefined
@@ -166,6 +170,7 @@ type ProviderSettings = {
166170
outputPrice?: number | undefined
167171
cacheWritesPrice?: number | undefined
168172
cacheReadsPrice?: number | undefined
173+
freeRequestsRpm?: number | undefined
169174
description?: string | undefined
170175
reasoningEffort?: ("low" | "medium" | "high") | undefined
171176
thinking?: boolean | undefined

src/schemas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export const modelInfoSchema = z.object({
109109
outputPrice: z.number().optional(),
110110
cacheWritesPrice: z.number().optional(),
111111
cacheReadsPrice: z.number().optional(),
112+
freeRequestsRpm: z.number().optional(),
112113
description: z.string().optional(),
113114
reasoningEffort: z.enum(["low", "medium", "high"]).optional(),
114115
thinking: z.boolean().optional(),

src/shared/api.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ export const geminiModels = {
628628
supportsPromptCache: false,
629629
inputPrice: 0,
630630
outputPrice: 0,
631+
freeRequestsRpm: 5,
631632
},
632633
"gemini-2.5-pro-preview-03-25": {
633634
maxTokens: 65_535,
@@ -644,6 +645,7 @@ export const geminiModels = {
644645
supportsPromptCache: false,
645646
inputPrice: 0,
646647
outputPrice: 0,
648+
freeRequestsRpm: 15,
647649
},
648650
"gemini-2.0-flash-lite-preview-02-05": {
649651
maxTokens: 8192,
@@ -652,6 +654,7 @@ export const geminiModels = {
652654
supportsPromptCache: false,
653655
inputPrice: 0,
654656
outputPrice: 0,
657+
freeRequestsRpm: 30,
655658
},
656659
"gemini-2.0-pro-exp-02-05": {
657660
maxTokens: 8192,
@@ -660,6 +663,7 @@ export const geminiModels = {
660663
supportsPromptCache: false,
661664
inputPrice: 0,
662665
outputPrice: 0,
666+
freeRequestsRpm: 5,
663667
},
664668
"gemini-2.0-flash-thinking-exp-01-21": {
665669
maxTokens: 65_536,
@@ -668,6 +672,7 @@ export const geminiModels = {
668672
supportsPromptCache: false,
669673
inputPrice: 0,
670674
outputPrice: 0,
675+
freeRequestsRpm: 10,
671676
},
672677
"gemini-2.0-flash-thinking-exp-1219": {
673678
maxTokens: 8192,
@@ -676,6 +681,7 @@ export const geminiModels = {
676681
supportsPromptCache: false,
677682
inputPrice: 0,
678683
outputPrice: 0,
684+
freeRequestsRpm: 10,
679685
},
680686
"gemini-2.0-flash-exp": {
681687
maxTokens: 8192,
@@ -684,6 +690,7 @@ export const geminiModels = {
684690
supportsPromptCache: false,
685691
inputPrice: 0,
686692
outputPrice: 0,
693+
freeRequestsRpm: 10,
687694
},
688695
"gemini-1.5-flash-002": {
689696
maxTokens: 8192,
@@ -692,6 +699,7 @@ export const geminiModels = {
692699
supportsPromptCache: false,
693700
inputPrice: 0,
694701
outputPrice: 0,
702+
freeRequestsRpm: 15,
695703
},
696704
"gemini-1.5-flash-exp-0827": {
697705
maxTokens: 8192,
@@ -700,6 +708,7 @@ export const geminiModels = {
700708
supportsPromptCache: false,
701709
inputPrice: 0,
702710
outputPrice: 0,
711+
freeRequestsRpm: 15,
703712
},
704713
"gemini-1.5-flash-8b-exp-0827": {
705714
maxTokens: 8192,
@@ -708,6 +717,7 @@ export const geminiModels = {
708717
supportsPromptCache: false,
709718
inputPrice: 0,
710719
outputPrice: 0,
720+
freeRequestsRpm: 15,
711721
},
712722
"gemini-1.5-pro-002": {
713723
maxTokens: 8192,
@@ -716,6 +726,7 @@ export const geminiModels = {
716726
supportsPromptCache: false,
717727
inputPrice: 0,
718728
outputPrice: 0,
729+
freeRequestsRpm: 2,
719730
},
720731
"gemini-1.5-pro-exp-0827": {
721732
maxTokens: 8192,
@@ -724,6 +735,7 @@ export const geminiModels = {
724735
supportsPromptCache: false,
725736
inputPrice: 0,
726737
outputPrice: 0,
738+
freeRequestsRpm: 2,
727739
},
728740
"gemini-exp-1206": {
729741
maxTokens: 8192,
@@ -732,6 +744,7 @@ export const geminiModels = {
732744
supportsPromptCache: false,
733745
inputPrice: 0,
734746
outputPrice: 0,
747+
freeRequestsRpm: 5,
735748
},
736749
} as const satisfies Record<string, ModelInfo>
737750

webview-ui/src/components/settings/ModelInfoView.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,16 @@ export const ModelInfoView = ({
7777
<span className="italic">
7878
{selectedModelId === "gemini-2.5-pro-preview-03-25"
7979
? t("settings:modelInfo.gemini.billingEstimate")
80-
: t("settings:modelInfo.gemini.freeRequests", {
81-
count: selectedModelId && selectedModelId.includes("flash") ? 15 : 2,
82-
})}{" "}
83-
<VSCodeLink href="https://ai.google.dev/pricing" className="text-sm">
84-
{t("settings:modelInfo.gemini.pricingDetails")}
85-
</VSCodeLink>
80+
: modelInfo.freeRequestsRpm && modelInfo.freeRequestsRpm > 0
81+
? t("settings:modelInfo.gemini.freeRequests", {
82+
count: modelInfo.freeRequestsRpm,
83+
})
84+
: null}{" "}
85+
{(selectedModelId === "gemini-2.5-pro-preview-03-25" || (modelInfo.freeRequestsRpm && modelInfo.freeRequestsRpm > 0)) && (
86+
<VSCodeLink href="https://ai.google.dev/pricing" className="text-sm">
87+
{t("settings:modelInfo.gemini.pricingDetails")}
88+
</VSCodeLink>
89+
)}
8690
</span>
8791
),
8892
].filter(Boolean)

0 commit comments

Comments
 (0)