Skip to content

Commit

Permalink
Merge pull request #104 from UN-OCHA/develop
Browse files Browse the repository at this point in the history
v1.9.0
  • Loading branch information
orakili authored Jan 28, 2025
2 parents bd199be + b4bda9d commit c273914
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
17 changes: 17 additions & 0 deletions modules/ocha_ai_chat/src/Form/OchaAiChatChatForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Ajax\HtmlCommand;
use Drupal\Core\Ajax\InvokeCommand;
use Drupal\Core\Ajax\MessageCommand;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Database\Connection;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
Expand Down Expand Up @@ -408,6 +409,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ?bool $po
$form['#suffix'] = '</div>';
$form['actions']['submit']['#attributes']['class'][] = 'use-ajax-submit';
$form['actions']['submit']['#ajax'] = [
'callback' => '::ajaxSubmitCallback',
'wrapper' => $id,
'disable-refocus' => TRUE,
'progress' => [
Expand All @@ -423,6 +425,21 @@ public function buildForm(array $form, FormStateInterface $form_state, ?bool $po
return $form;
}

/**
* Ajax callback for form submission.
*/
public function ajaxSubmitCallback(array &$form, FormStateInterface $form_state): AjaxResponse {
$response = new AjaxResponse();

// Replace the entire form.
$response->addCommand(new ReplaceCommand('#' . $form['actions']['submit']['#ajax']['wrapper'], $form));

// Set focus on the 'question' element.
$response->addCommand(new InvokeCommand('[data-drupal-selector="edit-question"]', 'focus'));

return $response;
}

/**
* {@inheritdoc}
*/
Expand Down
4 changes: 2 additions & 2 deletions modules/ocha_ai_tag/src/Services/OchaAiTagTagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ protected function getSimilarTerms(array $embeddings, bool $average_embeddings =
$embeddings = [
VectorHelper::mean($embeddings),
];
};
}

$results = [];
foreach ($this->getTermEmbeddings() as $vocabulary => $terms) {
Expand Down Expand Up @@ -391,7 +391,7 @@ protected function getSimilarityScoreCutOff(array $similarity_scores, ?float $al
$variance = 0.0;
foreach ($similarity_scores as $value) {
$variance += pow((float) $value - $mean, 2);
};
}
$deviation = (float) sqrt($variance / ($sample ? $count - 1 : $count));

// Calculate the similarity cut-off.
Expand Down
6 changes: 3 additions & 3 deletions src/Helpers/LocalizationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ class LocalizationHelper {
*
* @var array
*/
static protected array $collators;
protected static array $collators;

/**
* Store the instantiated formatters per language.
*
* @var array
*/
static protected array $formatters;
protected static array $formatters;

/**
* Store the default language.
*
* @var string
*/
static protected string $defaultLanguage;
protected static string $defaultLanguage;

/**
* Sort an array using a collator for the given language, perserving the keys.
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/VectorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function getSimilarityScoreCutOff(array $similarity_scores, float
$variance = 0.0;
foreach ($similarity_scores as $value) {
$variance += pow((float) $value - $mean, 2);
};
}
$deviation = (float) sqrt($variance / ($sample ? $count - 1 : $count));

// Calculate the similarity cut-off.
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/ocha_ai/VectorStore/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ protected function getSimilarityScoreCutOff(array $similarity_scores, ?float $al
$variance = 0.0;
foreach ($similarity_scores as $value) {
$variance += pow((float) $value - $mean, 2);
};
}
$deviation = (float) sqrt($variance / ($sample ? $count - 1 : $count));

// Calculate the similarity cut-off.
Expand Down

0 comments on commit c273914

Please sign in to comment.