Added personality - Chamberlain

This commit is contained in:
hbrain 2026-06-19 18:15:40 +02:00
parent be70760320
commit 3d996db3b2
4 changed files with 75 additions and 13 deletions

View file

@ -60,7 +60,23 @@ if ($jobdir === null || !is_dir($jobdir)) {
exit;
}
function mvlog_read_personality_keys(string $script): array {
if (!is_file($script)) return [];
$src = (string)@file_get_contents($script);
if ($src === '') return [];
if (!preg_match('/PERSONALITY_KEYS=\((.*?)\)/s', $src, $m)) return [];
if (!preg_match_all('/"((?:\\\\.|[^"\\\\])*)"/', $m[1], $mm)) return [];
$out = [];
foreach ($mm[1] as $raw) {
$key = stripcslashes($raw);
if ($key === '') continue;
$out[] = ['key' => $key, 'label' => ucfirst(str_replace(['_', '-'], ' ', $key))];
}
return $out;
}
$path = $jobdir . '/.mvlog-describe-prompt.txt';
$prompt = is_file($path) ? trim((string)@file_get_contents($path)) : '';
$personalities = mvlog_read_personality_keys($MVLOG_ROOT . '/bin/generate_data.sh');
echo json_encode(['status' => 'ok', 'additional_prompt' => $prompt], JSON_UNESCAPED_UNICODE);
echo json_encode(['status' => 'ok', 'additional_prompt' => $prompt, 'personalities' => $personalities], JSON_UNESCAPED_UNICODE);

View file

@ -11,6 +11,8 @@ $id = strtolower(trim((string)($_POST['id'] ?? '')));
$job = trim((string)($_POST['job'] ?? ''));
$max_frames = isset($_POST['max_frames']) ? intval($_POST['max_frames']) : 16;
$additional_prompt = trim((string)($_POST['additional_prompt'] ?? ''));
$personality = strtolower(trim((string)($_POST['personality'] ?? 'auto')));
if (!preg_match('/^[a-z0-9_-]+$/', $personality)) $personality = 'auto';
function mvlog_article_id_is_valid(string $id): bool {
return (bool)preg_match('/^[0-9]{14}[a-f0-9]{16}$/', $id);
@ -110,12 +112,9 @@ if (!is_file($script)) {
exit;
}
// Build command and execute. Pass optional additional prompt as the last argument.
if ($additional_prompt !== '') {
$cmd = escapeshellcmd($script) . ' ' . escapeshellarg($jobdir) . ' ' . escapeshellarg($title) . ' ' . escapeshellarg($location) . ' ' . escapeshellarg((string)$max_frames) . ' ' . escapeshellarg($additional_prompt) . ' 2>&1';
} else {
$cmd = escapeshellcmd($script) . ' ' . escapeshellarg($jobdir) . ' ' . escapeshellarg($title) . ' ' . escapeshellarg($location) . ' ' . escapeshellarg((string)$max_frames) . ' ' . escapeshellarg('no-append') . ' 2>&1';
}
// Build command and execute. Pass optional additional prompt and chosen personality.
$prompt_arg = $additional_prompt !== '' ? $additional_prompt : 'no-append';
$cmd = escapeshellcmd($script) . ' ' . escapeshellarg($jobdir) . ' ' . escapeshellarg($title) . ' ' . escapeshellarg($location) . ' ' . escapeshellarg((string)$max_frames) . ' ' . escapeshellarg($prompt_arg) . ' ' . escapeshellarg($personality) . ' 2>&1';
// Allow long-running
@set_time_limit(0);