Problem/Motivation
I'll add more later and add a patch later when I get a chance.
When using the openai_devel to generate some Articles, the default content type with the default install, I would get this error
array_rand(): Argument #1 ($array) must be of type array, null given
and could not generate any content.
I don't have the full error message because my local isn't running, but it pointed to /openai_devel/src/Plugin/DevelGenerate/ContentGPTDevelGenerate.php Line 223 which is $node_type = array_rand($results['node_types']);
.
Doing some step debugging I saw that $results['node_types'] was not always an array and array_rand() is causing the error because $results['node_types'] is a string and not an array.
Steps to reproduce
- Default install and enable openai_devel
- Enable pathauto
- Enter your openai key and id in config
- Try generating a couple of Articles (only Articles) entering body as a field, select generate path and select a user
Proposed resolution
Check that $results['node_types'] is an array before using array_rand().
if (is_array($results['node_types'])) {
$node_type = array_rand($results['node_types']);
}
else {
$node_type = $results['node_types'];
}
Step debugging was ery slow because the API calls to OpenAI took a long time. I suppose there could be another reason that $results['node_types'] is not always an array but sometimes a string.
Remaining tasks
User interface changes
API changes
Issue fork openai-3404107
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
Comment #2
kamkejj CreditAttribution: kamkejj at Nerdery for Nestle Purina PetCare - United States commentedComment #3
abhishek_gupta1 CreditAttribution: abhishek_gupta1 at Virasat Solutions commentedI verified this issue on my local, not getting above error. working fine for me.
Comment #4
kevinquillen CreditAttribution: kevinquillen at Velir commentedComment #6
kevinquillen CreditAttribution: kevinquillen at Velir commented