38 lines
1.8 KiB
PHP
38 lines
1.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
// Synthetic upstream probe: measures the maximum JSON output a model app will return.
|
|
// No patient data, no clinical content, no attachments. Prints sizes and token usage only.
|
|
$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;
|
|
|
|
$model = (string) ($argv[1] ?? 'qwen');
|
|
$count = (int) ($argv[2] ?? 200);
|
|
$prompt = '这是一次接口容量测试,与任何患者无关。请只输出一个JSON对象,键为items,值为长度恰好为' . $count
|
|
. '的数组,每个元素形如{"i":序号从1开始,"t":"第N条测试文本,用于测量输出长度,请写满约二十个汉字"}。不要输出解释文字。';
|
|
$started = microtime(true);
|
|
$response = DifyChatService::chat($model, [], $prompt, 'probe-output-limit-' . $model, [], [
|
|
'strict_files' => true, 'timeout' => 240,
|
|
]);
|
|
$content = (string) ($response['content'] ?? '');
|
|
$decoded = json_decode($content, true);
|
|
echo json_encode([
|
|
'model' => $model,
|
|
'requested_items' => $count,
|
|
'ok' => (bool) ($response['ok'] ?? false),
|
|
'error_code' => $response['error_code'] ?? '',
|
|
'latency_ms' => (int) ($response['latency_ms'] ?? 0),
|
|
'wall_seconds' => round(microtime(true) - $started, 1),
|
|
'content_bytes' => strlen($content),
|
|
'usage' => $response['usage'] ?? null,
|
|
'json_valid' => is_array($decoded),
|
|
'json_error' => is_array($decoded) ? '' : json_last_error_msg(),
|
|
'returned_items' => is_array($decoded) && is_array($decoded['items'] ?? null) ? count($decoded['items']) : null,
|
|
'tail_sample' => mb_substr($content, -60),
|
|
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";
|