Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CI) Improvement: Requests summary when body txt is changed. DIG-3968 #3366

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/acquia_dev/config_ignore.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.*'
Expand Down
1 change: 1 addition & 0 deletions config/acquia_prod/config_ignore.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.*'
Expand Down
1 change: 1 addition & 0 deletions config/acquia_stage/config_ignore.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ 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;
}
return self::buildConversation($options["prompt"], $options["text"], $options["conversation"] ?? [], $options["num_results"] ?? 5, $options["include_citations"] ?? TRUE);

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
8 changes: 8 additions & 0 deletions docroot/modules/custom/bos_core/bos_core.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

/**
Expand Down Expand Up @@ -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;
}
26 changes: 23 additions & 3 deletions docroot/modules/custom/bos_core/src/Form/BosCoreSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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' => '<span id="edit-rewrite-result"></span>',
],
],

Expand Down Expand Up @@ -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("<span id='edit-rewrite-result' style='color:green'><b>&#x2714; Success:</b> Authentication and Service Config are OK.</span>")];
}

}