更新
This commit is contained in:
@@ -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 '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user