From 30e6eb16d09fddef2af91ec7102a2cd9c0770539 Mon Sep 17 00:00:00 2001 From: David Upton Date: Tue, 5 Mar 2024 17:29:13 -0500 Subject: [PATCH] DIG-3968 Improvement: Requests summary when body txt is changed. --- config/acquia_dev/config_ignore.settings.yml | 1 + config/acquia_prod/config_ignore.settings.yml | 1 + .../acquia_stage/config_ignore.settings.yml | 1 + .../src/GcGenerationPayload.php | 4 +-- .../bos_google_cloud/src/GcGenerationURL.php | 4 +-- .../src/Services/GcConversation.php | 2 +- .../src/Services/GcSearch.php | 2 +- .../src/Services/GcTextRewriter.php | 4 +-- .../src/Services/GcTextSummarizer.php | 4 +-- .../src/Services/GcTranslation.php | 4 +-- .../modules/bos_list/bos_list.module | 10 ++++--- .../modules/custom/bos_core/bos_core.module | 8 ++++++ .../bos_core/src/Form/BosCoreSettingsForm.php | 26 ++++++++++++++++--- 13 files changed, 53 insertions(+), 18 deletions(-) diff --git a/config/acquia_dev/config_ignore.settings.yml b/config/acquia_dev/config_ignore.settings.yml index ea5f2b543d..8a1703ea7b 100644 --- a/config/acquia_dev/config_ignore.settings.yml +++ b/config/acquia_dev/config_ignore.settings.yml @@ -4,6 +4,7 @@ ignored_config_entities: - bos_city_score.settings - bos_core.settings - bos_emergency_alerts.settings + - bos_google_cloud.settings - bos_mnl.settings - bos_swiftype.settings - 'core.entity_view_display.node.metrolist_development.*' diff --git a/config/acquia_prod/config_ignore.settings.yml b/config/acquia_prod/config_ignore.settings.yml index 9791ce086d..c8cf50b5dc 100644 --- a/config/acquia_prod/config_ignore.settings.yml +++ b/config/acquia_prod/config_ignore.settings.yml @@ -4,6 +4,7 @@ ignored_config_entities: - bos_city_score.settings - bos_core.settings - bos_emergency_alerts.settings + - bos_google_cloud.settings - bos_mnl.settings - bos_swiftype.settings - 'core.entity_view_display.node.metrolist_development.*' diff --git a/config/acquia_stage/config_ignore.settings.yml b/config/acquia_stage/config_ignore.settings.yml index 3dc4a27930..98043526eb 100644 --- a/config/acquia_stage/config_ignore.settings.yml +++ b/config/acquia_stage/config_ignore.settings.yml @@ -4,6 +4,7 @@ ignored_config_entities: - bos_city_score.settings - bos_core.settings - bos_emergency_alerts.settings + - bos_google_cloud.settings - bos_mnl.settings - bos_swiftype.settings - 'core.entity_view_display.node.metrolist_development.*' diff --git a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/GcGenerationPayload.php b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/GcGenerationPayload.php index 951dce5cf2..f29d573079 100644 --- a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/GcGenerationPayload.php +++ b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/GcGenerationPayload.php @@ -46,7 +46,7 @@ public static function build(int $type, array $options):array|bool { case self::CONVERSATION: if (empty($options["text"]) || empty($options["prompt"])) { - Drupal::logger("google_cloud") + Drupal::logger("bos_google_cloud") ->error("Require Text and Prompt in payload (prompt:{$options["prompt"]},text:{$options["text"]}"); return FALSE; } @@ -54,7 +54,7 @@ public static function build(int $type, array $options):array|bool { case self::PREDICTION: if (empty($options["prediction"]) || empty($options["generation_config"])) { - Drupal::logger("google_cloud") + Drupal::logger("bos_google_cloud") ->error("Require Prediction and Generation Config in payload.",['referer' => __METHOD__]); return FALSE; } diff --git a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/GcGenerationURL.php b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/GcGenerationURL.php index 3c7b086ffe..fcc93ef8bc 100644 --- a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/GcGenerationURL.php +++ b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/GcGenerationURL.php @@ -123,7 +123,7 @@ public static function quota_exceeded(int $type): bool { default: // Unknown call type, - Drupal::logger("google_cloud") + Drupal::logger("bos_google_cloud") ->error("Unknown Payload type $type"); return TRUE; } @@ -141,7 +141,7 @@ public static function quota_exceeded(int $type): bool { return FALSE; } - Drupal::logger("google_cloud") + Drupal::logger("bos_google_cloud") ->warning("Quota limit of ($max_requests per $flood_window seconds) reached for $name:$id"); return TRUE; diff --git a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcConversation.php b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcConversation.php index 172a7accc3..6e2ca054b9 100644 --- a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcConversation.php +++ b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcConversation.php @@ -49,7 +49,7 @@ class GcConversation extends BosCurlControllerBase implements GcServiceInterface public function __construct(LoggerChannelFactory $logger, ConfigFactory $config) { // Load the service-supplied variables. - $this->log = $logger->get('GcAuthenticator'); + $this->log = $logger->get('bos_google_cloud'); $this->config = $config->get("bos_google_cloud.settings"); $this->settings = CobSettings::getSettings("GCAPI_SETTINGS", "bos_google_cloud"); diff --git a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcSearch.php b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcSearch.php index 2678289dc5..935ccae6de 100644 --- a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcSearch.php +++ b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcSearch.php @@ -49,7 +49,7 @@ class GcSearch extends BosCurlControllerBase implements GcServiceInterface { public function __construct(LoggerChannelFactory $logger, ConfigFactory $config) { // Load the service-supplied variables. - $this->log = $logger->get('GcAuthenticator'); + $this->log = $logger->get('bos_google_cloud'); $this->config = $config->get("bos_google_cloud.settings"); $this->settings = CobSettings::getSettings("GCAPI_SETTINGS", "bos_google_cloud"); diff --git a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTextRewriter.php b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTextRewriter.php index 5e35e76ef6..bc047fc947 100644 --- a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTextRewriter.php +++ b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTextRewriter.php @@ -45,11 +45,11 @@ class GcTextRewriter extends BosCurlControllerBase implements GcServiceInterface public function __construct(LoggerChannelFactory $logger, ConfigFactory $config, GcCacheAI $cache) { // Load the service-supplied variables. - $this->log = $logger->get('GcAuthenticator'); + $this->log = $logger->get('bos_google_cloud'); $this->config = $config->get("bos_google_cloud.settings"); $this->ai_cache = $cache; - $this->ai_cache->setExpiry($this->config->get("{$this::id()}.cache")); + $this->ai_cache->setExpiry($this->config->get("{$this::id()}.cache") ?? GcCacheAI::PERMANENT); $this->settings = CobSettings::getSettings("GCAPI_SETTINGS", "bos_google_cloud"); diff --git a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTextSummarizer.php b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTextSummarizer.php index 5a4c4e296c..6553a4e8ab 100644 --- a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTextSummarizer.php +++ b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTextSummarizer.php @@ -46,7 +46,7 @@ public function __construct(LoggerChannelFactory $logger, ConfigFactory $config, $this->config = $config->get("bos_google_cloud.settings"); $this->ai_cache = $cache; - $this->ai_cache->setExpiry($this->config->get("{$this::id()}.cache")); + $this->ai_cache->setExpiry($this->config->get("{$this::id()}.cache") ?? GcCacheAI::PERMANENT); $this->settings = CobSettings::getSettings("GCAPI_SETTINGS", "bos_google_cloud"); @@ -441,7 +441,7 @@ public function submitForm(array $form, FormStateInterface $form_state): void { ||$config->get("{$this::id()}.model_id") !== $values['model_id'] ||$config->get("{$this::id()}.location_id") !== $values['location_id'] ||$config->get("{$this::id()}.service_account") !== $values['service_account'] - ||$config->get("{$this::id()}.endpoint") !== $values['enAdpoint'] + ||$config->get("{$this::id()}.endpoint") !== $values['endpoint'] ||$config->get("{$this::id()}.cache") !== $values['cache']) { $config->set("{$this::id()}.project_id", $values['project_id']) ->set("{$this::id()}.model_id", $values['model_id']) diff --git a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTranslation.php b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTranslation.php index dfe36b797d..092f459810 100644 --- a/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTranslation.php +++ b/docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Services/GcTranslation.php @@ -42,11 +42,11 @@ class GcTranslation extends BosCurlControllerBase implements GcServiceInterface public function __construct(LoggerChannelFactory $logger, ConfigFactory $config, GcCacheAI $cache) { // Load the service-supplied variables. - $this->log = $logger->get('GcAuthenticator'); + $this->log = $logger->get('bos_google_cloud'); $this->config = $config->get("bos_google_cloud.settings"); $this->ai_cache = $cache; - $this->ai_cache->setExpiry($this->config->get("{$this::id()}.cache")); + $this->ai_cache->setExpiry($this->config->get("{$this::id()}.cache") ?? GcCacheAI::PERMANENT); $this->settings = CobSettings::getSettings("GCAPI_SETTINGS", "bos_google_cloud"); diff --git a/docroot/modules/custom/bos_components/modules/bos_list/bos_list.module b/docroot/modules/custom/bos_components/modules/bos_list/bos_list.module index 35ed024090..07d781b653 100644 --- a/docroot/modules/custom/bos_components/modules/bos_list/bos_list.module +++ b/docroot/modules/custom/bos_components/modules/bos_list/bos_list.module @@ -258,13 +258,17 @@ function bos_list_paragraph_list_summary_alter(array $form_widget, array $para, /** * Implements hook_theme_suggestions_alter(). */ -function bos_list_theme_suggestions_alter(array &$suggestions, array $variables, $hook) { +function bos_list_theme_suggestions_alter(array &$suggestions, array $variables, string $hook) { if ($hook == 'fieldset' || $hook == 'checkboxes' || $hook == 'bef_checkboxes') { if (isset($variables["element"]["#theme"])) { $suggestions[] = $hook . '_' . $variables["element"]["#theme"]; } - if (isset($variables["element"]["#name"])) { - $suggestions[] = $hook . '_' . $variables["element"]["#name"]; + if (isset($variables["element"]["#parents"])) { + $suggestion = $hook . "_"; + foreach($variables["element"]["#parents"] as $parent) { + $suggestion .= "_$parent"; + } + $suggestions[] = $suggestion; } } if ($hook == 'input') { diff --git a/docroot/modules/custom/bos_core/bos_core.module b/docroot/modules/custom/bos_core/bos_core.module index ba2bc6639b..dac83e20b1 100644 --- a/docroot/modules/custom/bos_core/bos_core.module +++ b/docroot/modules/custom/bos_core/bos_core.module @@ -66,6 +66,7 @@ function bos_core_form_alter(array &$form, FormStateInterface $form_state):void && !in_array('administrator', Drupal::currentUser()->getRoles())) { $form['actions']['preview']['#access'] = false; } + } /** @@ -1058,3 +1059,10 @@ function bos_core_node_load($entities):void { function bos_core_preprocess_username(&$variables) { realname_extension_preprocess_username($variables); } + +/** + * Implements hook_preprocess_HOOK(). + */ +function bos_core_preprocess_input__checkbox(&$variables) { + return; +} diff --git a/docroot/modules/custom/bos_core/src/Form/BosCoreSettingsForm.php b/docroot/modules/custom/bos_core/src/Form/BosCoreSettingsForm.php index af7944d9cb..d1f3d3fa09 100644 --- a/docroot/modules/custom/bos_core/src/Form/BosCoreSettingsForm.php +++ b/docroot/modules/custom/bos_core/src/Form/BosCoreSettingsForm.php @@ -4,6 +4,7 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Render\Markup; /** * Admin Settings form for bos_core. @@ -142,10 +143,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#description' => t('Note: Only the body field will be summarized.'), '#default_value' => array_merge($def_content_types, $ssettings['content_types']??[]), '#options' => $content_types, - '#attributes' => [ - "placeholder" => 'https://patterns.boston.gov/assets/icons/manifest.txt', - ], '#required' => TRUE, +// '#ajax' => [ +// 'callback' => [$this, '::ajaxFormHandler'], +// 'event' => 'click', +// 'wrapper' => 'edit-rewrite-result', +// 'disable-refocus' => TRUE, +// 'progress' => [ +// 'type' => 'throbber', +// ] +// ], +// '#suffix' => '', ], ], @@ -184,4 +192,16 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } + /** + * Helper to listen for Ajax callbacks, and redirect to correct service. + * + * @param array $form + * @param \Drupal\Core\Form\FormStateInterface $form_state + * + * @return array + */ + public function ajaxFormHandler(array &$form, FormStateInterface $form_state,$b,$c): array { + return ["#markup" => Markup::create("✔ Success: Authentication and Service Config are OK.")]; + } + }