Skip to content

Commit 9a1bc43

Browse files
committed
fix: remove duplicated function and tested the functionality in debug mode
1 parent 6530965 commit 9a1bc43

File tree

5 files changed

+98
-202
lines changed

5 files changed

+98
-202
lines changed

packages/types/src/providers/gemini.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,53 @@ export const legacyGeminiModels = {
299299
outputPrice: 0,
300300
},
301301
} as const satisfies Record<string, ModelInfo>
302+
303+
/**
304+
* Maps legacy Gemini model IDs to current supported models
305+
*/
306+
export function mapLegacyGeminiModel(modelId: string): GeminiModelId {
307+
if (modelId in geminiModels) {
308+
return modelId as GeminiModelId
309+
}
310+
311+
if (modelId in legacyGeminiModels) {
312+
if (modelId.startsWith("gemini-2.5-pro-preview-")) {
313+
return "gemini-2.5-pro"
314+
}
315+
316+
if (modelId.startsWith("gemini-1.5-pro-")) {
317+
return geminiDefaultModelId
318+
}
319+
320+
if (modelId.startsWith("gemini-1.5-flash-")) {
321+
return geminiDefaultModelId
322+
}
323+
324+
if (modelId.startsWith("gemini-2.5-pro-exp-")) {
325+
return "gemini-2.5-pro"
326+
}
327+
328+
if (modelId === "gemini-exp-1206") {
329+
return geminiDefaultModelId
330+
}
331+
332+
if (modelId === "gemini-2.0-pro-exp-02-05") {
333+
return "gemini-2.5-pro"
334+
}
335+
336+
if (
337+
modelId === "gemini-2.0-flash-thinking-exp-1219" ||
338+
modelId === "gemini-2.0-flash-thinking-exp-01-21" ||
339+
modelId === "gemini-2.5-flash-preview-04-17" ||
340+
modelId === "gemini-2.5-flash-preview-04-17:thinking"
341+
) {
342+
return "gemini-2.5-flash-preview-05-20"
343+
}
344+
345+
if (modelId === "gemini-2.0-flash-exp") {
346+
return geminiDefaultModelId
347+
}
348+
}
349+
350+
return geminiDefaultModelId
351+
}

packages/types/src/providers/vertex.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,45 @@ export const legacyVertexModels = {
321321
outputPrice: 0.6,
322322
},
323323
} as const satisfies Record<string, ModelInfo>
324+
325+
/**
326+
* Maps legacy Vertex model IDs to current supported models
327+
*/
328+
export function mapLegacyVertexModel(modelId: string): VertexModelId {
329+
if (modelId in vertexModels) {
330+
return modelId as VertexModelId
331+
}
332+
333+
if (modelId in legacyVertexModels) {
334+
if (modelId.startsWith("gemini-2.5-pro-preview-")) {
335+
return "gemini-2.5-pro"
336+
}
337+
338+
if (modelId.startsWith("gemini-1.5-pro-")) {
339+
return "gemini-2.0-flash-001"
340+
}
341+
342+
if (modelId.startsWith("gemini-1.5-flash-")) {
343+
return "gemini-2.0-flash-001"
344+
}
345+
346+
if (modelId.startsWith("gemini-2.5-pro-exp-")) {
347+
return "gemini-2.5-pro"
348+
}
349+
350+
if (modelId === "gemini-2.0-pro-exp-02-05") {
351+
return "gemini-2.5-pro"
352+
}
353+
354+
if (
355+
modelId === "gemini-2.0-flash-thinking-exp-1219" ||
356+
modelId === "gemini-2.0-flash-thinking-exp-01-21" ||
357+
modelId === "gemini-2.5-flash-preview-04-17" ||
358+
modelId === "gemini-2.5-flash-preview-04-17:thinking"
359+
) {
360+
return "gemini-2.5-flash-preview-05-20"
361+
}
362+
}
363+
364+
return vertexDefaultModelId
365+
}

src/api/providers/gemini.ts

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ import {
88
} from "@google/genai"
99
import type { JWTInput } from "google-auth-library"
1010

11-
import {
12-
type ModelInfo,
13-
type GeminiModelId,
14-
geminiDefaultModelId,
15-
geminiModels,
16-
legacyGeminiModels,
17-
} from "@roo-code/types"
11+
import { type ModelInfo, geminiDefaultModelId, geminiModels, mapLegacyGeminiModel } from "@roo-code/types"
1812

1913
import type { ApiHandlerOptions } from "../../shared/api"
2014
import { safeJsonParse } from "../../shared/safeJsonParse"
@@ -36,56 +30,6 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
3630

3731
private client: GoogleGenAI
3832

39-
/**
40-
* Maps legacy Gemini model IDs to current supported models
41-
*/
42-
private mapLegacyGeminiModel(modelId: string): GeminiModelId {
43-
if (modelId in geminiModels) {
44-
return modelId as GeminiModelId
45-
}
46-
47-
if (modelId in legacyGeminiModels) {
48-
if (modelId.startsWith("gemini-2.5-pro-preview-")) {
49-
return "gemini-2.5-pro"
50-
}
51-
52-
if (modelId.startsWith("gemini-1.5-pro-")) {
53-
return geminiDefaultModelId
54-
}
55-
56-
if (modelId.startsWith("gemini-1.5-flash-")) {
57-
return geminiDefaultModelId
58-
}
59-
60-
if (modelId.startsWith("gemini-2.5-pro-exp-")) {
61-
return "gemini-2.5-pro"
62-
}
63-
64-
if (modelId === "gemini-exp-1206") {
65-
return geminiDefaultModelId
66-
}
67-
68-
if (modelId === "gemini-2.0-pro-exp-02-05") {
69-
return "gemini-2.5-pro"
70-
}
71-
72-
if (
73-
modelId === "gemini-2.0-flash-thinking-exp-1219" ||
74-
modelId === "gemini-2.0-flash-thinking-exp-01-21" ||
75-
modelId === "gemini-2.5-flash-preview-04-17" ||
76-
modelId === "gemini-2.5-flash-preview-04-17:thinking"
77-
) {
78-
return "gemini-2.5-flash-preview-05-20"
79-
}
80-
81-
if (modelId === "gemini-2.0-flash-exp") {
82-
return geminiDefaultModelId
83-
}
84-
}
85-
86-
return geminiDefaultModelId
87-
}
88-
8933
constructor({ isVertex, ...options }: GeminiHandlerOptions) {
9034
super()
9135

@@ -220,7 +164,7 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
220164

221165
override getModel() {
222166
const modelId = this.options.apiModelId
223-
let id = modelId ? this.mapLegacyGeminiModel(modelId) : geminiDefaultModelId
167+
let id = modelId ? mapLegacyGeminiModel(modelId) : geminiDefaultModelId
224168

225169
if (modelId && modelId !== id) {
226170
this.options.apiModelId = id

src/api/providers/vertex.ts

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
type ModelInfo,
3-
type VertexModelId,
4-
vertexDefaultModelId,
5-
vertexModels,
6-
legacyVertexModels,
7-
} from "@roo-code/types"
1+
import { type ModelInfo, vertexDefaultModelId, vertexModels, mapLegacyVertexModel } from "@roo-code/types"
82

93
import type { ApiHandlerOptions } from "../../shared/api"
104

@@ -18,51 +12,9 @@ export class VertexHandler extends GeminiHandler implements SingleCompletionHand
1812
super({ ...options, isVertex: true })
1913
}
2014

21-
/**
22-
* Maps legacy Vertex model IDs to current supported models
23-
*/
24-
private mapLegacyVertexModel(modelId: string): VertexModelId {
25-
if (modelId in vertexModels) {
26-
return modelId as VertexModelId
27-
}
28-
29-
if (modelId in legacyVertexModels) {
30-
if (modelId.startsWith("gemini-2.5-pro-preview-")) {
31-
return "gemini-2.5-pro"
32-
}
33-
34-
if (modelId.startsWith("gemini-1.5-pro-")) {
35-
return "gemini-2.0-flash-001"
36-
}
37-
38-
if (modelId.startsWith("gemini-1.5-flash-")) {
39-
return "gemini-2.0-flash-001"
40-
}
41-
42-
if (modelId.startsWith("gemini-2.5-pro-exp-")) {
43-
return "gemini-2.5-pro"
44-
}
45-
46-
if (modelId === "gemini-2.0-pro-exp-02-05") {
47-
return "gemini-2.5-pro"
48-
}
49-
50-
if (
51-
modelId === "gemini-2.0-flash-thinking-exp-1219" ||
52-
modelId === "gemini-2.0-flash-thinking-exp-01-21" ||
53-
modelId === "gemini-2.5-flash-preview-04-17" ||
54-
modelId === "gemini-2.5-flash-preview-04-17:thinking"
55-
) {
56-
return "gemini-2.5-flash-preview-05-20"
57-
}
58-
}
59-
60-
return vertexDefaultModelId
61-
}
62-
6315
override getModel() {
6416
const modelId = this.options.apiModelId
65-
let id = modelId ? this.mapLegacyVertexModel(modelId) : vertexDefaultModelId
17+
let id = modelId ? mapLegacyVertexModel(modelId) : vertexDefaultModelId
6618

6719
if (modelId && id && modelId !== id) {
6820
this.options.apiModelId = id

webview-ui/src/components/ui/hooks/useSelectedModel.ts

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ import {
1212
moonshotModels,
1313
geminiDefaultModelId,
1414
geminiModels,
15-
legacyGeminiModels,
1615
mistralDefaultModelId,
1716
mistralModels,
1817
openAiModelInfoSaneDefaults,
1918
openAiNativeDefaultModelId,
2019
openAiNativeModels,
2120
vertexDefaultModelId,
2221
vertexModels,
23-
legacyVertexModels,
2422
xaiDefaultModelId,
2523
xaiModels,
2624
groqModels,
@@ -40,6 +38,8 @@ import {
4038
sambaNovaDefaultModelId,
4139
doubaoModels,
4240
doubaoDefaultModelId,
41+
mapLegacyGeminiModel,
42+
mapLegacyVertexModel,
4343
} from "@roo-code/types"
4444

4545
import type { ModelRecord, RouterModels } from "@roo/api"
@@ -48,98 +48,6 @@ import { useRouterModels } from "./useRouterModels"
4848
import { useOpenRouterModelProviders } from "./useOpenRouterModelProviders"
4949
import { useLmStudioModels } from "./useLmStudioModels"
5050

51-
/**
52-
* Maps legacy Gemini model IDs to current supported models
53-
*/
54-
function mapLegacyGeminiModel(modelId: string): string {
55-
if (modelId in geminiModels) {
56-
return modelId
57-
}
58-
59-
if (modelId in legacyGeminiModels) {
60-
if (modelId.startsWith("gemini-2.5-pro-preview-")) {
61-
return "gemini-2.5-pro"
62-
}
63-
64-
if (modelId.startsWith("gemini-1.5-pro-")) {
65-
return geminiDefaultModelId
66-
}
67-
68-
if (modelId.startsWith("gemini-1.5-flash-")) {
69-
return geminiDefaultModelId
70-
}
71-
72-
if (modelId.startsWith("gemini-2.5-pro-exp-")) {
73-
return "gemini-2.5-pro"
74-
}
75-
76-
if (modelId === "gemini-exp-1206") {
77-
return geminiDefaultModelId
78-
}
79-
80-
if (modelId === "gemini-2.0-pro-exp-02-05") {
81-
return "gemini-2.5-pro"
82-
}
83-
84-
if (
85-
modelId === "gemini-2.0-flash-thinking-exp-1219" ||
86-
modelId === "gemini-2.0-flash-thinking-exp-01-21" ||
87-
modelId === "gemini-2.5-flash-preview-04-17" ||
88-
modelId === "gemini-2.5-flash-preview-04-17:thinking"
89-
) {
90-
return "gemini-2.5-flash-preview-05-20"
91-
}
92-
93-
if (modelId === "gemini-2.0-flash-exp") {
94-
return geminiDefaultModelId
95-
}
96-
}
97-
98-
return geminiDefaultModelId
99-
}
100-
101-
/**
102-
* Maps legacy Vertex model IDs to current supported models
103-
*/
104-
function mapLegacyVertexModel(modelId: string): string {
105-
if (modelId in vertexModels) {
106-
return modelId
107-
}
108-
109-
if (modelId in legacyVertexModels) {
110-
if (modelId.startsWith("gemini-2.5-pro-preview-")) {
111-
return "gemini-2.5-pro"
112-
}
113-
114-
if (modelId.startsWith("gemini-1.5-pro-")) {
115-
return "gemini-2.0-flash-001"
116-
}
117-
118-
if (modelId.startsWith("gemini-1.5-flash-")) {
119-
return "gemini-2.0-flash-001"
120-
}
121-
122-
if (modelId.startsWith("gemini-2.5-pro-exp-")) {
123-
return "gemini-2.5-pro"
124-
}
125-
126-
if (modelId === "gemini-2.0-pro-exp-02-05") {
127-
return "gemini-2.5-pro"
128-
}
129-
130-
if (
131-
modelId === "gemini-2.0-flash-thinking-exp-1219" ||
132-
modelId === "gemini-2.0-flash-thinking-exp-01-21" ||
133-
modelId === "gemini-2.5-flash-preview-04-17" ||
134-
modelId === "gemini-2.5-flash-preview-04-17:thinking"
135-
) {
136-
return "gemini-2.5-flash-preview-05-20"
137-
}
138-
}
139-
140-
return vertexDefaultModelId
141-
}
142-
14351
export const useSelectedModel = (apiConfiguration?: ProviderSettings) => {
14452
const provider = apiConfiguration?.apiProvider || "anthropic"
14553
const openRouterModelId = provider === "openrouter" ? apiConfiguration?.openRouterModelId : undefined

0 commit comments

Comments
 (0)