Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit 67e4f0d

Browse files
committed
Merge remote-tracking branch 'origin/main'
# Conflicts: # src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/AppSettingsConfigurable.kt # src/main/resources/messages/MyBundle.properties
2 parents 2befd3c + fb04475 commit 67e4f0d

11 files changed

Lines changed: 98 additions & 23 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ bin/
4040

4141
### Mac OS ###
4242
.DS_Store
43-
/.idea/
43+
/.idea/

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Added
5+
- Add button for verifying Open AI token in settings.
6+
47

58
## [0.4.0] - 2023-03-29
69

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
7676

7777
## Acknowledgements
7878

79-
Inspired by Nutlope's [AICommits](https://github.com/Nutlope/aicommits).
79+
- Inspired by Nutlope's [AICommits](https://github.com/Nutlope/aicommits).
80+
- [openai-kotlin](https://github.com/aallam/openai-kotlin) for OpenAI API client.
8081

8182
## License
8283

gradle.properties

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ platformVersion = 2023.1
1515

1616
# https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
1717
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
18-
platformPlugins = org.jetbrains.kotlin, org.jetbrains.plugins.github
18+
platformPlugins = org.jetbrains.kotlin, org.jetbrains.plugins.github, Git4Idea
1919

2020
# If targeting 2022.3+, Java 17 is required.
2121
javaVersion = 17
2222

2323
# https://github.com/gradle/gradle/releases
24-
gradleVersion = 7.6
24+
gradleVersion = 8.0.2
2525

2626
# Opt-out flag for bundling Kotlin standard library.
2727
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
2828
# suppress inspection "UnusedProperty"
29-
# kotlin.stdlib.default.dependency = false
30-
kotlin.stdlib.default.dependency = false
29+
kotlin.stdlib.default.dependency = false
30+
31+
# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
32+
org.gradle.unsafe.configuration-cache = true
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
4+
networkTimeout=10000
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists

gradlew

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.blarc.ai.commits.intellij.plugin
22

33
import com.aallam.openai.api.BetaOpenAI
44
import com.aallam.openai.api.chat.*
5+
import com.aallam.openai.api.completion.CompletionRequest
56
import com.aallam.openai.api.model.ModelId
67
import com.aallam.openai.client.OpenAI
78
import com.github.blarc.ai.commits.intellij.plugin.settings.AppSettings
@@ -43,4 +44,8 @@ class OpenAIService {
4344
val completion: ChatCompletion = openAI.chatCompletion(chatCompletionRequest)
4445
return completion.choices[0].message!!.content
4546
}
47+
@Throws(Exception::class)
48+
suspend fun verifyToken(token: String){
49+
OpenAI(token).models()
50+
}
4651
}

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

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
11
package com.github.blarc.ai.commits.intellij.plugin.settings
22

3+
import com.aallam.openai.api.exception.OpenAIAPIException
34
import com.github.blarc.ai.commits.intellij.plugin.AICommitsBundle.message
5+
import com.github.blarc.ai.commits.intellij.plugin.OpenAIService
6+
import com.intellij.icons.AllIcons
47
import com.intellij.ide.starters.shared.withValidation
58
import com.intellij.openapi.options.BoundConfigurable
9+
import com.intellij.openapi.progress.runBackgroundableTask
10+
import com.intellij.ui.components.JBLabel
611
import com.intellij.ui.dsl.builder.*
7-
import java.awt.Component
12+
import kotlinx.coroutines.DelicateCoroutinesApi
13+
import kotlinx.coroutines.Dispatchers
14+
import kotlinx.coroutines.GlobalScope
15+
import kotlinx.coroutines.launch
816
import java.util.*
9-
import javax.swing.DefaultListCellRenderer
10-
import javax.swing.JList
17+
import javax.swing.JPasswordField
1118

1219
class AppSettingsConfigurable : BoundConfigurable(message("settings.general.group.title")) {
20+
21+
private val tokenPasswordField = JPasswordField()
22+
private val verifyLabel = JBLabel()
1323
override fun createPanel() = panel {
1424
// OpenAI Token
1525
row {
16-
passwordField()
26+
cell(tokenPasswordField)
1727
.label(message("settings.openAIToken"))
1828
.bindText(
1929
{ AppSettings.instance.getOpenAIToken().orEmpty() },
2030
{ AppSettings.instance.saveOpenAIToken(it) }
2131
)
2232
.align(Align.FILL)
33+
.resizableColumn()
34+
.focused()
35+
button(message("settings.verifyToken")) {
36+
verifyToken()
37+
}.align(AlignX.RIGHT)
2338
}
2439
// Get OpenAI Token
2540
row {
2641
comment(message("settings.openAITokenComment"))
42+
.align(AlignX.LEFT)
43+
cell(verifyLabel)
44+
.align(AlignX.RIGHT)
2745
}
2846

2947
// Prompt to use with OpenAI
@@ -36,7 +54,36 @@ class AppSettingsConfigurable : BoundConfigurable(message("settings.general.grou
3654
)
3755
.align(Align.FILL)
3856
}
57+
}
3958

59+
@OptIn(DelicateCoroutinesApi::class)
60+
private fun verifyToken() {
61+
runBackgroundableTask(message("settings.verify.running")) {
62+
if (tokenPasswordField.password.isEmpty()) {
63+
verifyLabel.icon = AllIcons.General.InspectionsError
64+
verifyLabel.text = message("settings.verify.token-is-empty")
65+
} else {
66+
verifyLabel.icon = AllIcons.General.InlineRefreshHover
67+
verifyLabel.text = message("settings.verify.running")
68+
69+
GlobalScope.launch(Dispatchers.IO) {
70+
try {
71+
println(String(tokenPasswordField.password))
72+
OpenAIService.instance.verifyToken(String(tokenPasswordField.password))
73+
verifyLabel.text = message("settings.verify.valid")
74+
verifyLabel.icon = AllIcons.General.InspectionsOK
75+
}
76+
catch (e: OpenAIAPIException) {
77+
verifyLabel.text = message("settings.verify.invalid", e.statusCode)
78+
verifyLabel.icon = AllIcons.General.InspectionsError
79+
}
80+
catch (e: Exception) {
81+
verifyLabel.text = message("settings.verify.invalid", "Unknown")
82+
verifyLabel.icon = AllIcons.General.InspectionsError
83+
}
84+
}
85+
}
86+
}
4087

4188
}
4289
}

src/main/resources/META-INF/plugin.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
<!-- Product and plugin compatibility requirements.
2828
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html -->
2929
<depends>com.intellij.modules.platform</depends>
30-
<depends>org.jetbrains.plugins.yaml</depends>
3130
<depends>Git4Idea</depends>
3231

3332
<applicationListeners>

0 commit comments

Comments
 (0)