I'm not a developer/engineer, or code savvy by any means, but lately I've been working with Codex to help me out with my Backdrop site and it's been a game changer. The model can get really creative sometimes and has even made updates to some of my modules to help me accomplish my goals. 

For example, I was struggling with the font awesome module until Codex helped me realize that it didn't support the version that was required to provide the icons that I wanted. Codex made the changes, and even provided new functionality to the module such as adding a field for a custom CDN URL, and it worked like a charm. Since this these changes were helpful for my site, and helped update the module's compatibility with a newer version of font awesome, it made me wonder...is this worthy of sharing back with the author/community? 

Is it ok to share AI generated code with the community? Honestly I have no idea what I'm doing, but I was able to get my work done and I think it could also be helpful to others. I'm curious how others feel about the subject.

Best, D. 

Most helpful answers

I think it’s totally fine to share, especially if it helps others! Just be honest that it was AI-assisted and make sure it works well and doesn’t break anything. Many people would appreciate a useful update like that.

Comments

I think it’s totally fine to share, especially if it helps others! Just be honest that it was AI-assisted and make sure it works well and doesn’t break anything. Many people would appreciate a useful update like that.

My take is similar to that of the Mesa project: 

 "We don't care how you came up with the patch but you have to understand it, know how it works and be able to explain that to the maintainers reviewing the PR. Also you need to make sure that whatever you did is compatible with the repo's license."

 

Update: I had gotten that quote from a news article. The guide's actual wording is similar: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37233/diffs

With any contribution, you need to keep the reviewers in mind. It can't be too large a change that is hard to understand; the changes should be relevant to the intended functionality or bug fix. Random changes are not appreciated. And if there are tests, the PR should pass those tests. And if it's a core PR it will need to have a new test with it. You will need to make sure that the test actually tests what is relevant. I've heard that some AI generated tests don't actually test properly despite claims.

I have tried using Chat GPT several times to write or edit code on websites, in some cases successfully, in others - the code does not work or even breaks the entire site.

I find it useful to test with AI generated code placed in template.php of the theme the site is running. This is not even a module or custom module and is easily fixed if there is a problem.

Example of successful and working code suggested to me by Chat GPT to place in template.php:

<?php

function theme_name_preprocess_page(&$variables) {
// Check the path of the page
if (current_path() == 'node/62') {
// Add the JavaScript file
backdrop_add_js(path_to_theme() . '/js/google_conversion.js', array('type' => 'file', 'scope' => 'footer'));
}
}

This code allowed me to count visits to the contact page as conversions in Google Ads.

In another example, code in template.php allowed me to specify a specific CSS class in the body for selected pages.

It has also happened that a code suggested by Chat GPT caused an error message and when I reported the error it acknowledged that the code was for Drupal 7, but corrected itself and suggested new code that works with Backdrop

I have many cases where AI has answered my questions correctly on how to achieve a given functionality through Views or Rules and equally unsuccessful examples of the same. It has also helped me successfully fix problems with Global Redirect and many other cases.

I have released contrib modules written with AI assistance and fixed things I might otherwise have been otherwise unable to fix. 

When submitting a PR to others, I think that Herb's advice sounds pretty good.