更新
This commit is contained in:
@@ -11,6 +11,7 @@ use app\common\model\tcm\Diagnosis;
|
||||
use app\common\model\tcm\DiagnosisAiReport;
|
||||
use app\common\service\DifyChatService;
|
||||
use app\common\service\NihaixiaClinicalSkill;
|
||||
use app\common\service\TcmAncientBooksReference;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
@@ -1630,7 +1631,7 @@ PROMPT;
|
||||
'model_label' => self::cleanText($modelLabel, 50),
|
||||
'report_content' => $content,
|
||||
'message_id' => self::cleanText($messageId, 191),
|
||||
'ancient_book_sources_json' => json_encode($ancientBookSources, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '[]',
|
||||
'ancient_book_sources_json' => json_encode(TcmAncientBooksReference::localizeSources($ancientBookSources), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?: '[]',
|
||||
'prompt_version' => self::PROMPT_VERSION,
|
||||
'case_fingerprint' => (string) $context['fingerprint'],
|
||||
'generated_by' => $adminId,
|
||||
@@ -1763,7 +1764,8 @@ PROMPT;
|
||||
private static function decodeAncientBookSources(mixed $value): array
|
||||
{
|
||||
$decoded = is_string($value) ? json_decode($value, true) : null;
|
||||
return is_array($decoded) && array_is_list($decoded) ? array_values(array_filter($decoded, 'is_array')) : [];
|
||||
return is_array($decoded) && array_is_list($decoded)
|
||||
? TcmAncientBooksReference::localizeSources($decoded) : [];
|
||||
}
|
||||
|
||||
/** @return array<string,array<string,mixed>> */
|
||||
|
||||
@@ -12,6 +12,7 @@ use app\common\model\dept\Dept;
|
||||
use app\common\model\tcm\PatientAiReport;
|
||||
use app\common\service\DifyChatService;
|
||||
use app\common\service\NihaixiaClinicalSkill;
|
||||
use app\common\service\TcmAncientBooksReference;
|
||||
use app\common\service\FileService;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
@@ -247,8 +248,8 @@ class PatientAiReportLogic extends BaseLogic
|
||||
'source_snapshot' => $sourceJson,
|
||||
'source_summary_json' => self::encodeJson($sourceSummary),
|
||||
'source_diagnosis_ids_json' => self::encodeJson($diagnosisIds),
|
||||
'ancient_book_sources_json' => self::encodeJson(is_array($upstream['ancient_book_sources'] ?? null)
|
||||
? $upstream['ancient_book_sources'] : []),
|
||||
'ancient_book_sources_json' => self::encodeJson(TcmAncientBooksReference::localizeSources(
|
||||
is_array($upstream['ancient_book_sources'] ?? null) ? $upstream['ancient_book_sources'] : [])),
|
||||
'source_hash' => $sourceHash,
|
||||
'prompt_version' => self::PROMPT_VERSION,
|
||||
'message_id' => self::cleanText($upstream['message_id'] ?? '', 191),
|
||||
@@ -1110,19 +1111,29 @@ class PatientAiReportLogic extends BaseLogic
|
||||
}
|
||||
$seen = [];
|
||||
foreach ($accumulated as $source) {
|
||||
$seen[(string) ($source['url'] ?? '')] = true;
|
||||
$seen[self::ancientBookSourceKey($source)] = true;
|
||||
}
|
||||
foreach ($sources as $source) {
|
||||
if (!is_array($source) || !is_string($source['url'] ?? null) || isset($seen[$source['url']])) {
|
||||
if (!is_array($source)) {
|
||||
continue;
|
||||
}
|
||||
$seen[$source['url']] = true;
|
||||
$key = self::ancientBookSourceKey($source);
|
||||
if (isset($seen[$key])) {
|
||||
continue;
|
||||
}
|
||||
$seen[$key] = true;
|
||||
$accumulated[] = $source;
|
||||
if (count($accumulated) >= 12) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $accumulated;
|
||||
return TcmAncientBooksReference::localizeSources($accumulated);
|
||||
}
|
||||
|
||||
private static function ancientBookSourceKey(array $source): string
|
||||
{
|
||||
return (string) ($source['commit'] ?? '') . "\0" . (string) ($source['path'] ?? '')
|
||||
. "\0" . (string) ($source['line'] ?? '');
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $snapshot */
|
||||
@@ -1505,7 +1516,8 @@ class PatientAiReportLogic extends BaseLogic
|
||||
'source_summary' => $sourceSummary !== [] ? $sourceSummary : self::emptySourceSummary(),
|
||||
'source_diagnosis_ids' => self::decodeJsonArray($row['source_diagnosis_ids_json'] ?? ''),
|
||||
'knowledge_source' => NihaixiaClinicalSkill::knowledgeSourceForPromptVersion((string) ($row['prompt_version'] ?? '')),
|
||||
'ancient_book_sources' => self::decodeJsonArray($row['ancient_book_sources_json'] ?? ''),
|
||||
'ancient_book_sources' => TcmAncientBooksReference::localizeSources(
|
||||
self::decodeJsonArray($row['ancient_book_sources_json'] ?? '')),
|
||||
'prompt_version' => (string) ($row['prompt_version'] ?? ''),
|
||||
'version' => max((int) ($row['version'] ?? 1), 1),
|
||||
'generated_time' => $generatedTime,
|
||||
|
||||
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
||||
namespace app\adminapi\logic\tcm;
|
||||
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\service\NihaixiaClinicalSkill;
|
||||
use app\common\service\TcmAncientBooksReference;
|
||||
use app\common\service\prescriptionai\PrescriptionAiAccess as Access;
|
||||
use app\common\service\prescriptionai\PrescriptionAiCipher as Cipher;
|
||||
use app\common\service\prescriptionai\PrescriptionAiDoctorSnapshot as DoctorSnapshot;
|
||||
@@ -298,6 +300,9 @@ final class PrescriptionAiLogic
|
||||
}
|
||||
foreach ($results as $result) {
|
||||
$body = $full ? (new Cipher())->decrypt($result['body_cipher'], 'result:' . $result['batch_id'] . ':' . $result['model_key']) : [];
|
||||
if ($full) {
|
||||
$body = self::localizeSourceMetadata($body);
|
||||
}
|
||||
unset($result['body_cipher']);
|
||||
$result['score'] = $result['score'] === null ? null : (float) $result['score'];
|
||||
$result['herb_score'] = $result['herb_score'] === null ? null : (float) $result['herb_score'];
|
||||
@@ -321,6 +326,15 @@ final class PrescriptionAiLogic
|
||||
return $map;
|
||||
}
|
||||
|
||||
/** Existing encrypted results may still contain repository links. */
|
||||
private static function localizeSourceMetadata(array $body): array
|
||||
{
|
||||
$body['knowledge_source'] = NihaixiaClinicalSkill::localizeKnowledgeSource($body['knowledge_source'] ?? null);
|
||||
$body['ancient_book_sources'] = TcmAncientBooksReference::localizeSources(
|
||||
is_array($body['ancient_book_sources'] ?? null) ? $body['ancient_book_sources'] : []);
|
||||
return $body;
|
||||
}
|
||||
|
||||
private static function formatBatch(array $batch, array $models, ?array $rx = null): array
|
||||
{
|
||||
$validity = $batch['validity'];
|
||||
|
||||
Reference in New Issue
Block a user