Give the AI subsystem one profile table and one collection, read everywhere
This commit is contained in:
+16
-13
@@ -102,14 +102,9 @@ header('Content-Type: application/json');
|
||||
header('Cache-Control: no-store, no-cache');
|
||||
require_once dirname(__DIR__) . '/include/ai.php';
|
||||
|
||||
// History depth is per profile, and decided here rather than by the page. Varaverk Assistant
|
||||
// spends ~2500 of its 16384 on retrieved passages, so it cannot afford deep history; the other
|
||||
// two retrieve nothing and can carry a real conversation. Reasoning is not stored in history,
|
||||
// so it does not compound.
|
||||
// troubleshoot carries a whole log tail into context, so its history is the shallowest of the
|
||||
// four — the evidence for "why did this fail" is the log in front of it, not the conversation.
|
||||
const VV_AI_PROFILES = ['varaverk' => 3, 'chat' => 8, 'code' => 4, 'troubleshoot' => 2];
|
||||
const VV_AI_MAX_TURNS = 3; // fallback when a profile is not recognised
|
||||
// History depth is per profile and still decided server-side rather than by the page — the page
|
||||
// simply no longer carries a second copy of the numbers. include/ai_profiles.php holds them.
|
||||
// Reasoning is not stored in history, so it does not compound.
|
||||
const VV_AI_MAX_QUESTION = 4000; // characters
|
||||
const VV_AI_MAX_HIST_MSG = 4000; // characters per retained message
|
||||
const VV_AI_JOB_TTL = 3600; // seconds before a job file is reaped
|
||||
@@ -153,8 +148,16 @@ if (!vv_ai_enabled()) {
|
||||
}
|
||||
|
||||
// ── stats ─────────────────────────────────────────────────────────────────────
|
||||
// Served from the shared 'ai' cache that Tools/api_cache_writer.sh refreshes every minute, on
|
||||
// the same terms as the monitor and arrs payloads. This action is polled every 30 seconds by
|
||||
// every open tab and used to pay a full collection each time — around a second, most of it spent
|
||||
// waiting on Ollama and nvidia-smi — for numbers that only change when the writer next runs.
|
||||
//
|
||||
// ?live=1 bypasses it, for the case where something was just changed and the point is to see the
|
||||
// result. A missing cache always falls back to collecting, so the cache can never be the reason
|
||||
// the banner fails to render.
|
||||
if ($action === 'stats') {
|
||||
echo json_encode(['ok' => true, 'stats' => vv_ai_stats()]);
|
||||
echo json_encode(['ok' => true, 'stats' => vv_ai_stats_cached(isset($_GET['live']))]);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -232,7 +235,7 @@ if ($action === 'chat_save') {
|
||||
if (!$isPost) { http_response_code(405); echo json_encode(['ok' => false, 'error' => 'POST only']); exit; }
|
||||
|
||||
$profile = trim($_POST['profile'] ?? 'chat');
|
||||
if (!isset(VV_AI_PROFILES[$profile])) {
|
||||
if (!vv_ai_profile_ok($profile)) {
|
||||
echo json_encode(['ok' => false, 'error' => 'Unknown profile: ' . $profile]); exit;
|
||||
}
|
||||
|
||||
@@ -250,7 +253,7 @@ if ($action === 'chat_save') {
|
||||
// saved under one profile can be reopened under another, and the reopened turn is trimmed
|
||||
// again on the way back out by ask — so storing a little more than any single profile will
|
||||
// send costs nothing and keeps the transcript readable.
|
||||
$cap = max(VV_AI_PROFILES) * 2;
|
||||
$cap = vv_ai_profiles_max_turns() * 2;
|
||||
if (count($clean) > $cap) $clean = array_slice($clean, -$cap);
|
||||
|
||||
$r = vv_ai_chat_save(trim($_POST['id'] ?? ''), $profile, $clean);
|
||||
@@ -308,10 +311,10 @@ if ($action === 'ask') {
|
||||
}
|
||||
|
||||
$profile = trim($_POST['profile'] ?? 'varaverk');
|
||||
if (!isset(VV_AI_PROFILES[$profile])) {
|
||||
if (!vv_ai_profile_ok($profile)) {
|
||||
echo json_encode(['ok' => false, 'error' => 'Unknown profile: ' . $profile]); exit;
|
||||
}
|
||||
$maxTurns = VV_AI_PROFILES[$profile] ?? VV_AI_MAX_TURNS;
|
||||
$maxTurns = vv_ai_profile_turns($profile);
|
||||
|
||||
// Where the caller is standing — "master.conf", "daily_sync_maintenance.sh", a log name.
|
||||
// The scheduler page sends it so a question can say "this setting" and mean something; the
|
||||
|
||||
@@ -100,15 +100,14 @@ vv_api_data();
|
||||
//
|
||||
// Null on any host that is not the AI host or has AI_ENABLED false, which is also what makes the
|
||||
// row absent rather than empty there. Same shape as every other optional subsystem on this page.
|
||||
// Reads the shared 'ai' cache the writer maintains and only collects on a miss. Landing here at
|
||||
// all already means the monitor cache missed; paying a second full AI collection on top of that
|
||||
// would make the slowest request on this page slower still, for figures a background writer
|
||||
// refreshed under a minute ago.
|
||||
$_vv_ai = null;
|
||||
if (vv_ai_ui_on()) {
|
||||
require_once dirname(__DIR__) . '/include/ai.php';
|
||||
$_vv_ai = [
|
||||
'model' => vv_ai_config()['model'],
|
||||
'runtime' => vv_ai_runtime_stats(),
|
||||
'index' => vv_ai_index_stats(),
|
||||
'tokens' => vv_ai_token_stats()['today'] ?? null,
|
||||
];
|
||||
$_vv_ai = vv_ai_monitor_block(vv_ai_stats_cached(isset($_GET['live'])));
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
|
||||
Reference in New Issue
Block a user