-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsManager.cs
More file actions
111 lines (99 loc) · 3.36 KB
/
SettingsManager.cs
File metadata and controls
111 lines (99 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
namespace MimicMuseAI
{
public class SettingsManager
{
private static SettingsManager _instance;
public static SettingsManager Instance => _instance ??= new SettingsManager();
private readonly string settingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.ini");
private readonly IniFileHelper iniFileHelper;
private SettingsManager()
{
iniFileHelper = new IniFileHelper(settingsFilePath);
InitializeDefaultValues();
}
private void InitializeDefaultValues()
{
if (!iniFileHelper.KeyExists("OpenAPI", "Url"))
{
OpenAPIUrl = "https://api.openai.com";
}
if (!iniFileHelper.KeyExists("OpenAPI", "Model"))
{
OpenAPIModel = "text-davinci-003";
}
if (!iniFileHelper.KeyExists("OpenAPI", "Key"))
{
OpenAPIKey = "YOUR_API_KEY";
}
if (!iniFileHelper.KeyExists("Tokens", "ContextTokenLimit"))
{
ContextTokenLimit = 14000;
}
if (!iniFileHelper.KeyExists("Tokens", "LoreBookBudget"))
{
LoreBookBudget = 20;
}
if (!iniFileHelper.KeyExists("Tokens", "MaxReplyTokens"))
{
MaxReplyTokens = 2096;
}
}
public string OpenAPIUrl
{
get => GetSetting("OpenAPI", "Url");
set => SaveSetting("OpenAPI", "Url", value);
}
public string OpenAPIModel
{
get => GetSetting("OpenAPI", "Model");
set => SaveSetting("OpenAPI", "Model", value);
}
public string OpenAPIKey
{
get => GetSetting("OpenAPI", "Key");
set => SaveSetting("OpenAPI", "Key", value);
}
public int ContextTokenLimit
{
get => int.TryParse(GetSetting("Tokens", "ContextTokenLimit"), out var value) ? value : 0;
set => SaveSetting("Tokens", "ContextTokenLimit", value.ToString());
}
public int LoreBookBudget
{
get => int.TryParse(GetSetting("Tokens", "LoreBookBudget"), out var value) ? value : 0;
set => SaveSetting("Tokens", "LoreBookBudget", value.ToString());
}
public int MaxReplyTokens
{
get => int.TryParse(GetSetting("Tokens", "MaxReplyTokens"), out var value) ? value : 0;
set => SaveSetting("Tokens", "MaxReplyTokens", value.ToString());
}
private string GetSetting(string section, string key)
{
try
{
return iniFileHelper.Read(section, key);
}
catch (Exception ex)
{
MessageBox.Show($"Error reading setting from INI file: {ex.Message}");
return string.Empty;
}
}
public void SaveSetting(string section, string key, string value)
{
try
{
iniFileHelper.Write(section, key, value);
}
catch (Exception ex)
{
MessageBox.Show($"Error saving setting to INI file: {ex.Message}");
}
}
}
}