AI Field module allows you to add an AI type field. We can use AI field type as field which can be used to generate content using OpenAI API. For using this Field, first we need to set OpenAI "API key" in configuration form. Then user can add field of AI Field type and after adding required field settings we can use this field in Nodes for content generation using AI.

Project link

https://www.drupal.org/project/ai_field

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

    Comments

    abhishek.sa created an issue. See original summary.

    abhishek.sa’s picture

    Status: Active » Needs review
    abhishek.sa’s picture

    Project: AI Field » Drupal.org security advisory coverage applications
    Version: 1.0.x-dev »
    Component: Code » module
    Issue summary: View changes
    vishal.kadam’s picture

    Thank you for applying!

    Please read Review process for security advisory coverage: What to expect for more details and Security advisory coverage application checklist to understand what reviewers look for. Tips for ensuring a smooth review gives some hints for a smoother review.

    The important notes are the following.

    • If you have not done it yet, you should run phpcs --standard=Drupal,DrupalPractice on the project, which alone fixes most of what reviewers would report.
    • For the time this application is open, only your commits are allowed.
    • The purpose of this application is giving you a new drupal.org role that allows you to opt projects into security advisory coverage, either projects you already created, or projects you will create. The project status won't be changed by this application and no other user will be able to opt projects into security advisory policy.
    • We only accept an application per user. If you change your mind about the project to use for this application, or it is necessary to use a different project for the application, please update the issue summary with the link to the correct project and the issue title with the project name and the branch to review.

    To the reviewers

    Please read How to review security advisory coverage applications, Application workflow, What to cover in an application review, and Tools to use for reviews.

    The important notes are the following.

    • It is preferable to wait for a Code Review Administrator before commenting on newly created applications. Code Review Administrators will do some preliminary checks that are necessary before any change on the project files is suggested.
    • Reviewers should show the output of a CLI tool only once per application.
    • It may be best to have the applicant fix things before further review.

    For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues.

    vishal.kadam’s picture

    Title: [1.0.x] AI Field Module » [1.0.x] AI Field
    Issue summary: View changes
    avpaderno’s picture

    Status: Needs review » Needs work
    • The following points are just a start and don't necessarily encompass all of the changes that may be necessary
    • A specific point may just be an example and may apply in other places
    • A review is about code that doesn't follow the coding standards, contains possible security issue, or doesn't correctly use the Drupal API; the single points aren't ordered, not even by importance

    src/Controller/AIFieldController.php

    /**
     * An example controller.
     */
    class AIFieldController extends ControllerBase {
    

    The description in that comment is not for that controller class, which is not just an example controller.

    $open_ai_key = \Drupal::config('ai_field.settings')->get('openai_api_key');

    Any dependency a controller has must be injected using the dependency injection container.

        $answer = new AIFieldController();
        $model_key = $model_value;
        $model = $answer->listModels()[$model_key];
    

    Controller instances are never created that way.
    In this case, it is not even necessary, since that code is executed by a non-static method of that controller.

    src/Form/AIFieldConfigurationForm.php

      /**
       * {@inheritdoc}
       */
      public function validateForm(array &$form, FormStateInterface $form_state) {
      }
    

    There is no need to implement an empty method.

        $this->config('ai_field.settings')
          ->set('openai_api_key', $values['openai_api_key'])
          ->save();
        \Drupal::messenger()->addMessage(t('OpenAI API Key has been saved'));
    

    The parent class already shows a message about the settings being saved. I am not sure there is the need to add a specific message.

    ai_field.module

        $open_ai_key = \Drupal::config('ai_field.settings')->get('openai_api_key');
        if (empty($open_ai_key)) {
          $form['actions']['submit']['#disabled'] = TRUE;
          \Drupal::messenger()->addError(t('Can not add AI field without setting OpenAI API Key.'));
        }
    

    That is code for a validation handler.

    vishal.kadam’s picture

    Fix phpcs issues.

    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml ai_field/
    
    
    FILE: ai_field/ai_field.info.yml
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     9 | ERROR | [x] Expected 1 newline at end of file; 0 found
    ----------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------
    
    
    FILE: ai_field/ai_field.routing.yml
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     7 | ERROR | [x] Expected 1 newline at end of file; 0 found
    ----------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------
    
    
    FILE: ai_field/ai_field.links.menu.yml
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     5 | ERROR | [x] Expected 1 newline at end of file; 0 found
    ----------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------
    
    
    FILE: ai_field/src/Plugin/Field/FieldWidget/AiFieldWidget.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
      90 | WARNING | Unused variable $response.
     121 | WARNING | Unused variable $response.
    --------------------------------------------------------------------------------
    
    
    FILE: ai_field/src/Plugin/Field/FieldType/AiFieldType.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 10 WARNINGS AFFECTING 10 LINES
    --------------------------------------------------------------------------------
      74 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      82 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      89 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      98 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     107 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     115 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     124 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     134 | WARNING | #description values usually have to run through t() for translation
     163 | WARNING | #description values usually have to run through t() for translation
     171 | WARNING | #description values usually have to run through t() for translation
    --------------------------------------------------------------------------------
    
    
    FILE: ai_field/src/Form/AIFieldConfigurationForm.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
     39 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     61 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     61 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    --------------------------------------------------------------------------------
    
    
    FILE: ai_field/src/Controller/AIFieldController.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
     18 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     45 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    --------------------------------------------------------------------------------
    
    abhishek.sa’s picture

    Status: Needs work » Needs review

    Updated the code as per suggestions mentioned in #6.
    Also fix phpcs issues mentioned in #7.

    rushikesh raval’s picture

    Priority: Normal » Major

    I am changing the issue priority as per Issue priorities.

    rushikesh raval’s picture

    Priority: Major » Critical

    I am changing the issue priority as per issue priorities.

    solideogloria’s picture

    There are some functions that have a blank line after the function signature. There doesn't need to be blank lines after a function's opening brace. One is in the tokens include file.

    ai_field.services.yml has an entry for a controller. Controls shouldn't have entries in the services YAML, since they aren't injected.

    For readability, I recommend that instead of using a class name like AIFieldConfigurationForm, you use AiFieldConfigurationForm, with "Ai", and do likewise for similar classes. There isn't a 100% required way to do it for acronyms, but Drupal does use StackedHttpKernel instead of StackedHTTPKernel, and I think that's good.

    This is pretty minor, but there are typos in the module description in composer.json:

    This is a AI Field for generating conetnt using OpenAI

    avpaderno’s picture

    Priority: Critical » Normal
    Status: Needs review » Needs work
    vishal.kadam’s picture

    Priority: Normal » Minor

    I am changing priority as per Issue priorities.

    avpaderno’s picture

    Actually, a page controller can also be a service method, but in that case the service does not extends ControllerBase.
    Structure of routes gives more details.

    avpaderno’s picture

    That said, the ai_field.ai_field_services service is not used for a page controller. The only route defined in ai_field.routing.yml shows a form.

    ai_field.AIFieldConfigurationForm:
      path: '/admin/config/ai-field-form'
      defaults:
        _form: '\Drupal\ai_field\Form\AIFieldConfigurationForm'
        _title: 'AI Field'
      requirements:
        _permission: 'administer site configuration'
    
    vishal.kadam’s picture

    Status: Needs work » Closed (won't fix)

    This thread has been idle, in the Needs work state with no activity for several months. Therefore, I am assuming that you are no longer pursuing this application, and I marked it as Closed (won't fix).

    If this is incorrect, and you are still pursuing this application, then please feel free to re-open it and set the issue status to Needs work or Needs review, depending on the current status of your code.

    avpaderno’s picture

    Status: Closed (won't fix) » Needs work

    This application waited four months for a review. Let's keep this application open for longer.

    avpaderno’s picture

    Status: Needs work » Closed (won't fix)

    This thread has been idle, in the Needs work state with no activity for more than eight months; the application has been created more than 11 months ago. Therefore, I marked it as Closed (won't fix).

    If this is incorrect, and you are still pursuing this application, please feel free to re-open it and set the issue status to Needs work or Needs review, depending on the current status of your code.

    Now that this issue is closed, please review the contribution record.

    As a contributor, attribute any organization helped you, or if you volunteered your own time.

    Maintainers, please credit people who helped resolve this issue.