Skip to content

Commit aed31a0

Browse files
committed
fix: EDIT_CODE model backward compatibility (fixes #1129)
1 parent 3011dba commit aed31a0

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package ee.carlrobert.codegpt.settings.service;
22

33
public enum FeatureType {
4-
CHAT,
5-
CODE_COMPLETION,
6-
AUTO_APPLY,
7-
COMMIT_MESSAGE,
8-
INLINE_EDIT,
9-
NEXT_EDIT,
10-
LOOKUP
11-
}
4+
CHAT,
5+
CODE_COMPLETION,
6+
AUTO_APPLY,
7+
COMMIT_MESSAGE,
8+
INLINE_EDIT,
9+
NEXT_EDIT,
10+
LOOKUP
11+
}

src/main/kotlin/ee/carlrobert/codegpt/completions/CompletionRequestFactory.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package ee.carlrobert.codegpt.completions
22

33
import com.intellij.openapi.components.service
4-
import com.intellij.openapi.fileEditor.FileDocumentManager
54
import com.intellij.openapi.vfs.LocalFileSystem
6-
import com.intellij.openapi.vfs.readText
75
import ee.carlrobert.codegpt.completions.factory.*
86
import ee.carlrobert.codegpt.psistructure.ClassStructureSerializer
97
import ee.carlrobert.codegpt.settings.prompts.CoreActionsState

