Skip to content

Commit fdfc6c2

Browse files
committed
refactor: remove jtokkit dependency
Do not check if prompt is too large, but let OpenAI API do the validation, because we don't have max tokens for all models.
1 parent 48abd39 commit fdfc6c2

File tree

2 files changed

+1
-16
lines changed

2 files changed

+1
-16
lines changed

build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,4 @@ dependencies {
114114
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
115115
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
116116
}
117-
118-
implementation("com.knuddels:jtokkit:0.1.0")
119117
}

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/AICommitAction.kt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import com.intellij.openapi.project.Project
1414
import com.intellij.openapi.vcs.VcsDataKeys
1515
import com.intellij.openapi.vcs.changes.Change
1616
import com.intellij.vcs.commit.AbstractCommitWorkflowHandler
17-
import com.knuddels.jtokkit.Encodings
18-
import com.knuddels.jtokkit.api.EncodingType
1917
import git4idea.repo.GitRepositoryManager
2018
import kotlinx.coroutines.Dispatchers
2119
import kotlinx.coroutines.runBlocking
@@ -42,18 +40,13 @@ class AICommitAction : AnAction(), DumbAware {
4240
return@runBackgroundableTask
4341
}
4442

45-
val prompt = AppSettings.instance.getPrompt(diff)
46-
if (isPromptTooLarge(prompt)) {
47-
sendNotification(Notification.promptTooLarge())
48-
return@runBackgroundableTask
49-
}
50-
5143
if (commitMessage == null) {
5244
sendNotification(Notification.noCommitMessage())
5345
return@runBackgroundableTask
5446
}
5547

5648
val openAIService = OpenAIService.instance
49+
val prompt = AppSettings.instance.getPrompt(diff)
5750
runBlocking(Dispatchers.Main) {
5851
try {
5952
val generatedCommitMessage = openAIService.generateCommitMessage(prompt, 1)
@@ -105,10 +98,4 @@ class AICommitAction : AnAction(), DumbAware {
10598
}
10699
.joinToString("\n")
107100
}
108-
109-
private fun isPromptTooLarge(prompt: String): Boolean {
110-
val registry = Encodings.newDefaultEncodingRegistry()
111-
val encoding = registry.getEncoding(EncodingType.CL100K_BASE)
112-
return encoding.countTokens(prompt) > 4000
113-
}
114101
}

0 commit comments

Comments
 (0)