ai_agents_test-1.0.0-alpha1/src/Entity/AgentTestResult.php

src/Entity/AgentTestResult.php
<?php

declare(strict_types=1);

namespace Drupal\ai_agents_test\Entity;

use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\ai_agents_test\AgentTestResultInterface;
use Drupal\user\EntityOwnerTrait;

/**
 * Defines the agent test result entity class.
 *
 * @ContentEntityType(
 *   id = "ai_agents_test_result",
 *   label = @Translation("Agent Test Result"),
 *   label_collection = @Translation("Agent Test Results"),
 *   label_singular = @Translation("agent test result"),
 *   label_plural = @Translation("agent test results"),
 *   label_count = @PluralTranslation(
 *     singular = "@count agent test results",
 *     plural = "@count agent test results",
 *   ),
 *   handlers = {
 *     "list_builder" = "Drupal\ai_agents_test\AgentTestResultListBuilder",
 *     "views_data" = "Drupal\views\EntityViewsData",
 *     "form" = {
 *       "add" = "Drupal\ai_agents_test\Form\AgentTestResultForm",
 *       "edit" = "Drupal\ai_agents_test\Form\AgentTestResultForm",
 *       "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm",
 *       "delete-multiple-confirm" = "Drupal\Core\Entity\Form\DeleteMultipleForm",
 *     },
 *     "route_provider" = {
 *       "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider",
 *     },
 *   },
 *   base_table = "ai_agents_test_result",
 *   admin_permission = "administer ai_agents_test_result",
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label",
 *     "uuid" = "uuid",
 *     "owner" = "uid",
 *   },
 *   links = {
 *     "collection" = "/admin/content/ai-agents-test/result",
 *     "add-form" = "/admin/content/ai-agents-test/result/add",
 *     "canonical" = "/admin/content/ai-agents-test/result/{ai_agents_test_result}",
 *     "edit-form" = "/admin/content/ai-agents-test/result/{ai_agents_test_result}/edit",
 *     "delete-form" = "/admin/content/ai-agents-test/result/{ai_agents_test_result}/delete",
 *     "delete-multiple-form" = "/admin/content/ai-agents-test/result/delete-multiple",
 *   },
 * )
 */
final class AgentTestResult extends ContentEntityBase implements AgentTestResultInterface {

  use EntityChangedTrait;
  use EntityOwnerTrait;

