This commit is contained in:
Your Name
2026-10-09 14:13:57 +08:00
parent 51d8fd409e
commit 5706e9a6a5
15 changed files with 732 additions and 162 deletions
@@ -12,6 +12,15 @@ final class ClinicalKnowledgeReference
return TcmAncientBooksReference::augmentQuery(NihaixiaClinicalSkill::augmentQuery($query));
}
/** @param list<array<string,mixed>> $ancientBookSources */
public static function augmentQueryWithAncientBookSources(string $query, array $ancientBookSources): string
{
return TcmAncientBooksReference::augmentQueryWithSources(
NihaixiaClinicalSkill::augmentQuery($query),
$ancientBookSources
);
}
/** @param array<int,array<string,mixed>> $messages
* @return array<int,array<string,mixed>>
*/
@@ -79,7 +79,7 @@ class DifyChatService
$ancientBookSources = ClinicalKnowledgeReference::ancientBookSources($query);
try {
$query = ClinicalKnowledgeReference::augmentQuery($query);
$query = ClinicalKnowledgeReference::augmentQueryWithAncientBookSources($query, $ancientBookSources);
} catch (\RuntimeException $error) {
return self::error('SKILL_UNAVAILABLE', '临床 AI 参考资料不可用');
}
@@ -239,7 +239,7 @@ class DifyChatService
$ancientBookSources = ClinicalKnowledgeReference::ancientBookSources($query);
try {
$query = ClinicalKnowledgeReference::augmentQuery($query);
$query = ClinicalKnowledgeReference::augmentQueryWithAncientBookSources($query, $ancientBookSources);
} catch (\RuntimeException $error) {
return self::error('SKILL_UNAVAILABLE', '临床 AI 参考资料不可用');
}
@@ -163,7 +163,16 @@ final class TcmAncientBooksReference
if (str_contains($query, self::MARKER)) {
return $query;
}
$reference = self::referenceForText($query);
return self::augmentQueryWithSources($query, self::sourcesForText($query));
}
/** @param list<array<string,mixed>> $sources */
public static function augmentQueryWithSources(string $query, array $sources): string
{
if (str_contains($query, self::MARKER)) {
return $query;
}
$reference = self::referenceForSources($sources);
return $reference === '' ? $query : $reference . "\n\n" . $query;
}
@@ -193,7 +202,12 @@ final class TcmAncientBooksReference
public static function referenceForText(string $text): string
{
$sources = self::sourcesForText($text);
return self::referenceForSources(self::sourcesForText($text));
}
/** @param list<array<string,mixed>> $sources */
public static function referenceForSources(array $sources): string
{
if ($sources === []) {
return '';
}