ai_agents_test-1.0.0-alpha1/src/Plugin/AgentsParameterTest/LessThanTest.php

src/Plugin/AgentsParameterTest/LessThanTest.php
<?php

declare(strict_types=1);

namespace Drupal\ai_agents_test\Plugin\AgentsParameterTest;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\ai\Service\FunctionCalling\ExecutableFunctionCallInterface;
use Drupal\ai_agents_test\AgentsParameterTestPluginBase;
use Drupal\ai_agents_test\Attribute\AgentsParameterTest;

/**
 * Plugin implementation of the agents_parameter_test.
 */
#[AgentsParameterTest(
  id: 'less_than',
  label: new TranslatableMarkup('Less Than'),
  description: new TranslatableMarkup('Is the value less than the expected value.'),
)]
final class LessThanTest extends AgentsParameterTestPluginBase {

  /**
   * {@inheritdoc}
   */
  public function runTest(ExecutableFunctionCallInterface $tool, array $values, string $parameter_name, array $rule, string $tool_name): void {
    $expected_value = $rule['value'];
    $actual = $values[$parameter_name];
    if (!is_numeric($actual) || $actual > $expected_value) {
      $error_message = sprintf('Parameter %s for tool %s was not less than %s or not a number.', $parameter_name, $tool->getPluginId(), $expected_value);
      $this->errors[] = $error_message;
      $this->details[] = $this->createDetailedResultRow(
        result: FALSE,
        object: "Tool: $tool_name, Parameter: $parameter_name",
        type: 'Less Than',
        expected: $expected_value,
        actual: (string) $actual,
        details: $error_message,
      );
    }
    else {
      $this->details[] = $this->createDetailedResultRow(
        result: TRUE,
        object: "Tool: $tool_name, Parameter: $parameter_name",
        type: 'Less Than',
        expected: $expected_value,
        actual: (string) $actual,
        details: '',
      );
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc