forked from arturbac/kdevcxx_with_ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_settings.h
More file actions
182 lines (145 loc) · 5.83 KB
/
Copy pathapp_settings.h
File metadata and controls
182 lines (145 loc) · 5.83 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// SPDX-FileCopyrightText: 2024 Artur Bać
// SPDX-License-Identifier: MIT
#pragma once
#include <aiprocess/universal_config.h>
#include <string>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <spdlog/common.h>
#pragma clang diagnostic pop
namespace aiprocess
{
enum struct backend_type_e : std::uint8_t
{
kate,
kdevelop
};
consteval auto adl_enum_bounds(backend_type_e)
{
using enum backend_type_e;
return simple_enum::adl_info{.first = kate, .last = kdevelop};
}
inline constexpr string_view kdevcxx_with_ai_app_settings_file_name{"kdevcxx_with_ai_app_settings.json"};
inline constexpr string_view kate_with_ai_app_settings_file_name{"kate_with_ai_app_settings.json"};
inline constexpr string_view kdevcxx_with_ai_ai_settings_file_name{"kdevcxx_with_ai_ai_settings.json"};
enum struct app_settings_version_e : std::uint8_t
{
v1 = 1,
latest = v1
};
consteval auto adl_enum_bounds(app_settings_version_e)
{
using enum app_settings_version_e;
return simple_enum::adl_info{.first = v1, .last = latest};
}
struct app_settings_t
{
std::string log_path{"logs_ai"};
// https://github.com/gabime/spdlog/wiki/3.-Custom-formatting
std::string console_log_pattern = "[thread %t] [%n] %v";
std::string general_log_pattern = "[%H:%M:%S %z] [%^%L%$] [thread %t] [%n] %v";
std::string snippet_log_pattern = "[%H:%M:%S %z] [%^%L%$] [thread %t] [%n] %v";
std::string important_log_pattern = "[%H:%M:%S %z] [%^%L%$] [thread %t] [%n] %v";
using level_enum = spdlog::level::level_enum;
level_enum console_log_level{level_enum::trace};
level_enum general_log_level{level_enum::trace};
level_enum snippet_log_level{level_enum::trace};
level_enum important_log_level{level_enum::info};
std::size_t flush_every{3};
// /usr/include/qt5/QtCore/qnamespace.h
// ControlModifier = 0x04000000
// Key_1 = 0x31,
int activation_keys{0x04000000 | 0x31};
app_settings_version_e version{simple_enum::limits::max<app_settings_version_e>()};
static constexpr app_settings_version_e expected_version{simple_enum::limits::max<app_settings_version_e>()};
};
template<backend_type_e>
auto load_app_settings() noexcept -> app_settings_t;
extern template auto load_app_settings<backend_type_e::kdevelop>() noexcept -> app_settings_t;
extern template auto load_app_settings<backend_type_e::kate>() noexcept -> app_settings_t;
template<backend_type_e>
auto store_app_settings(app_settings_t const & cfg) noexcept -> bool;
extern template auto store_app_settings<backend_type_e::kdevelop>(app_settings_t const & cfg) noexcept -> bool;
extern template auto store_app_settings<backend_type_e::kate>(app_settings_t const & cfg) noexcept -> bool;
enum struct ai_settings_version_e : std::uint8_t
{
v1 = 1,
v2,
latest = v2
};
consteval auto adl_enum_bounds(ai_settings_version_e)
{
using enum ai_settings_version_e;
return simple_enum::adl_info{.first = v1, .last = latest};
}
//
#if 1
// executed [AI below string is declaration of rules for openai gpt compress them without changing meaning but for
// optimising network connection and improving ai use] AI CODE BLOCK BEGIN
inline constexpr std::string_view default_ai_rules{
"Great c++23 coder, prefers std::ranges/views over loops, uses nodiscard and constexpr,"
" favors short/fast code with trailing return, adheres to lower_case, uses boost-ext/ut for tests,"
" code-only responses without explanations, unless requested, comments with // or /* */."
};
// AI CODE BLOCK END
#else
inline constexpr std::string_view default_ai_rules{
"You are great c++23 coder, preferring std::ranges and std::views over while and for loops,"
" using nodiscard attibute where appropriate, when possible You use constexpr, you prefer short and fast code,"
" when writing function you are using trailing return type,"
" using lower_case convention always, if implementing unit tests You use boost-ext/ut,"
" you don't produce explanations unless asked for, you return only code unless being asked for something else"
"when commenting code You use c++ comments like // or for comments block /* */"
};
#endif
inline constexpr std::string_view default_gpt_model{"gpt-4-1106-preview"};
/**
* @struct ai_settings_t
*
* @brief Holds the configuration settings for AI interaction.
*
* This structure is used to store configuration parameters for AI interaction,
* including API access and behavior rules.
*/
struct ai_settings_t
{
/// API key for authentication with the AI service.
std::string api_key{};
/// Rules that the AI should follow when processing requests.
std::string cxx_rules{default_ai_rules};
/// Identifier for the GPT model to be used for AI completions.
std::string gpt_model{default_gpt_model};
/// Version of the AI settings currently in use.
ai_settings_version_e version{simple_enum::limits::max<ai_settings_version_e>()};
/// Expected version of the AI settings structure.
static constexpr ai_settings_version_e expected_version{simple_enum::limits::max<ai_settings_version_e>()};
};
/**
* Loads AI settings from a default or specified location.
*
* @return ai_settings_t containing the settings for the AI.
*/
[[nodiscard]]
auto load_ai_settings() noexcept -> ai_settings_t;
/**
* Stores AI settings to a default or specified location.
*
* @param cfg The AI settings to store.
* @return True if successful, false otherwise.
*/
auto store_ai_settings(ai_settings_t const &) noexcept -> bool;
/**
* Retrieves the home directory of the current user.
*
* @return A string containing the path to the home directory.
*/
[[nodiscard]]
auto get_home_directory() noexcept -> std::string;
/**
* Constructs the full path to the configuration file based on the home directory.
*
* @return A string containing the full path to the configuration file.
*/
[[nodiscard]]
auto get_config_path() noexcept -> std::string;
} // namespace aiprocess