From 38e2f3d152849015cb0d11dad63dd6459fa4e4b8 Mon Sep 17 00:00:00 2001 From: "Peter Droogmans (attiks)" Date: Tue, 23 Apr 2024 15:55:55 +0200 Subject: [PATCH 1/4] chore: Use ara, not Arabic --- .../custom/ocha_ai_summarize/ocha_ai_summarize.module | 1 + .../src/Plugin/QueueWorker/OchaAiSummarizeActionPoints.php | 7 +++++++ .../src/Plugin/QueueWorker/OchaAiSummarizeExtractText.php | 3 +++ .../src/Plugin/QueueWorker/OchaAiSummarizeSummarize.php | 7 +++++++ 4 files changed, 18 insertions(+) diff --git a/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module b/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module index e187482..4865be9 100644 --- a/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module +++ b/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module @@ -1359,6 +1359,7 @@ function ocha_ai_summarize_get_lang_name($code) { function ocha_ai_summarize_get_lang_code($code) { $lang_codes = [ 'Arabic' => 'ar', + 'ara' => 'ar', 'chi_sim' => 'zh-hans', 'eng' => 'en', 'fra' => 'fr', diff --git a/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeActionPoints.php b/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeActionPoints.php index ff9d1ec..ef04408 100644 --- a/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeActionPoints.php +++ b/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeActionPoints.php @@ -56,7 +56,14 @@ public function processItem($data) { $bot = $data->brain ?? 'openai'; $nid = $data->nid; $document_language = $data->language ?? 'eng'; + if ($document_language == 'Arabic') { + $document_language = 'ara'; + } + $output_language = $data->output_language ?? 'eng'; + if ($output_language == 'Arabic') { + $output_language = 'ara'; + } if (empty($nid)) { return; diff --git a/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeExtractText.php b/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeExtractText.php index 3aa1f89..3383c20 100644 --- a/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeExtractText.php +++ b/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeExtractText.php @@ -62,6 +62,9 @@ public static function create(ContainerInterface $container, array $configuratio public function processItem($data) { $nid = $data->nid; $document_language = $data->language ?? 'eng'; + if ($document_language == 'Arabic') { + $document_language = 'ara'; + } if (empty($nid)) { return; diff --git a/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeSummarize.php b/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeSummarize.php index c23e2d0..9f34671 100644 --- a/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeSummarize.php +++ b/html/modules/custom/ocha_ai_summarize/src/Plugin/QueueWorker/OchaAiSummarizeSummarize.php @@ -57,7 +57,14 @@ public function processItem($data) { $nid = $data->nid; $num_paragraphs = $data->num_paragraphs; $document_language = $data->language ?? 'eng'; + if ($document_language == 'Arabic') { + $document_language = 'ara'; + } + $output_language = $data->output_language ?? 'eng'; + if ($output_language == 'Arabic') { + $output_language = 'ara'; + } if (empty($nid)) { return; From 99e1dfaa2503bcedf1687302e695d9e48f889796 Mon Sep 17 00:00:00 2001 From: "Peter Droogmans (attiks)" Date: Tue, 23 Apr 2024 15:56:35 +0200 Subject: [PATCH 2/4] chore: Limit bedrock max tokens --- html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module b/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module index 4865be9..04b3113 100644 --- a/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module +++ b/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module @@ -1288,7 +1288,7 @@ function ocha_ai_summarize_check_length($text, $bot) { break; case 'bedrock': - $max_tokens = 3.5 * 42000; + $max_tokens = 2 * 42000; break; } From 6adf38e9b6cf7671b82f011472f2da0fd93f6adc Mon Sep 17 00:00:00 2001 From: "Peter Droogmans (attiks)" Date: Wed, 24 Apr 2024 09:07:29 +0200 Subject: [PATCH 3/4] bug: Nested elements in docx Refs: OPS-10321 --- .../ocha_ai_summarize/ocha_ai_summarize.module | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module b/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module index 04b3113..fb9f971 100644 --- a/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module +++ b/html/modules/custom/ocha_ai_summarize/ocha_ai_summarize.module @@ -25,6 +25,7 @@ use GuzzleHttp\Exception\ClientException; use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; use OpenAI\Client; +use PhpOffice\PhpWord\Element\TextRun; use PhpOffice\PhpWord\IOFactory; use Psr\Http\Message\ResponseInterface; use Symfony\Component\Process\Process; @@ -799,7 +800,16 @@ function ocha_ai_summarize_extract_pages_from_doc($filename, $document_language } } elseif (method_exists($element, 'getText')) { - $text .= $element->getText() . "\n"; + $t = $element->getText(); + if (is_string($t)) { + $text .= $element->getText() . "\n"; + } + elseif ($t instanceof TextRun) { + $text .= $t->getText() . "\n"; + } + else { + // Ignore it. + } } } From d7f920e65acbaf0f36e040f153d6bdb9dec05688 Mon Sep 17 00:00:00 2001 From: "Peter Droogmans (attiks)" Date: Wed, 24 Apr 2024 09:20:57 +0200 Subject: [PATCH 4/4] Add patch to prevent php notice from Drupal core PHP mailer --- PATCHES/core--drupal--3418098-php-mailer.patch | 13 +++++++++++++ composer.patches.json | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 PATCHES/core--drupal--3418098-php-mailer.patch diff --git a/PATCHES/core--drupal--3418098-php-mailer.patch b/PATCHES/core--drupal--3418098-php-mailer.patch new file mode 100644 index 0000000..fe43323 --- /dev/null +++ b/PATCHES/core--drupal--3418098-php-mailer.patch @@ -0,0 +1,13 @@ +diff --git a/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php b/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php +index 09a56006a6..1767dc4875 100644 +--- a/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php ++++ b/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php +@@ -113,7 +113,7 @@ public function mail(array $message) { + $mail_body = preg_replace('@\r?\n@', $line_endings, $message['body']); + $mail_headers = $headers->toString(); + +- if (!$this->request->server->has('WINDIR') && !str_contains($this->request->server->get('SERVER_SOFTWARE'), 'Win32')) { ++ if (!$this->request->server->has('WINDIR') && !str_contains($this->request->server->get('SERVER_SOFTWARE', ''), 'Win32')) { + // On most non-Windows systems, the "-f" option to the sendmail command + // is used to set the Return-Path. There is no space between -f and + // the value of the return path. diff --git a/composer.patches.json b/composer.patches.json index 4590bbe..56df7a9 100644 --- a/composer.patches.json +++ b/composer.patches.json @@ -3,6 +3,9 @@ "drupal/admin_feedback": { "https://www.drupal.org/project/admin_feedback/issues/3389123": "https://www.drupal.org/files/issues/2023-09-22/admin_feedback-install_from_config-3112866-2.patch" }, + "drupal/core": { + "https://www.drupal.org/project/drupal/issues/3418098": "PATCHES/core--drupal--3418098-php-mailer.patch" + }, "drupal/csp": { "Simplify log format": "PATCHES/csp-log-format.patch" },