src/main/kotlin/ee/carlrobert/codegpt/settings/models/ModelRegistry.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class ModelRegistry {
123123
),
124124
FeatureType.INLINE_EDIT to ModelSelection(
125125
ServiceType.PROXYAI,
126-
GPT_5_MINI,
127-
"GPT-5 Mini"
126+
GEMINI_FLASH_2_5,
127+
"Gemini Flash 2.5"
128128
),
129129
FeatureType.LOOKUP to ModelSelection(
130130
ServiceType.PROXYAI,
@@ -202,7 +202,11 @@ class ModelRegistry {
202202
GPT_5_MINI,
203203
"GPT-5 Mini"
204204
),
205-
FeatureType.INLINE_EDIT to ModelSelection(ServiceType.PROXYAI, GPT_5_MINI, "GPT-5 Mini"),
205+
FeatureType.INLINE_EDIT to ModelSelection(
206+
ServiceType.PROXYAI,
207+
GEMINI_FLASH_2_5,
208+
"Gemini Flash 2.5"
209+
),
206210
FeatureType.LOOKUP to ModelSelection(ServiceType.PROXYAI, GPT_5_MINI, "GPT-5 Mini"),
207211
FeatureType.CODE_COMPLETION to ModelSelection(
208212
ServiceType.PROXYAI,

src/main/kotlin/ee/carlrobert/codegpt/settings/models/ModelSettings.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ModelSettings : SimplePersistentStateComponent<ModelSettingsState>(ModelSe
6060

6161
migrateCustomOpenAIModelCodesToIds()
6262
migrateMissingProviderInformation()
63+
migrateEditCodeModel()
6364
notifyIfChanged(oldState, this.state)
6465
}
6566

@@ -113,7 +114,7 @@ class ModelSettings : SimplePersistentStateComponent<ModelSettingsState>(ModelSe
113114
val newModel = getModelFromState(newState, featureType)
114115

115116
if (oldModel != newModel) {
116-
val service = findServiceTypeForModel(featureType, newModel)
117+
val service = getProviderForFeature(featureType) ?: return
117118
notifyModelChange(featureType, newModel, service)
118119
}
119120
}
@@ -123,10 +124,6 @@ class ModelSettings : SimplePersistentStateComponent<ModelSettingsState>(ModelSe
123124
return state.getModelSelection(featureType)?.model
124125
}
125126

126-
private fun findServiceTypeForModel(featureType: FeatureType, modelId: String?): ServiceType {
127-
return ServiceType.CUSTOM_OPENAI
128-
}
129-
130127
private fun migrateMissingProviderInformation() {
131128
FeatureType.entries.forEach { featureType ->
132129
val modelDetailsState = getModelDetailsState(featureType)
@@ -140,6 +137,13 @@ class ModelSettings : SimplePersistentStateComponent<ModelSettingsState>(ModelSe
140137
}
141138
}
142139

140+
private fun migrateEditCodeModel() {
141+
state.modelSelections["EDIT_CODE"]?.let {
142+
state.setModelSelection(FeatureType.INLINE_EDIT, it.model, it.provider!!)
143+
state.modelSelections.remove("EDIT_CODE")
144+
}
145+
}
146+
143147
private fun inferProviderFromModelCode(
144148
featureType: FeatureType,
145149
modelCode: String

src/main/kotlin/ee/carlrobert/codegpt/settings/models/ModelSettingsState.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ee.carlrobert.codegpt.settings.service.FeatureType
55
import ee.carlrobert.codegpt.settings.service.ServiceType
66

77
class ModelSettingsState : BaseState() {
8-
var modelSelections by map<FeatureType, ModelDetailsState>()
8+
var modelSelections by map<String, ModelDetailsState>()
99

1010
init {
1111
if (modelSelections.isEmpty()) {
@@ -17,18 +17,16 @@ class ModelSettingsState : BaseState() {
1717
val registry = ModelRegistry.getInstance()
1818
FeatureType.entries.forEach { featureType ->
1919
val defaultModel = registry.getDefaultModelForFeature(featureType)
20-
if (defaultModel != null) {
21-
setModelSelection(featureType, defaultModel.model, defaultModel.provider)
22-
}
20+
setModelSelection(featureType, defaultModel.model, defaultModel.provider)
2321
}
2422
}
2523

2624
fun getModelSelection(featureType: FeatureType): ModelDetailsState? {
27-
return modelSelections[featureType]
25+
return modelSelections[featureType.name]
2826
}
2927

3028
fun setModelSelection(featureType: FeatureType, model: String?, provider: ServiceType) {
31-
modelSelections[featureType] = ModelDetailsState().apply {
29+
modelSelections[featureType.name] = ModelDetailsState().apply {
3230
this.model = model
3331
this.provider = provider
3432
}

src/test/kotlin/ee/carlrobert/codegpt/settings/models/ModelSettingsTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ModelSettingsTest : IntegrationTest() {
4141
lastNotification.set(NotificationData(FeatureType.COMMIT_MESSAGE, newModel, serviceType, "commitMessage"))
4242
}
4343
override fun inlineEditModelChanged(newModel: String, serviceType: ServiceType) {
44-
lastNotification.set(NotificationData(FeatureType.INLINE_EDIT, newModel, serviceType, "editCode"))
44+
lastNotification.set(NotificationData(FeatureType.INLINE_EDIT, newModel, serviceType, "inlineEdit"))
4545
}
4646
override fun nextEditModelChanged(newModel: String, serviceType: ServiceType) {
4747
lastNotification.set(NotificationData(FeatureType.NEXT_EDIT, newModel, serviceType, "nextEdit"))
@@ -129,7 +129,7 @@ class ModelSettingsTest : IntegrationTest() {
129129
}
130130

131131
fun `test setModelWithProvider with next edit triggers next edit notification`() {
132-
modelSettings.state.modelSelections.remove(FeatureType.NEXT_EDIT)
132+
modelSettings.state.modelSelections.remove("NEXT_EDIT")
133133
lastNotification.set(null)
134134

135135
modelSettings.setModelWithProvider(FeatureType.NEXT_EDIT, "zeta", ServiceType.PROXYAI)
@@ -204,7 +204,7 @@ class ModelSettingsTest : IntegrationTest() {
204204
val detailsState = ModelDetailsState()
205205
detailsState.model = "gpt-4o"
206206
detailsState.provider = null
207-
state.modelSelections[FeatureType.CHAT] = detailsState
207+
state.modelSelections["CHAT"] = detailsState
208208

209209
modelSettings.loadState(state)
210210

@@ -217,7 +217,7 @@ class ModelSettingsTest : IntegrationTest() {
217217
val detailsState = ModelDetailsState()
218218
detailsState.model = "unknown-model"
219219
detailsState.provider = null
220-
state.modelSelections[FeatureType.CHAT] = detailsState
220+
state.modelSelections["CHAT"] = detailsState
221221

222222
modelSettings.loadState(state)
223223

0 commit comments

Comments
 (0)