Steps to reproduce
1: Installed the module using Composer with the command: composer require 'drupal/openai_client:^1.1'.
2: when we try to open "AI assistants" /admin/structure/assistants, it shows an error
TypeError: OpenAI::client(): Argument #1 ($apiKey) must be of type string, null given, called in /modules/openai_client/src/OpenAIClientWrapper.php on line 70 in OpenAI::client() (line 13 of /vendor/openai-php/client/src/OpenAI.php).
I've attached an image illustrating my actions—installing the module and searching within the extend panel.
| Comment | File | Size | Author |
|---|---|---|---|
| openai.png | 84.61 KB | aman_lnwebworks |
Issue fork openai_client-3456210
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:
- 3456210-typeerror-openaiclient-argument
changes, plain diff MR !5
- 1.1.x
changes, plain diff MR !3
Comments
Comment #3
aman_lnwebworks commentedHi @psf_
I have created MR!3 for the above issue, Please review it once.
Thank you !!
Comment #4
psf_ commentedHi, thx by the patch.
I have some notes:
- In "src/OpenAIClientWrapper.php" you were erased all comments, it's are required by code styling that we have comments.
- In the protected method getApiToken() we can't send any status message, because that will spawn the user with messages. This method is called so many times.
Comment #8
ankitv18 commented@psf_ please review the MR!5 I guess we could use the ternary operator to handle the null value passed as token.
Comment #9
psf_ commentedIn this line:
$token = empty($token) ? $this->getApiToken() : '';"$this->getApiToken()" can return a NULL value if the user don't configure the module.
I change your commit with:
But I don't tested it.
Comment #10
ankitv18 commentedI can implement the same logic with combination or ternary and null coalescing operator.
Comment #11
psf_ commentedI see it OK, but I don't tested it.
I'm so busy, when I get free I will try it, or apply it if anyother tested it.
Thx so much
Comment #13
psf_ commentedMerged, thx : ))
Comment #14
psf_ commented