p43Q
This commit is contained in:
@@ -189,6 +189,49 @@ final class PromptBuilderConfig
|
||||
return $terms;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string[]>
|
||||
*/
|
||||
private function getVocabularyStringListMap(string $mapPathConfigPath): array
|
||||
{
|
||||
if (!$this->hasPath($mapPathConfigPath)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->vocabulary === null) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'RetrieX prompt vocabulary map config path "%s" is set but no vocabulary resolver is available.',
|
||||
$mapPathConfigPath
|
||||
));
|
||||
}
|
||||
|
||||
$mapPath = $this->getRequiredString($mapPathConfigPath);
|
||||
$map = $this->vocabulary->map($mapPath, []);
|
||||
|
||||
if ($map === []) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'RetrieX prompt vocabulary map "%s" resolved to an empty map.',
|
||||
$mapPath
|
||||
));
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $item
|
||||
* @param array<string, string[]> $vocabularyMap
|
||||
* @return string[]
|
||||
*/
|
||||
private function getParameterStringList(array $item, string $id, string $localKey, array $vocabularyMap): array
|
||||
{
|
||||
if (array_key_exists($localKey, $item)) {
|
||||
return $this->normalizeMixedStringList($item[$localKey]);
|
||||
}
|
||||
|
||||
return $vocabularyMap[$id] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
@@ -735,7 +778,10 @@ final class PromptBuilderConfig
|
||||
*/
|
||||
public function getMeasurementEvidenceAccessoryLookupGuardTerms(): array
|
||||
{
|
||||
return $this->getRequiredStringList('measurement_evidence_guard.accessory_lookup_guard_terms');
|
||||
return $this->getConfiguredStringListOrVocabularyView(
|
||||
'measurement_evidence_guard.accessory_lookup_guard_terms',
|
||||
'measurement_evidence_guard.vocabulary_views.accessory_lookup_guard_terms'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -743,7 +789,10 @@ final class PromptBuilderConfig
|
||||
*/
|
||||
public function getMeasurementEvidenceAccessoryLookupPassthroughTerms(): array
|
||||
{
|
||||
return $this->getRequiredStringList('measurement_evidence_guard.accessory_lookup_passthrough_terms');
|
||||
return $this->getConfiguredStringListOrVocabularyView(
|
||||
'measurement_evidence_guard.accessory_lookup_passthrough_terms',
|
||||
'measurement_evidence_guard.vocabulary_views.accessory_lookup_passthrough_terms'
|
||||
);
|
||||
}
|
||||
|
||||
public function getMeasurementEvidenceRuleTemplate(string $key): string
|
||||
@@ -783,6 +832,9 @@ final class PromptBuilderConfig
|
||||
$out = [];
|
||||
$genericPositiveContextTerms = $this->getMeasurementEvidenceGenericPositiveContextTerms();
|
||||
$genericNegativeContextTerms = $this->getMeasurementEvidenceGenericNegativeContextTerms();
|
||||
$requestTermsByParameter = $this->getVocabularyStringListMap('measurement_evidence_guard.vocabulary_maps.request_terms');
|
||||
$positiveTermsByParameter = $this->getVocabularyStringListMap('measurement_evidence_guard.vocabulary_maps.positive_terms');
|
||||
$nonEquivalentTermsByParameter = $this->getVocabularyStringListMap('measurement_evidence_guard.vocabulary_maps.non_equivalent_terms');
|
||||
|
||||
foreach ($value as $item) {
|
||||
if (!is_array($item)) {
|
||||
@@ -799,15 +851,15 @@ final class PromptBuilderConfig
|
||||
$out[] = [
|
||||
'id' => $id,
|
||||
'label' => $label,
|
||||
'request_terms' => $this->normalizeMixedStringList($item['request_terms'] ?? []),
|
||||
'positive_terms' => $this->normalizeMixedStringList($item['positive_terms'] ?? []),
|
||||
'request_terms' => $this->getParameterStringList($item, $id, 'request_terms', $requestTermsByParameter),
|
||||
'positive_terms' => $this->getParameterStringList($item, $id, 'positive_terms', $positiveTermsByParameter),
|
||||
'positive_context_terms' => array_key_exists('positive_context_terms', $item)
|
||||
? $this->normalizeMixedStringList($item['positive_context_terms'])
|
||||
: $genericPositiveContextTerms,
|
||||
'negative_context_terms' => array_key_exists('negative_context_terms', $item)
|
||||
? $this->normalizeMixedStringList($item['negative_context_terms'])
|
||||
: $genericNegativeContextTerms,
|
||||
'non_equivalent_terms' => $this->normalizeMixedStringList($item['non_equivalent_terms'] ?? []),
|
||||
'non_equivalent_terms' => $this->getParameterStringList($item, $id, 'non_equivalent_terms', $nonEquivalentTermsByParameter),
|
||||
'safe_no_evidence_answer_de' => isset($item['safe_no_evidence_answer_de']) && is_scalar($item['safe_no_evidence_answer_de'])
|
||||
? trim((string) $item['safe_no_evidence_answer_de'])
|
||||
: '',
|
||||
|
||||
Reference in New Issue
Block a user