11package ai.devchat.cli
22
3- import ai.devchat.common.DevChatPathUtil.workPath
43import com.fasterxml.jackson.databind.ObjectMapper
54import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
65import java.io.File
76
8- data class ModelConfig (var provider : String? = null , var isStream : Boolean = false )
9-
7+ /*
8+ * default_model: gpt-3.5-turbo
9+ * models:
10+ * gpt-3.5-turbo:
11+ * provider: devchat.ai
12+ * stream: true
13+ */
1014class DevChatConfig {
1115 private var configPath: String
1216
1317 // Getters and Setters
14- private var defaultModel : String? = null
15- private var models: Map <String , ModelConfig >? = null
18+ var default_model : String? = null
19+ var models: Map <String , ModelConfig >? = null
1620
1721 constructor () {
1822 // default config path
19- configPath = " $workPath /config.yml"
23+ configPath = System .getProperty( " user.home " ) + " /.chat /config.yml"
2024 }
2125
2226 constructor (configPath: String ) {
2327 this .configPath = configPath
2428 }
2529
30+ open class ModelConfig {
31+ // getters and setters
32+ var provider: String? = null
33+ var isStream = false
34+ }
35+
2636 fun writeDefaultConfig () {
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- )
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+ })
3967 save()
4068 }
4169
4270 fun load (): DevChatConfig {
4371 return try {
44- ObjectMapper (YAMLFactory ()).readValue(File (configPath), DevChatConfig ::class .java)
72+ val mapper =
73+ ObjectMapper (YAMLFactory ())
74+ mapper.readValue(File (configPath), DevChatConfig ::class .java)
4575 } catch (e: Exception ) {
4676 throw RuntimeException (" Failed to load config" , e)
4777 }
4878 }
4979
50- private fun save () {
80+ fun save () {
5181 try {
52- ObjectMapper (YAMLFactory ()).writeValue(File (configPath), this )
82+ val mapper = ObjectMapper (YAMLFactory ())
83+ mapper.writeValue(File (configPath), this )
5384 } catch (e: Exception ) {
5485 throw RuntimeException (" Failed to save config" , e)
5586 }
5687 }
57- }
88+ }
0 commit comments