AI Models - one model's window: Add (no id - ?provider= picks its * provider) or Edit. The model's name, suggested from what its provider lists; * what it is for, saying what that use case uses now; its temperature; and * the company's instructions that go with every request it handles. Try it * sends it a one-line request as it is in the window, unsaved. Save asks first * (check_ai_model, admin/post/ai_models.php), so what is wrong shows beside * each field. */ require_once '../../includes/modal_header.php'; $model_id = intval($_GET['id'] ?? 0); $row = $model_id ? aiModelRow($model_id) : null; if ($model_id && !$row) { echo json_encode(['error' => 'That AI model no longer exists.']); exit; } $provider_id = $row ? intval($row['ai_model_ai_provider_id']) : intval($_GET['provider'] ?? 0); $providers = []; $sql = mysqli_query($mysqli, "SELECT ai_provider_id, ai_provider_name, ai_provider_kind FROM ai_providers ORDER BY ai_provider_name"); while ($provider = mysqli_fetch_assoc($sql)) { $providers[intval($provider['ai_provider_id'])] = $provider; } if (!isset($providers[$provider_id])) { $provider_id = count($providers) === 1 ? array_key_first($providers) : 0; } $use_cases = aiUseCases(); $map = aiUseCaseMap(['model' => $model_id])['map']; // A new one goes where there is nothing yet - General first $use_case = $row ? (string) $row['ai_model_use_case'] : 'General'; if (!$row) { foreach ($use_cases as $case => $about) { if (!$map[$case]['own']) { $use_case = $case; break; } } } // What each use case has now, without this one - so picking one says what it takes over, or that it won't be used $taken = []; foreach ($map as $case => $lands) { $taken[$case] = $lands['own'] ? ['name' => $lands['model']['ai_model_name'], 'provider' => $lands['model']['ai_provider_name'], 'first' => intval($lands['model']['ai_model_id']) < ($model_id ?: PHP_INT_MAX)] : null; } $temperature = $row && $row['ai_model_temperature'] !== null ? rtrim(rtrim(number_format(floatval($row['ai_model_temperature']), 2, '.', ''), '0'), '.') : ''; $error_for = function ($field) { return '
'; }; ob_start(); ?>