43 lines
3.5 KiB
PHP
43 lines
3.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
// One bounded diagnostic request to the configured provider with an already-authorized attachment.
|
|
// Never output the URL, key, request/response body or clinical findings.
|
|
$serverRoot = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'server' . DIRECTORY_SEPARATOR;
|
|
chdir($serverRoot);
|
|
require $serverRoot . 'vendor/autoload.php';
|
|
$app = new \think\App($serverRoot);
|
|
$app->initialize();
|
|
use app\common\service\DifyChatService as Chat;
|
|
use app\common\service\prescriptionai\PrescriptionAiCipher as Cipher;
|
|
try {
|
|
$batch = \think\facade\Db::name('prescription_ai_batch')->where('id', 1)->where('prescription_id', 7556)->find();
|
|
$secret = (string) config('prescription_analysis.encryption_key', '');
|
|
if ($secret === '') { $secret = trim((string) file_get_contents(root_path('runtime') . 'prescription_ai_private/snapshot.key')); }
|
|
$context = (new Cipher($secret))->decrypt($batch['context_cipher'], 'context');
|
|
$files = array_values(array_filter($context['files'], static fn (array $f): bool => $f['status'] !== 'restricted' && !empty($f['url']) && $f['type'] === 'image'));
|
|
$file = $files[0];
|
|
$config = (array) config('prescription_ai');
|
|
$model = $config['models']['openai'];
|
|
$specs = (new ReflectionMethod(Chat::class, 'buildRequestSpecs'))->invoke(null, $config['base_url'], $model['name'], [],
|
|
'附件传输检查。仅回复 OK,不输出或分析图片内容。', 'rxai-attachment-diagnostic', false,
|
|
[['type' => 'image', 'transfer_method' => 'remote_url', 'url' => $file['url']]], []);
|
|
$spec = $specs[0];
|
|
$response = (new ReflectionMethod(Chat::class, 'sendRequest'))->invoke(null, $spec['url'], $spec['payload'], $model['api_key'], 10);
|
|
$decoded = json_decode($response['body'], true);
|
|
$message = strtolower((string) ($decoded['message'] ?? $decoded['error']['message'] ?? ''));
|
|
$flags = [];
|
|
foreach (['upload', 'disabled', 'image', 'vision', 'support', 'download', 'timeout', 'invalid', 'required', 'limit', 'file', 'extension', 'not allowed', 'format'] as $word) {
|
|
if (str_contains($message, $word)) { $flags[] = $word; }
|
|
}
|
|
$technicalWords = explode(' ', 'file files is are the a an not no can cannot be must should remote local url transfer method uploaded upload unsupported supported allowed type types size large too exceeds maximum minimum empty missing exist exists found invalid valid param parameter parameters enabled enable disabled disable app application config configuration variable value values required mandatory in on of to and or for this image document content mime extension number count length user id does do set provided only accept accepts belong belongs owner permission access denied failed fetch download server request input inputs object list array string assistant prompt form unsupported_file_type');
|
|
preg_match_all('/[a-z_]+/', $message, $words);
|
|
$safeStructure = array_map(static fn (string $word): string => in_array($word, $technicalWords, true) ? $word : '[redacted]', $words[0]);
|
|
$code = $decoded['code'] ?? $decoded['error']['code'] ?? '';
|
|
echo json_encode(['protocol' => $spec['protocol'], 'http_code' => $response['http_code'], 'curl_errno' => $response['errno'],
|
|
'provider_code' => is_string($code) && preg_match('/^[a-zA-Z0-9_]{1,80}$/', $code) ? $code : '', 'message_categories' => $flags,
|
|
'technical_message_structure' => array_slice($safeStructure, 0, 35)]), PHP_EOL;
|
|
} catch (Throwable $e) {
|
|
echo json_encode(['probe_error' => get_class($e), 'code' => $e->getCode()]), PHP_EOL;
|
|
exit(1);
|
|
}
|