p43A
This commit is contained in:
@@ -11,6 +11,7 @@ final class PromptBuilderConfig
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly array $config = [],
|
||||
private readonly ?DomainVocabularyConfig $vocabulary = null,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -159,6 +160,35 @@ final class PromptBuilderConfig
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function getConfiguredStringListOrVocabularyView(string $configPath, string $viewPathConfigPath): array
|
||||
{
|
||||
if ($this->hasPath($configPath)) {
|
||||
return $this->getRequiredStringList($configPath);
|
||||
}
|
||||
|
||||
if ($this->vocabulary === null) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'RetrieX prompt config path "%s" is missing and no vocabulary resolver is available.',
|
||||
$configPath
|
||||
));
|
||||
}
|
||||
|
||||
$viewPath = $this->getRequiredString($viewPathConfigPath);
|
||||
$terms = $this->vocabulary->view($viewPath, []);
|
||||
|
||||
if ($terms === []) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'RetrieX prompt vocabulary view "%s" resolved to an empty list.',
|
||||
$viewPath
|
||||
));
|
||||
}
|
||||
|
||||
return $terms;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
@@ -193,6 +223,21 @@ final class PromptBuilderConfig
|
||||
|
||||
|
||||
|
||||
private function hasPath(string $path): bool
|
||||
{
|
||||
$current = $this->config;
|
||||
|
||||
foreach (explode('.', $path) as $segment) {
|
||||
if (!is_array($current) || !array_key_exists($segment, $current)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$current = $current[$segment];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getOptionalValue(string $path): mixed
|
||||
{
|
||||
$current = $this->config;
|
||||
@@ -573,7 +618,10 @@ final class PromptBuilderConfig
|
||||
*/
|
||||
public function getTechnicalProductKeywords(): array
|
||||
{
|
||||
return $this->getRequiredStringList('technical_product_keywords');
|
||||
return $this->getConfiguredStringListOrVocabularyView(
|
||||
'technical_product_keywords',
|
||||
'vocabulary_views.technical_product_keywords'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -581,7 +629,10 @@ final class PromptBuilderConfig
|
||||
*/
|
||||
public function getAccessoryRequestKeywords(): array
|
||||
{
|
||||
return $this->getRequiredStringList('accessory_request_keywords');
|
||||
return $this->getConfiguredStringListOrVocabularyView(
|
||||
'accessory_request_keywords',
|
||||
'vocabulary_views.accessory_request_keywords'
|
||||
);
|
||||
}
|
||||
|
||||
public function getMeasurementEvidenceSectionLabel(): string
|
||||
|
||||
Reference in New Issue
Block a user