Skip to content

Commit b2583b4

Browse files
authored
Merge pull request #31 from devchat-ai/bug-fix
Bug fix
2 parents a7ea994 + 1cb6e78 commit b2583b4

9 files changed

Lines changed: 53 additions & 79 deletions

File tree

.idea/vcs.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "ai.devchat"
9-
version = "0.0.1"
9+
version = "0.0.2"
1010

1111
repositories {
1212
mavenCentral()

src/main/kotlin/ai/devchat/cli/DevChatConfig.kt

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,22 @@ import com.fasterxml.jackson.databind.ObjectMapper
44
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
55
import java.io.File
66

7-
/*
8-
* default_model: gpt-3.5-turbo
9-
* models:
10-
* gpt-3.5-turbo:
11-
* provider: devchat.ai
12-
* stream: true
13-
*/
14-
class DevChatConfig {
15-
private var configPath: String
16-
17-
// Getters and Setters
7+
data class ModelConfig(val provider: String?, val isStream: Boolean)
8+
class DevChatConfig(private val configPath: String) {
189
var default_model: String? = null
1910
var models: Map<String, ModelConfig>? = null
2011

21-
constructor() {
22-
// default config path
23-
configPath = System.getProperty("user.home") + "/.chat/config.yml"
24-
}
25-
26-
constructor(configPath: String) {
27-
this.configPath = configPath
28-
}
29-
30-
open class ModelConfig {
31-
// getters and setters
32-
var provider: String? = null
33-
var isStream = false
34-
}
35-
3612
fun writeDefaultConfig() {
3713
default_model = "gpt-3.5-turbo"
38-
models = java.util.Map.of(
39-
"gpt-3.5-turbo",
40-
object : ModelConfig() {
41-
init {
42-
provider = "devchat.ai"
43-
isStream = true
44-
}
45-
},
46-
"gpt-3.5-turbo-16k",
47-
object : ModelConfig() {
48-
init {
49-
provider = "devchat.ai"
50-
isStream = true
51-
}
52-
},
53-
"gpt-4",
54-
object : ModelConfig() {
55-
init {
56-
provider = "devchat.ai"
57-
isStream = true
58-
}
59-
},
60-
"claude-2",
61-
object : ModelConfig() {
62-
init {
63-
provider = "general"
64-
isStream = true
65-
}
66-
})
14+
models = mapOf(
15+
"gpt-3.5-turbo" to ModelConfig(provider = "devchat.ai", isStream = true),
16+
"gpt-3.5-turbo-16k" to ModelConfig(provider = "devchat.ai", isStream = true),
17+
"gpt-4" to ModelConfig(provider = "devchat.ai", isStream = true),
18+
"claude-2" to ModelConfig(provider = "general", isStream = true),
19+
"xinghuo-2" to ModelConfig(provider = "general", isStream = true),
20+
"chatglm_pro" to ModelConfig(provider = "general", isStream = true),
21+
"ERNIE-Bot" to ModelConfig(provider = "general", isStream = true),
22+
)
6723
save()
6824
}
6925

src/main/kotlin/ai/devchat/cli/DevChatWrapper.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ai.devchat.cli
33
import ai.devchat.common.DevChatPathUtil
44
import ai.devchat.common.Log
55
import ai.devchat.common.Settings
6+
import ai.devchat.idea.balloon.DevChatNotifier
67
import com.alibaba.fastjson.JSON
78
import com.alibaba.fastjson.JSONArray
89
import com.intellij.util.alsoIfNull
@@ -111,6 +112,11 @@ class DevChatWrapper(
111112

112113
val prompt: (MutableList<Pair<String, String?>>, String, ((String) -> Unit)?) -> Unit get() = {
113114
flags: MutableList<Pair<String, String?>>, message: String, callback: ((String) -> Unit)? ->
115+
if (apiKey.isNullOrEmpty()) {
116+
DevChatNotifier.stickyError("DevChat Error", "Please config your API key first.")
117+
} else if (!apiKey!!.startsWith("DC.")) {
118+
DevChatNotifier.stickyError("DevChat Error", "Invalid API key format.")
119+
}
114120
flags
115121
.find { it.first == "model" && !it.second.isNullOrEmpty() }
116122
.alsoIfNull { flags.add("model" to defaultModel) }

src/main/kotlin/ai/devchat/idea/DevChatSetupThread.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DevChatSetupThread(private val project: Project) : Thread() {
2929
workflowEnv.installRequirements(it)
3030
}
3131

32-
val config = DevChatConfig()
32+
val config = DevChatConfig("$workPath/config.yml")
3333
config.writeDefaultConfig()
3434
notifyInfo(project, "DevChat initialization has completed successfully.")
3535
} catch (e: Exception) {

src/main/kotlin/ai/devchat/idea/balloon/DevChatNotifier.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package ai.devchat.idea.balloon
33
import com.intellij.notification.NotificationGroupManager
44
import com.intellij.notification.NotificationType
55
import com.intellij.openapi.project.Project
6+
import com.intellij.notification.Notification
7+
import com.intellij.notification.Notifications
8+
import com.intellij.notification.NotificationDisplayType
69

710
object DevChatNotifier {
811
@JvmStatic
@@ -20,4 +23,11 @@ object DevChatNotifier {
2023
.createNotification(content!!, NotificationType.ERROR)
2124
.notify(project)
2225
}
26+
27+
fun stickyError(title: String, content: String) {
28+
val notification = Notification(
29+
"stickyBalloon", title, content, NotificationType.ERROR
30+
)
31+
Notifications.Bus.notify(notification)
32+
}
2333
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<applicationService serviceImplementation="ai.devchat.idea.settings.DevChatSettingsState"/>
3737
<notificationGroup id="Custom Notification Group"
3838
displayType="BALLOON"/>
39+
<notificationGroup id="stickyBalloon" displayType="STICKY_BALLOON" isLogByDefault="true"/>
3940
</extensions>
4041
<actions>
4142
<action id="ai.devchat.idea.action.AddToDevChatEditorAction"
Lines changed: 17 additions & 5 deletions
Loading
Lines changed: 5 additions & 17 deletions
Loading

0 commit comments

Comments
 (0)