  /**
   * {@inheritdoc}
   */
  public function preSave(EntityStorageInterface $storage): void {
    parent::preSave($storage);
    if (!$this->getOwnerId()) {
      // If no owner has been set explicitly, make the anonymous user the owner.
      $this->setOwnerId(0);
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type): array {

    $fields = parent::baseFieldDefinitions($entity_type);

    $fields['label'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Label'))
      ->setRequired(TRUE)
      ->setSetting('max_length', 255)
      ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'weight' => -5,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'string',
        'weight' => -5,
      ])
      ->setDisplayConfigurable('view', TRUE);

    $fields['uid'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Author'))
      ->setSetting('target_type', 'user')
      ->setDefaultValueCallback(self::class . '::getDefaultEntityOwner')
      ->setDisplayOptions('form', [
        'type' => 'entity_reference_autocomplete',
        'settings' => [
          'match_operator' => 'CONTAINS',
          'size' => 60,
          'placeholder' => '',
        ],
        'weight' => 15,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'author',
        'weight' => 15,
      ])
      ->setDisplayConfigurable('view', TRUE);

    $fields['created'] = BaseFieldDefinition::create('created')
      ->setLabel(t('Authored on'))
      ->setDescription(t('The time that the agent test result was created.'))
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'timestamp',
        'weight' => 20,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('form', [
        'type' => 'datetime_timestamp',
        'weight' => 20,
      ])
      ->setDisplayConfigurable('view', TRUE);

    $fields['changed'] = BaseFieldDefinition::create('changed')
      ->setLabel(t('Changed'))
      ->setDescription(t('The time that the agent test result was last edited.'));

    $fields['test_id'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Test ID'))
      ->setDescription(t('The test ID of the agent test result.'))
      ->setSetting('target_type', 'ai_agents_test')
      ->setDisplayOptions('form', [
        'type' => 'entity_reference_autocomplete',
        'settings' => [
          'match_operator' => 'CONTAINS',
          'size' => 60,
          'placeholder' => '',
        ],
        'weight' => 10,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'string',
        'weight' => 10,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // Result can either be success, failure or inconclusive. Select list.
    $fields['result'] = BaseFieldDefinition::create('list_string')
      ->setLabel(t('Result'))
      ->setDescription(t('The result of the agent test.'))
      ->setSettings([
        'allowed_values' => [
          'success' => t('Success'),
          'failure' => t('Failure'),
          'inconclusive' => t('Inconclusive'),
        ],
      ])
      ->setDisplayOptions('form', [
        'type' => 'options_select',
        'weight' => 25,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'string',
        'weight' => 25,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // Summary results blob.
    $fields['summary_results'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('Summary Results'))
      ->setDescription(t('The summary results of the agent test.'))
      ->setDisplayOptions('form', [
        'type' => 'text_textarea',
        'weight' => 30,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'text_default',
        'weight' => 30,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // Detailed results blob.
    $fields['detailed_results'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('Detailed Results'))
      ->setDescription(t('The detailed results of the agent test.'))
      ->setDisplayOptions('form', [
        'type' => 'text_textarea',
        'weight' => 30,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'text_default',
        'weight' => 30,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // Error stack.
    $fields['error_stack'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('Error Stack'))
      ->setDescription(t('The error stack of the agent test.'))
      ->setDisplayOptions('form', [
        'type' => 'text_textarea',
        'weight' => 30,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'text_default',
        'weight' => 30,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // The actual error message.
    $fields['error_message'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('Error Message'))
      ->setDescription(t('The actual error message.'))
      ->setDisplayOptions('form', [
        'type' => 'text_textarea',
        'weight' => 30,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'text_default',
        'weight' => 30,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // The configuration of the agent that was tested.
    $fields['agent_configuration'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('Agent Configuration'))
      ->setDescription(t('The configuration of the agent that was tested.'))
      ->setDisplayOptions('form', [
        'type' => 'text_textarea',
        'weight' => 35,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'text_default',
        'weight' => 35,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // The md5 id of the agent that was tested.
    $fields['agent_version_id'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Agent Version ID'))
      ->setDescription(t('The md5 id of the agent that was tested.'))
      ->setSetting('max_length', 255)
      ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'weight' => 40,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'string',
        'weight' => 40,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // Tokenized system prompt.
    $fields['system_prompt'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('System Prompt'))
      ->setDescription(t('The tokenized system prompt used for the test.'))
      ->setDisplayOptions('form', [
        'type' => 'text_textarea',
        'weight' => 45,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'text_default',
        'weight' => 45,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // The chat provider used for the test.
    $fields['chat_provider'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Chat Provider'))
      ->setDescription(t('The chat provider used for the test.'))
      ->setSetting('max_length', 255)
      ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'weight' => 45,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'string',
        'weight' => 45,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // The model used for the test.
    $fields['model'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Model'))
      ->setDescription(t('The model used for the test.'))
      ->setSetting('max_length', 255)
      ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'weight' => 50,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'string',
        'weight' => 50,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // The configuration of the provider/model used for the test.
    $fields['provider_configuration'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('Provider Configuration'))
      ->setDescription(t('The configuration of the provider/model used for the test.'))
      ->setDisplayOptions('form', [
        'type' => 'text_textarea',
        'weight' => 55,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'text_default',
        'weight' => 55,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // The tools and parameters that was outputted as a blob.
    $fields['tools'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('Tools'))
      ->setDescription(t('The tools and parameters that was outputted as a blob.'))
      ->setDisplayOptions('form', [
        'type' => 'text_textarea',
        'weight' => 60,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'text_default',
        'weight' => 60,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // The textual response given by the agent.
    $fields['response'] = BaseFieldDefinition::create('string_long')
      ->setLabel(t('Response'))
      ->setDescription(t('The textual response given by the agent.'))
      ->setDisplayOptions('form', [
        'type' => 'text_textarea',
        'weight' => 65,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'text_default',
        'weight' => 65,
      ])
      ->setDisplayConfigurable('view', TRUE);

    // If it was a test group, the result of the test group.
    $fields['agent_test_group_result'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Agent Test Group Result'))
      ->setSetting('target_type', 'ai_agents_test_group_result')
      ->setSetting('handler_settings', [
        'target_bundles' => [
          'ai_agents_test_group_result' => 'ai_agents_test_group_result',
        ],
      ])
      ->setDisplayOptions('form', [
        'type' => 'entity_reference_autocomplete',
        'settings' => [
          'match_operator' => 'CONTAINS',
          'size' => 60,
          'placeholder' => '',
        ],
        'weight' => 40,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'entity_reference_label',
        'weight' => 40,
      ])
      ->setDisplayConfigurable('view', TRUE);

    return $fields;
  }

}

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

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