[1.0.x] ChatGPT Content Generator

Created on 25 January 2023, about 2 years ago
Updated 29 January 2023, about 2 years ago

This module will integrate OpenAI ChatGPT with our Drupal system. It will add a link on the content add and edit page. On clicking this link, it will open a popup which will provide access to the ChatGPT content search. Content creators can copy the article from the popup and can create a new content with it.

The module has two parts -
1. ChatGPT API Configuration page - A "ChatGPT API Settings" link will appear on the Admin->Configuration page from where you can update the API endpoint, access token and other required information to make the API Call.
2. ChatGPT Search link on the content add and edit page.

Project Link

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

📌 Task
Status

Fixed

Component

module

Created by

🇮🇳India anup.sinha Bengaluru

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @anup.sinha
  • 🇮🇳India jitesh_1 Jaipur

    Thank you for applying! Reviewers will review the project files, describing what needs to be changed.

    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 smother review.

    To reviewers: Please read How to review security advisory coverage applications , What to cover in an application review , and Drupal.org security advisory coverage application workflow .

    While this application is open, only the user who opened the application can make commits to the project used for the application.


    Reviewers only describe what needs to be changed; they don't provide patches to fix what reported in a review.

  • 🇮🇳India vishal.kadam Mumbai

    It seems you have missed working on the coding standards. You can use the PHPCS tool for checking and resolving issues.

    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml chatgpt_plugin/
    
    FILE: chatgpt_plugin/chatgpt/chatgpt.info.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: chatgpt_plugin/chatgpt/chatgpt.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: chatgpt_plugin/chatgpt/chatgpt.module
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 23 ERRORS AND 1 WARNING AFFECTING 20 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      1 | ERROR   | [x] Missing file doc comment
      1 | ERROR   | [x] The PHP open tag must be followed by exactly one blank line
     10 | ERROR   | [x] Line indented incorrectly; expected 2 spaces, found 4
     10 | ERROR   | [x] Expected 1 space after SWITCH keyword; 0 found
     11 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 8
     12 | ERROR   | [x] Line indented incorrectly; expected 6 spaces, found 10
     13 | ERROR   | [x] Line indented incorrectly; expected 6 spaces, found 10
     14 | ERROR   | [x] Line indented incorrectly; expected 6 spaces, found 10
     15 | ERROR   | [x] Line indented incorrectly; expected 6 spaces, found 10
     16 | ERROR   | [x] Line indented incorrectly; expected 6 spaces, found 10
     18 | ERROR   | [x] Line indented incorrectly; expected 2 spaces, found 4
     20 | ERROR   | [x] Expected 1 blank line after function; 2 found
     24 | WARNING | [ ] Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for
        |         |     xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."
     27 | ERROR   | [x] Line indented incorrectly; expected 2 spaces, found 4
     28 | ERROR   | [x] Line indented incorrectly; expected 2 spaces, found 4
     29 | ERROR   | [x] Line indented incorrectly; expected 2 spaces, found 4
     30 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 8
     30 | ERROR   | [x] Short array syntax must be used to define arrays
     31 | ERROR   | [x] Array indentation error, expected 10 spaces but found 12
     32 | ERROR   | [x] Array indentation error, expected 10 spaces but found 12
     33 | ERROR   | [x] Array indentation error, expected 10 spaces but found 12
     36 | ERROR   | [x] Line indented incorrectly; expected 2 spaces, found 4
     39 | ERROR   | [x] Expected 1 newline at end of file; 0 found
     39 | ERROR   | [x] A closing tag is not permitted at the end of a PHP file
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 23 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: chatgpt_plugin/chatgpt/chatgpt.routing.yml
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     14 | ERROR | [x] Expected 1 newline at end of file; 0 found
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    
    FILE: chatgpt_plugin/chatgpt/css/chatgpt.css
    ----------------------------------------------------------------------------
    FOUND 7 ERRORS AFFECTING 6 LINES
    ----------------------------------------------------------------------------
     2 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     3 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     4 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     5 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     6 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     7 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 2
     7 | ERROR | [x] Expected 1 newline at end of file; 0 found
    ----------------------------------------------------------------------------
    PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------
    
    
    FILE: chatgpt_plugin/chatgpt/README.md
    ----------------------------------------------------------------------
    FOUND 0 ERRORS AND 8 WARNINGS AFFECTING 8 LINES
    ----------------------------------------------------------------------
     13 | WARNING | Line exceeds 80 characters; contains 481 characters
     16 | WARNING | Line exceeds 80 characters; contains 220 characters
     28 | WARNING | Line exceeds 80 characters; contains 214 characters
     29 | WARNING | Line exceeds 80 characters; contains 110 characters
     30 | WARNING | Line exceeds 80 characters; contains 128 characters
     45 | WARNING | Line exceeds 80 characters; contains 140 characters
     46 | WARNING | Line exceeds 80 characters; contains 81 characters
     53 | WARNING | Line exceeds 80 characters; contains 142 characters
    ----------------------------------------------------------------------
    
    
    FILE: chatgpt_plugin/chatgpt/src/Form/ChatGPTForm.php
    -----------------------------------------------------------------------------------------------------------------------------
    FOUND 4 ERRORS AFFECTING 3 LINES
    -----------------------------------------------------------------------------------------------------------------------------
     103 | ERROR | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
     108 | ERROR | [x] Concat operator must be surrounded by a single space
     108 | ERROR | [x] Concat operator must be surrounded by a single space
     113 | ERROR | [x] Inline comments must start with a capital letter
    -----------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------------------------
  • Status changed to Needs work about 2 years ago
  • 🇮🇳India jitesh_1 Jaipur

    Hello @anup.sinha,

    1. Move file out from Chatgpt
    2. add composer.json (optional) but good to have. See here https://www.drupal.org/docs/creating-custom-modules/add-a-composerjson-file#s-define-your-project-as-a-php-package
  • 🇮🇳India akshay.singh Noida
    $payload = [
          "model" => $model,
          "prompt" => $prompt_text,
          "temperature" => (int) $temperature,
          "max_tokens" => (int) $max_tokens,
        ];
        $json_input = json_encode($payload);
        $headr = [];
        $headr[] = 'Content-Type: application/json';
        $headr[] = 'Authorization: Bearer ' . $access_token;
    
        // cURL starts.
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $json_input);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headr);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        $reply = curl_exec($curl);
        $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        curl_close($curl);
        // cURL ends
        $decoded_data = json_decode($reply);
    
        // Error handling for OpenAI API.
        if ($http_status != 200) {
          $error_msg = $decoded_data->error->type.": ".$decoded_data->error->message;
          $ajax_response->addCommand(new HtmlCommand('#chatgpt-result', $error_msg));
          return $ajax_response;
        }
        else {
          // processing success response data.
          $text = $decoded_data->choices[0]->text;
          $ajax_response->addCommand(new HtmlCommand('#chatgpt-result', $text));
          return $ajax_response;
        }
    

    you must replace curl with Drupal::httpClient as it is the preferred and recommended way when it comes to drupal.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Usually, after reviewing a project, we allow the developer to opt projects into security advisory coverage. This project is too small for us and it doesn't contain enough PHP code to really assess your skills as developer.

    Have you made any other contributions that we could instead review?

  • 🇮🇳India anup.sinha Bengaluru

    Hi @apaderno,

    Many thanks for your update. I have almost 10 years of experience working with Drupal CMS but I started contributing to Drupal org really late in my career. I started working on Drupal org core issues just 5 months back. Below are the three patches I have currently worked on, also here is my linkedin account - https://www.linkedin.com/in/anup-sinha-12650b72/. I have recently got my community role also in Drupal org for being an active users and frequent participation. PFA the screenshot for the same. I hope this helps you to evaluate my Drupal skill.

    Drupal 10 patch:
    1. https://www.drupal.org/project/drupal/issues/3266529 🐛 Password reset invalid mail notify language Needs work
    2. https://www.drupal.org/project/drupal/issues/2926529 🐛 Route with space at the end does not work Needs work
    3. https://www.drupal.org/project/drupal/issues/3201472 🐛 Clarify via the field description that the notification email address is used for the reply-to address, not the from address Needs work

    Patch review:
    1. https://www.drupal.org/project/drupal/issues/3331212 📌 Remove unused variable $result from MoveTest Fixed

    Also this is the only ChatGPT Drupal plugin currently available in the Drupal org. So lot of people want to use it in their real live projects as ChatGPT is really hot in the market right now and it can be huge beneficial for the content team. This is why I wanted to opt this project into security advisory coverage.

    Also all the code review comments are already addressed except #7 (httpClient method instead of cURL) on which I am already working on. Let me know please if there is any other info you need from me for this module.

    Thanks & Regards,
    Anup

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    By contributions I meant another module, a theme, or a distribution, not patches.

    We need another project with commits from you with more PHP code.

  • 🇮🇳India anup.sinha Bengaluru

    Hi @apaderno,

    No, I don't have any other module or theme as I recently started contributing to Drupal org. This is the first ever project I have published on Drupal.org.

    Thanks & Regards,
    Anup

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Remember to change status, after you changed the files basing on what comments #3 and #7 reported and committed those changes.

  • Status changed to Needs review about 2 years ago
  • 🇮🇳India anup.sinha Bengaluru

    Hello Everyone,

    All the code review comments have been addressed and committed into the branch - 1.0.x . Please validate the same and let me know please if there is any observation.

    Git repo URL - https://git.drupalcode.org/project/chatgpt_plugin
    Branch - 1.0.x

    Thanks & Regards,
    Anup

  • Assigned to apaderno
  • Status changed to RTBC about 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Thank you for your contribution! I am going to update your account.

    These are some recommended readings to help with excellent maintainership:

    You can find more contributors chatting on the Slack #contribute channel. So, come hang out and stay involved .
    Thank you, also, for your patience with the review process.
    Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review . I encourage you to learn more about that process and join the group of reviewers.

    I thank all the reviewers.

  • Status changed to Fixed about 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024