|
1 | 1 | package ai.devchat.cli |
2 | 2 |
|
| 3 | +import ai.devchat.common.DevChatPathUtil.workPath |
3 | 4 | import com.fasterxml.jackson.databind.ObjectMapper |
4 | 5 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory |
5 | 6 | import java.io.File |
6 | 7 |
|
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 | + |
14 | 10 | class DevChatConfig { |
15 | 11 | private var configPath: String |
16 | 12 |
|
17 | 13 | // 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 |
20 | 16 |
|
21 | 17 | constructor() { |
22 | 18 | // default config path |
23 | | - configPath = System.getProperty("user.home") + "/.chat/config.yml" |
| 19 | + configPath = "$workPath/config.yml" |
24 | 20 | } |
25 | 21 |
|
26 | 22 | constructor(configPath: String) { |
27 | 23 | this.configPath = configPath |
28 | 24 | } |
29 | 25 |
|
30 | | - open class ModelConfig { |
31 | | - // getters and setters |
32 | | - var provider: String? = null |
33 | | - var isStream = false |
34 | | - } |
35 | | - |
36 | 26 | 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 | + ) |
67 | 39 | save() |
68 | 40 | } |
69 | 41 |
|
70 | 42 | fun load(): DevChatConfig { |
71 | 43 | 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) |
75 | 45 | } catch (e: Exception) { |
76 | 46 | throw RuntimeException("Failed to load config", e) |
77 | 47 | } |
78 | 48 | } |
79 | 49 |
|
80 | | - fun save() { |
| 50 | + private fun save() { |
81 | 51 | try { |
82 | | - val mapper = ObjectMapper(YAMLFactory()) |
83 | | - mapper.writeValue(File(configPath), this) |
| 52 | + ObjectMapper(YAMLFactory()).writeValue(File(configPath), this) |
84 | 53 | } catch (e: Exception) { |
85 | 54 | throw RuntimeException("Failed to save config", e) |
86 | 55 | } |
|
0 commit comments