-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatAI.config.php
More file actions
208 lines (196 loc) · 8.12 KB
/
ChatAI.config.php
File metadata and controls
208 lines (196 loc) · 8.12 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php namespace ProcessWire;
require_once __DIR__ . "/classes/ChatAIModelClient.php";
$configData = wire("modules")->getConfig("ChatAI");
$modelClient = new ChatAIModelClient();
$modelClient->setWire(wire());
$modelList = $modelClient->modelOptions();
$selectedModel = $modelClient->resolveModelId((string) ($configData["agenttools_model_id"] ?? ""));
$configuredEmbeddingModel = (string) ($configData["agenttools_embedding_model_id"] ?? "");
$selectedEmbeddingModel = $configuredEmbeddingModel !== "" ? $modelClient->resolveModelId($configuredEmbeddingModel) : "";
if (!$selectedModel || ($modelList && !isset($modelList[$selectedModel]))) {
$selectedModel = (string) (array_key_first($modelList) ?? "");
}
if ($configuredEmbeddingModel !== "" && (!$selectedEmbeddingModel || ($modelList && !isset($modelList[$selectedEmbeddingModel])))) {
$selectedEmbeddingModel = "";
}
$embeddingStatus = $modelClient->validateEmbeddingModel($selectedEmbeddingModel);
$embeddingChildren = [];
$embeddingModelOptions = $modelList
? ["" => __("Select an embeddings model")] + $modelList
: ["" => __("No AgentTools models configured")];
if (empty($embeddingStatus["ok"])) {
$embeddingChildren[] = [
"name" => "agenttools_embedding_warning",
"type" => "markup",
"label" => __("Embedding setup incomplete"),
"value" => "<p class='ui-state-error' style='padding: 0.75em; margin: 0 0 1em;'>" .
wire("sanitizer")->entities(implode(" ", $embeddingStatus["errors"] ?? [])) .
"</p>",
"columnWidth" => 100,
];
}
$embeddingChildren[] = [
"name" => "agenttools_embedding_model_id",
"type" => "select",
"label" => __("Embedding model"),
"columnWidth" => 100,
"options" => $embeddingModelOptions,
"value" => $selectedEmbeddingModel,
"notes" => $modelList
? __("Select an AgentTools entry for embeddings. This can be different from the chat model and should point to an embeddings-capable endpoint/model.")
: __("Configure at least one suitable model/API key in AgentTools first."),
];
$roles = wire("roles");
$promptRoleOptions = [];
foreach ($roles as $role) {
if (in_array($role->name, ["guest", "superuser"], true)) {
continue;
}
$promptRoleOptions[$role->name] = $role->name;
}
$config = [
[
"name" => "agenttools",
"type" => "fieldset",
"label" => __("AgentTools LLM"),
"description" => __("ChatAI uses AgentTools for chat model credentials, provider, endpoint, and model selection."),
"children" => [
[
"name" => "agenttools_model_id",
"type" => "select",
"label" => __("Model"),
"columnWidth" => 100,
"options" => $modelList ?: ["" => __("No AgentTools models configured")],
"value" => $selectedModel,
"notes" => $modelList
? __("Models are configured in AgentTools. Re-save ChatAI after changing AgentTools models.")
: __("Configure at least one Engineer model/API key in AgentTools first."),
],
[
"name" => "finetune",
"type" => "fieldset",
"label" => __("Generation Settings"),
"children" => [
[
"name" => "verbosity",
"type" => "select",
"label" => __("Verbosity"),
"columnWidth" => 20,
"options" => [
"low" => "Low",
"medium" => "Medium",
"high" => "High",
],
"value" => "medium",
],
[
"name" => "reasoning_effort",
"type" => "select",
"label" => __("Reasoning Effort"),
"columnWidth" => 20,
"options" => [
"minimal" => "Minimal",
"low" => "Low",
"medium" => "Medium",
"high" => "High",
],
"value" => "medium",
],
[
"name" => "llm_timeout",
"type" => "integer",
"label" => __("Timeout seconds"),
"columnWidth" => 20,
"value" => 25,
],
[
"name" => "max_completion_tokens",
"type" => "integer",
"label" => __("Max tokens"),
"columnWidth" => 20,
"notes" => __("Max tokens per message"),
"value" => 2000,
],
[
"name" => "max_messages",
"type" => "integer",
"label" => __("Maximum questions"),
"columnWidth" => 20,
"notes" => __("Max questions per conversation"),
"value" => 20,
],
[
"name" => "max_strikes",
"type" => "integer",
"label" => __("Maximum blacklist"),
"columnWidth" => 20,
"notes" => __(
"Number of blacklist strikes before being blocked",
),
"value" => 3,
],
],
],
],
],
[
"name" => "agenttools_embeddings",
"type" => "fieldset",
"label" => __("RAG Embeddings"),
"description" => __("Embeddings use a separately selected AgentTools model entry. Configure a dedicated embeddings-capable entry in AgentTools if needed. Changing embedding settings requires a full reindex of vectors."),
"collapsed" => empty($embeddingStatus["ok"]) ? 0 : 5,
"children" => $embeddingChildren,
],
[
"name" => "prompt_roles",
"type" => "checkboxes",
"label" => __("Roles allowed to craft prompt"),
"options" => $promptRoleOptions,
"value" => [],
"columnWidth" => 50,
"notes" => __(
"Superuser is always allowed.\r\n" .
"If no roles are selected, only superusers can access the ChatAI dashboard tabs.\r\n" .
"Select one or more roles (for example the 'chatai' role created on install) to allow them as well.",
),
],
[
"name" => "files",
"type" => "fieldset",
"label" => __("Files"),
"children" => [
[
"name" => "widget",
"type" => "text",
"label" => __("Path to widget file"),
"notes" => "Default is /site/modules/ChatAI/chatai-widget.php",
"value" => "/site/modules/ChatAI/chatai-widget.php",
"stripTags" => true,
],
[
"name" => "css",
"type" => "text",
"label" => __("Path to CSS file"),
"notes" => "Default is /site/modules/ChatAI/chatai.css",
"value" => "/site/modules/ChatAI/chatai.css",
"stripTags" => true,
],
[
"name" => "js",
"type" => "text",
"label" => __("Path to JS file"),
"notes" => "Default is /site/modules/ChatAI/chatai.js",
"value" => "/site/modules/ChatAI/chatai.js",
"stripTags" => true,
],
[
"name" => "rag_view",
"type" => "text",
"label" => __("Path to indexing view file"),
"notes" => "Default is /site/modules/ChatAI/classes/RAG/chatai-rag.php",
"value" => "/site/modules/ChatAI/classes/RAG/chatai-rag.php",
"stripTags" => true,
],
],
],
];