Content Suggestions: All generate Ajax error

Created on 18 February 2025, 4 days ago

Problem/Motivation

Each of the content suggestions result in an Ajax error and throw the following warning in the logs:

Error: Call to a member function setChatSystemRole() on null in Drupal\ai_content_suggestions\AiContentSuggestionsPluginBase->sendChat() (line 311 of /isis/websites/web/modules/contrib/ai/modules/ai_content_suggestions/src/AiContentSuggestionsPluginBase.php)

Steps to reproduce

We are running a complex multi-site with quite a number of modules and some custom content types as well. I recognize our full environment cannot be duplicated. As far as AI is, we've enabled AI Core, AI CKEditor integration, AI Content Suggestions, Microsoft Azure AI. Setup everything so that CKEditor is working fine with the AI integrations.

I've configured content suggestions to use the same model as CKEditor's AI integration and enabled them all, leaving 'Tone' to the default options (no taxonomy). While there is an error saving the settings, they appear to stick.

I pull up an existing node, the body of which has been renamed to 'Description'. Click any of the content suggestions fields, set it to use the 'Description' field, and submit -- Ajax error.

Stack trace below:

#0 /web/modules/contrib/ai/modules/ai_content_suggestions/src/Plugin/AiContentSuggestions/Tone.php(174): Drupal\ai_content_suggestions\AiContentSuggestionsPluginBase->sendChat()
#1 /web/modules/contrib/ai/modules/ai_content_suggestions/src/AiContentSuggestionsFormAlter.php(64): Drupal\ai_content_suggestions\Plugin\AiContentSuggestions\Tone->updateFormWithResponse()
#2 [internal function]: Drupal\ai_content_suggestions\AiContentSuggestionsFormAlter::getPluginResponse()
#3 /web/core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php(69): call_user_func_array()
#4 /web/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php(112): Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse()
#5 [internal function]: Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber->onException()
#6 /web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
#7 /vendor/symfony/http-kernel/HttpKernel.php(239): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#8 /vendor/symfony/http-kernel/HttpKernel.php(91): Symfony\Component\HttpKernel\HttpKernel->handleThrowable()
#9 /web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#10 /web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#11 /web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#12 /web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#13 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#14 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass()
#15 /web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#16 /web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#17 /web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#18 /web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#19 /web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#20 /web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#21 /web/index.php(19): Drupal\Core\DrupalKernel->handle()
#22 {main}

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Other Submodules

Created by

🇺🇸United States srees

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

Merge Requests

Comments & Activities

  • Issue created by @srees
  • First commit to issue fork.
  • Pipeline finished with Failed
    3 days ago
    Total: 434s
    #428190
  • Pipeline finished with Failed
    3 days ago
    Total: 279s
    #428193
  • Pipeline finished with Failed
    3 days ago
    Total: 229s
    #428198
  • Pipeline finished with Failed
    3 days ago
    Total: 195s
    #428199
  • Pipeline finished with Failed
    3 days ago
    Total: 260s
    #428224
  • Pipeline finished with Success
    3 days ago
    Total: 287s
    #428267
  • 🇬🇧United Kingdom MrDaleSmith

    I suspect there is something wrong with your set up as the provider should never be null: your work around is probably not going to be something we'd want in the module unless there's a more generic bug to be addressed. Can you recreate this issue on a clean install on a D10 test site?

    I don't think your change is ideal as the $response variable isn't created when there's an error, which may cause other errors.

  • 🇺🇸United States srees

    I concur that this does not address whatever the root of the problem is, only a symptom.

    I added these changes to my local ddev instance and it now passes that point in the code and errors at another, as suggested by mrdalesmith in #7:

    Warning: Undefined variable $response
    ...
    Error: Call to a member function getText() on null in Drupal\ai_content_suggestions\AiContentSuggestionsPluginBase->sendChat() (line 320 of /var/www/html/web/modules/contrib/ai/modules/ai_content_suggestions/src/AiContentSuggestionsPluginBase.php)
    #0 /var/www/html/web/modules/contrib/ai/modules/ai_content_suggestions/src/Plugin/AiContentSuggestions/Summarise.php(104): Drupal\ai_content_suggestions\AiContentSuggestionsPluginBase->sendChat('Create a detail...')
    #1 /var/www/html/web/modules/contrib/ai/modules/ai_content_suggestions/src/AiContentSuggestionsFormAlter.php(64): Drupal\ai_content_suggestions\Plugin\AiContentSuggestions\Summarise->updateFormWithResponse(Array, Object(Drupal\Core\Form\FormState))
    #2 [internal function]: Drupal\ai_content_suggestions\AiContentSuggestionsFormAlter::getPluginResponse(Array, Object(Drupal\Core\Form\FormState), Object(Symfony\Component\HttpFoundation\Request))
    #3 /var/www/html/web/core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php(69): call_user_func_array(Array, Array)
    #4 /var/www/html/web/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php(112): Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse(Object(Symfony\Component\HttpFoundation\Request), Array, Object(Drupal\Core\Form\FormState), Array)
    #5 [internal function]: Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber->onException(Object(Symfony\Component\HttpKernel\Event\ExceptionEvent), 'kernel.exceptio...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
    #6 /var/www/html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ExceptionEvent), 'kernel.exceptio...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
    #7 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(239): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ExceptionEvent), 'kernel.exceptio...')
    #8 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(91): Symfony\Component\HttpKernel\HttpKernel->handleThrowable(Object(Drupal\Core\Form\FormAjaxException), Object(Symfony\Component\HttpFoundation\Request), 1)
    #9 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #10 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #11 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #12 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #13 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #14 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #15 /var/www/html/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #16 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #17 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #18 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #19 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #20 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #21 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #22 {main}

    I'm lost as to why provider is null.

  • 🇺🇸United States srees

    It seems tied to line 283:
    $provider = $this->providerPluginManager->loadProviderFromSimpleOption($preferred_model);

    If I change this line:
    301: $provider_config = $this->getSetProvider($this->operationType(), $this->config->get('plugins')[$this->getPluginId()]);

    to:
    $provider_config = $this->getSetProvider($this->operationType(), null);

    Then everything functions using the default model for chat.

  • 🇺🇸United States srees
  • 🇺🇸United States srees

    Didn't realize Drupal is moving to forks instead of patches. Already did this one and have to run to a meeting.

    I consider this a functional workaround, but does not solve the root issue of the preferred provider not working.

  • 🇺🇸United States srees

    I've determined that the problem is actually with the Azure provider, which is incorrectly evaluating the isUsable() function.

    No need to apply this patch, I'll open a ticket in that project. Please close this one.

  • 🇺🇸United States srees
Production build 0.71.5 2024