-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.cpp
More file actions
103 lines (91 loc) · 3.27 KB
/
Copy pathconfig.cpp
File metadata and controls
103 lines (91 loc) · 3.27 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
#include "config.hpp"
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <sys/stat.h>
std::string Config::trim(const std::string& s) {
size_t l = s.find_first_not_of(" \t\r\n");
size_t r = s.find_last_not_of(" \t\r\n");
if (l == std::string::npos) return {};
return s.substr(l, r - l + 1);
}
std::string Config::get_home() {
const char* h = std::getenv("HOME");
return h ? std::string(h) : std::string("/root");
}
bool Config::load(const std::string& path) {
std::ifstream f(path);
if (!f) return false;
std::string line, section;
while (std::getline(f, line)) {
line = trim(line);
if (line.empty() || line[0] == '#' || line[0] == ';') continue;
if (line.front() == '[' && line.back() == ']') {
section = line.substr(1, line.size() - 2);
for (auto& c : section) c = static_cast<char>(std::tolower(c));
continue;
}
auto eq = line.find('=');
if (eq == std::string::npos) continue;
std::string key = trim(line.substr(0, eq));
std::string value = trim(line.substr(eq + 1));
for (auto& c : key) c = static_cast<char>(std::tolower(c));
if (section == "settings") {
if (key == "auto_cycle") cfg_.auto_cycle = (value == "true" || value == "1");
else if (key == "cycle_delay_ms") cfg_.cycle_delay_ms = std::stoi(value);
else if (key == "warn_accuracy") cfg_.warn_accuracy = (value == "true" || value == "1");
else if (key == "learning_rate") cfg_.learning_rate = std::stof(value);
else if (key == "train_epochs") cfg_.train_epochs = std::stoi(value);
} else if (section == "prompts") {
if (!value.empty()) cfg_.prompts.push_back(value);
}
}
return true;
}
bool Config::write_default(const std::string& path) {
// Ensure parent directory exists
auto slash = path.rfind('/');
if (slash != std::string::npos) {
std::string dir = path.substr(0, slash);
// mkdir -p equivalent (simple recursive)
std::string tmp;
for (char c : dir) {
tmp += c;
if (c == '/') mkdir(tmp.c_str(), 0755);
}
mkdir(dir.c_str(), 0755);
}
std::ofstream f(path);
if (!f) return false;
f << R"(# nvisual configuration file
# Edit this file to customize the AI prompts and behavior.
#
# WARNING: The AI (~1K parameters) is a very small neural network
# and may not give accurate answers. To improve accuracy:
# 1. Add prompt/answer pairs to:
# ~/.config/nvisual/dataset/dataset.jsonl
# Format: {"prompt": "Your question?", "answer": "The answer"}
# 2. Run: nvisual --train
# to fine-tune the model on your custom data.
[settings]
auto_cycle = true
cycle_delay_ms = 0
warn_accuracy = true
learning_rate = 0.05
train_epochs = 100
[prompts]
prompt1 = What is 2 + 2?
prompt2 = What is the capital of France?
prompt3 = What color is the sky?
prompt4 = Is water wet?
prompt5 = What is the speed of light?
prompt6 = Who invented the telephone?
prompt7 = What is the largest planet?
prompt8 = How many days in a week?
prompt9 = What gas do plants absorb?
prompt10 = What is the boiling point of water?
)";
return f.good();
}