Skip to content
Snippets Groups Projects
Commit 9a02171c authored by Marcus Johansson's avatar Marcus Johansson
Browse files

Issue #3442743 by Marcus_Johansson: Add bypass for three combinations

parent 9353fd9e
No related branches found
Tags 1.0.0-beta2
No related merge requests found
......@@ -162,6 +162,12 @@ class FileToTextBase extends AiInterpolatorFieldRule implements AiInterpolatorFi
'#default_value' => $fieldDefinition->getConfig($entity->bundle())->getThirdPartySetting('ai_interpolator', 'interpolator_unstructured_images', TRUE),
];
$form['interpolator_unstructured_bypass_unstructured'] = [
'#type' => 'checkbox',
'#title' => 'Bypass on perfect match',
'#description' => $this->t('This will bypass an API call if the input file is a text and the output is text, input file is md and the output is markdown or input file is html and the output is html.'),
'#default_value' => $fieldDefinition->getConfig($entity->bundle())->getThirdPartySetting('ai_interpolator', 'interpolator_unstructured_bypass_unstructured', TRUE),
];
return $form;
}
......@@ -175,6 +181,19 @@ class FileToTextBase extends AiInterpolatorFieldRule implements AiInterpolatorFi
foreach ($entity->{$interpolatorConfig['base_field']} as $entityWrapper) {
if ($entityWrapper->entity) {
$fileEntity = $entityWrapper->entity;
// Check if bypass is on.
if ($interpolatorConfig['unstructured_bypass_unstructured']) {
$fileType = $fileEntity->getMimeType();
$outputType = $interpolatorConfig['unstructured_output_format'];
if (
($fileType === 'text/plain' && $outputType === 'text') ||
($fileType === 'text/markdown' && $outputType === 'markdown') ||
($fileType === 'text/html' && $outputType === 'html')
) {
$values[] = file_get_contents($fileEntity->getFileUri());
continue;
}
}
$extract = [];
if ($interpolatorConfig['unstructured_images']) {
$extract = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment