initialize(); $row = AiProviderModel::where('enabled', 1) ->whereRaw('(visible IS NULL OR visible = 1)') ->whereRaw('(apiKey IS NOT NULL AND LENGTH(TRIM(apiKey)) > 0)') ->order('sortWeight', 'asc') ->order('id', 'asc') ->find(); $providerHint = $row ? [ 'id' => (int) $row->id, 'providerId' => (string) ($row->providerId ?? ''), 'endpoint' => trim((string) ($row->apiEndpoint ?? '')) ?: '(默认内置)', 'model' => (string) ($row->model ?? ''), ] : null; $messages = [ ['role' => 'system', 'content' => AiCallService::buildSystemPrompt([ 'mbtiType' => 'ENTJ', 'summary' => '', 'nickname' => '冒烟测试', 'testAppendix' => '', ])], [ 'role' => 'user', 'content' => '用两三句话回答:ENTJ 常见的一个优势和一个盲点分别是什么?不要以#或@开头,不要人设签名。', ], ]; $r = AiCallService::chat($messages, ['temperature' => 0.45, 'maxTokens' => 512]); $content = trim((string) ($r['content'] ?? '')); $ok = $content !== '' && empty($r['isDegraded']); $payload = [ 'first_provider' => $providerHint, 'api_path' => strtolower((string) ($row->providerId ?? '')) === 'anthropic' ? 'POST {endpoint}/v1/messages (Anthropic)' : 'POST {endpoint}/chat/completions (OpenAI 兼容)', 'isDegraded' => !empty($r['isDegraded']), 'providerId' => (string) ($r['providerId'] ?? ''), 'content_preview'=> $ok ? mb_substr($content, 0, 280) . (mb_strlen($content) > 280 ? '…' : '') : $content, 'ok' => $ok, ]; echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT), "\n"; exit($ok ? 0 : 1);