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

src/Plugin/AgentsParameterTest/LlmTest.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;
use Drupal\ai_agents_test\Traits\LlmTestTrait;

/**
 * Plugin implementation of the agents_parameter_test.
 */
#[AgentsParameterTest(
  id: 'llm',
  label: new TranslatableMarkup('LLM Test'),
  description: new TranslatableMarkup('Test the value against a prompt.'),
)]
final class LlmTest extends AgentsParameterTestPluginBase {

  use LlmTestTrait;

  /**
   * {@inheritdoc}
   */
  public function runTest(ExecutableFunctionCallInterface $tool, array $values, string $parameter_name, array $rule, string $tool_name): void {
    $prompt = $rule['value'];
    $actual = $values[$parameter_name];
    $result = $this->testUsingLlm($prompt, $actual);
    if ($result['result'] === FALSE) {
      $error_message = sprintf('Parameter %s for tool %s was not correct - reason: %s.', $parameter_name, $tool->getPluginId(), $result['reasoning']);
      $this->errors[] = $error_message;
      $this->details[] = $this->createDetailedResultRow(
        result: FALSE,
        object: "Tool: $tool_name, Parameter: $parameter_name",
        type: 'LLM Check',
        expected: $prompt,
        actual: $actual,
        details: $result['reasoning'],
      );
    }
    else {
      $this->details[] = $this->createDetailedResultRow(
        result: TRUE,
        object: "Tool: $tool_name, Parameter: $parameter_name",
        type: 'LLM Check',
        expected: $prompt,
        actual: $actual,
        details: $result['reasoning'],
      );
    }
  }

}

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

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