41 lines
1.9 KiB
PHP
41 lines
1.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
// One known failed task only; use the normal authorization and retry-budget checks.
|
|
use app\adminapi\logic\tcm\PrescriptionAiLogic;
|
|
use app\common\service\prescriptionai\PrescriptionAiAccess;
|
|
use think\facade\Db;
|
|
|
|
$serverRoot = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'server' . DIRECTORY_SEPARATOR;
|
|
chdir($serverRoot);
|
|
require $serverRoot . 'vendor/autoload.php';
|
|
$app = new \think\App($serverRoot);
|
|
$app->initialize();
|
|
try {
|
|
$model = in_array('--openai', $argv, true) ? 'openai' : 'qwen';
|
|
$expectedError = $model === 'openai' ? 'INPUT_TOKEN_BUDGET_EXCEEDED' : 'INVALID_FILE_EVIDENCE_OUTPUT';
|
|
$batch = Db::name('prescription_ai_batch')->where('id', 1)->where('prescription_id', 7556)->find();
|
|
$task = Db::name('prescription_ai_task')->where('batch_id', 1)->where('model_key', $model)->find();
|
|
if (!$batch || !$task || $batch['validity'] !== 'current'
|
|
|| $task['status'] !== 'failed' || $task['error_code'] !== $expectedError) {
|
|
throw new RuntimeException('Task is no longer the expected failed task');
|
|
}
|
|
if (Db::name('prescription_ai_task')->where('model_key', $model)->where('status', 'running')->count() > 0) {
|
|
throw new RuntimeException('A model task is running; do not stop its consumer');
|
|
}
|
|
$actor = (int) $batch['actor_id'];
|
|
$info = PrescriptionAiAccess::actor($actor);
|
|
if (!$info || !PrescriptionAiAccess::allowed($actor, $info, 'retry')) {
|
|
throw new RuntimeException('Retry is not authorized for the original actor');
|
|
}
|
|
if (in_array('--apply', $argv, true)) {
|
|
$result = PrescriptionAiLogic::retry(1, $model, $actor, $info);
|
|
} else {
|
|
$result = ['model' => $model, 'eligible' => true, 'running_model_tasks' => 0, 'applied' => false];
|
|
}
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE), PHP_EOL;
|
|
} catch (Throwable $error) {
|
|
echo json_encode(['retry_error' => get_class($error), 'code' => $error->getCode()]), PHP_EOL;
|
|
exit(1);
|
|
}
|