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

src/Plugin/AgentsParameterTest/NotOneOfTest.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: 'not_one_of',
  label: new TranslatableMarkup('Not One Of'),
  description: new TranslatableMarkup('Is the value not one of the expected values.'),
)]
final class NotOneOfTest extends AgentsParameterTestPluginBase {

  /**
   * {@inheritdoc}
   */
  public function runTest(ExecutableFunctionCallInterface $tool, array $values, string $parameter_name, array $rule, string $tool_name): void {
    $possible_values = array_map('trim', explode(',', $rule['value']));
    $actual = $values[$parameter_name];
    if (in_array($actual, $possible_values)) {
      $error_message = sprintf('Parameter %s for tool %s was one of %s.', $parameter_name, $tool->getPluginId(), implode(', ', $possible_values));
      $this->errors[] = $error_message;
      $this->details[] = $this->createDetailedResultRow(
        result: FALSE,
        object: "Tool: $tool_name, Parameter: $parameter_name",
        type: 'Not One Of',
        expected: implode(', ', $possible_values),
        actual: $actual,
        details: $error_message,
      );
    }
    else {
      $this->details[] = $this->createDetailedResultRow(
        result: TRUE,
        object: "Tool: $tool_name, Parameter: $parameter_name",
        type: 'Not One Of',
        expected: implode(', ', $possible_values),
        actual: $actual,
        details: '',
      );
    }
  }

}

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

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