Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/api/providers/__tests__/gemini.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ describe("GeminiHandler", () => {
const modelInfo = invalidHandler.getModel()
expect(modelInfo.id).toBe(geminiDefaultModelId) // Default model
})

it("should exclude apply_diff and include edit in tool preferences", () => {
const modelInfo = handler.getModel()
expect(modelInfo.info.excludedTools).toContain("apply_diff")
expect(modelInfo.info.includedTools).toContain("edit")
})

it("should not duplicate tool entries if already present", () => {
const modelInfo = handler.getModel()
const excludedCount = modelInfo.info.excludedTools!.filter((t: string) => t === "apply_diff").length
const includedCount = modelInfo.info.includedTools!.filter((t: string) => t === "edit").length
expect(excludedCount).toBe(1)
expect(includedCount).toBe(1)
})
})

describe("calculateCost", () => {
Expand Down
26 changes: 26 additions & 0 deletions src/api/providers/__tests__/vertex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,31 @@ describe("VertexHandler", () => {
expect(modelInfo.info.maxTokens).toBe(8192)
expect(modelInfo.info.contextWindow).toBe(1048576)
})

it("should exclude apply_diff and include edit in tool preferences", () => {
const testHandler = new VertexHandler({
apiModelId: "gemini-2.0-flash-001",
vertexProjectId: "test-project",
vertexRegion: "us-central1",
})

const modelInfo = testHandler.getModel()
expect(modelInfo.info.excludedTools).toContain("apply_diff")
expect(modelInfo.info.includedTools).toContain("edit")
})

it("should not duplicate tool entries if already present", () => {
const testHandler = new VertexHandler({
apiModelId: "gemini-2.0-flash-001",
vertexProjectId: "test-project",
vertexRegion: "us-central1",
})

const modelInfo = testHandler.getModel()
const excludedCount = modelInfo.info.excludedTools!.filter((t: string) => t === "apply_diff").length
const includedCount = modelInfo.info.includedTools!.filter((t: string) => t === "edit").length
expect(excludedCount).toBe(1)
expect(includedCount).toBe(1)
})
})
})
7 changes: 7 additions & 0 deletions src/api/providers/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
defaultTemperature: info.defaultTemperature ?? 1,
})

// Gemini models perform better with the edit tool instead of apply_diff.
info = {
...info,
excludedTools: [...new Set([...(info.excludedTools || []), "apply_diff"])],
includedTools: [...new Set([...(info.includedTools || []), "edit"])],
}

// The `:thinking` suffix indicates that the model is a "Hybrid"
// reasoning model and that reasoning is required to be enabled.
// The actual model ID honored by Gemini's API does not have this
Expand Down
9 changes: 8 additions & 1 deletion src/api/providers/vertex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class VertexHandler extends GeminiHandler implements SingleCompletionHand
override getModel() {
const modelId = this.options.apiModelId
let id = modelId && modelId in vertexModels ? (modelId as VertexModelId) : vertexDefaultModelId
const info: ModelInfo = vertexModels[id]
let info: ModelInfo = vertexModels[id]
const params = getModelParams({
format: "gemini",
modelId: id,
Expand All @@ -24,6 +24,13 @@ export class VertexHandler extends GeminiHandler implements SingleCompletionHand
defaultTemperature: info.defaultTemperature ?? 1,
})

// Vertex Gemini models perform better with the edit tool instead of apply_diff.
info = {
...info,
excludedTools: [...new Set([...(info.excludedTools || []), "apply_diff"])],
includedTools: [...new Set([...(info.includedTools || []), "edit"])],
}

// The `:thinking` suffix indicates that the model is a "Hybrid"
// reasoning model and that reasoning is required to be enabled.
// The actual model ID honored by Gemini's API does not have this
Expand Down
Loading