Skip to content

Commit 79fb298

Browse files
committed
Refactor DevChat Installation Manager & support workflow env setup
1 parent 6f64442 commit 79fb298

5 files changed

Lines changed: 196 additions & 310 deletions

File tree

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

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,55 @@
11
package ai.devchat.cli
22

3+
import ai.devchat.common.DevChatPathUtil.workPath
34
import com.fasterxml.jackson.databind.ObjectMapper
45
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
56
import java.io.File
67

7-
/*
8-
* default_model: gpt-3.5-turbo
9-
* models:
10-
* gpt-3.5-turbo:
11-
* provider: devchat.ai
12-
* stream: true
13-
*/
8+
data class ModelConfig(var provider: String? = null, var isStream: Boolean = false)
9+
1410
class DevChatConfig {
1511
private var configPath: String
1612

1713
// Getters and Setters
18-
var default_model: String? = null
19-
var models: Map<String, ModelConfig>? = null
14+
private var defaultModel: String? = null
15+
private var models: Map<String, ModelConfig>? = null
2016

2117
constructor() {
2218
// default config path
23-
configPath = System.getProperty("user.home") + "/.chat/config.yml"
19+
configPath = "$workPath/config.yml"
2420
}
2521

2622
constructor(configPath: String) {
2723
this.configPath = configPath
2824
}
2925

30-
open class ModelConfig {
31-
// getters and setters
32-
var provider: String? = null
33-
var isStream = false
34-
}
35-
3626
fun writeDefaultConfig() {
37-
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-
})
27+
defaultModel = "gpt-3.5-turbo"
28+
models = mapOf(
29+
"gpt-3.5-turbo" to ModelConfig(
30+
provider = "devchat.ai", isStream = true
31+
), "gpt-3.5-turbo-16k" to ModelConfig(
32+
provider = "devchat.ai", isStream = true
33+
), "gpt-4" to ModelConfig(
34+
provider = "devchat.ai", isStream = true
35+
), "claude-2" to ModelConfig(
36+
provider = "general", isStream = true
37+
)
38+
)
6739
save()
6840
}
6941

7042
fun load(): DevChatConfig {
7143
return try {
72-
val mapper =
73-
ObjectMapper(YAMLFactory())
74-
mapper.readValue(File(configPath), DevChatConfig::class.java)
44+
ObjectMapper(YAMLFactory()).readValue(File(configPath), DevChatConfig::class.java)
7545
} catch (e: Exception) {
7646
throw RuntimeException("Failed to load config", e)
7747
}
7848
}
7949

80-
fun save() {
50+
private fun save() {
8151
try {
82-
val mapper = ObjectMapper(YAMLFactory())
83-
mapper.writeValue(File(configPath), this)
52+
ObjectMapper(YAMLFactory()).writeValue(File(configPath), this)
8453
} catch (e: Exception) {
8554
throw RuntimeException("Failed to save config", e)
8655
}

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

Lines changed: 0 additions & 200 deletions
This file was deleted.

0 commit comments

Comments
 (0)