Installation/configuration resilience (ai_translate)

Created on 10 January 2025, 3 months ago

I experienced this error when re-testing an ai_translate issue, so this is a new issue raised from that testing covered under https://www.drupal.org/project/ai/issues/3494285#comment-15930348 🐛 Translating unpublished content creates a published tranlsation Active

The issues may be related to ai_translate specifically, or they may be a symptom of wider issues with AI Core.

Problem/Motivation

When installing and configuring AI Translate, you can encounter a number of unhelpful errors and messages if you do not undertake that correctly.

Steps to reproduce

Using D11 Umami with just the following core and modules enabled:

  • Drupal Core 11.1.1 - long list
  • Admin Toolbar 3.5.1 - toolbar and extras
  • AI (Artificial Intelligence) 1.0.0-beta7 - AI Core and AI Translate
  • Key 8.x-1.19

I'm logged in as the admin account. I haven't configured anything yet, which is the cause of my woes.

I created an article and then clicked on the Translate tab.

I see the following errors:

  • Error message - Please set a default chat provider & model in the AI module settings.
  • Error message - Warning: Undefined array key 1 in Drupal\ai_translate\Form\AiTranslateForm->buildForm() (line 116 of modules/contrib/ai/modules/ai_translate/src/Form/AiTranslateForm.php).

The first error is useful. I should not get the second error. The stack trace is:

TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/html/web/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 431 of core/lib/Drupal/Component/Utility/Html.php).
Drupal\Component\Render\FormattableMarkup::placeholderEscape() (Line: 187)
Drupal\Component\Render\FormattableMarkup::placeholderFormat() (Line: 195)
Drupal\Core\StringTranslation\TranslatableMarkup->render() (Line: 15)
Drupal\Core\StringTranslation\TranslatableMarkup->__toString() (Line: 203)
Drupal\Core\Utility\LinkGenerator->doGenerate() (Line: 180)
Drupal\Core\Utility\LinkGenerator->generate() (Line: 164)
Drupal\Core\Link->toString() (Line: 128)
Drupal\ai_translate\Form\AiTranslateForm->buildForm()
call_user_func_array() (Line: 528)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 279)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 219)
Drupal\Core\Form\FormBuilder->getForm() (Line: 19)
Drupal\ai_translate\Controller\ContentTranslationControllerOverride->overview()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 593)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 709)
Drupal\Core\DrupalKernel->handle() (Line: 19)

I want to use Open AI, but visiting the link displayed by the module under "Default providers" at /en/admin/config/ai/settings to /en/admin/config/ai/providers gives me an access denied error. I am admin and shouldn't see an access denied error and the cause of the issue is not clear to me.

Ooops... so I'd missed the ai_provider_openai module.

I installed and enabled that module.
I added my Open AI key via /en/admin/config/system/keys and configured ai_provider_openai to use that key at /en/admin/config/ai/providers/openai

That access denied error has gone away :)

I click on the Translate tab again. Same two errors :(

Ooops... I haven't configured AI Translate to use Open AI yet.
Dropdown at /en/admin/config/ai/ai-translate says to use the "Default from AI Module (chat)", which is just as well as there's no AI option under "Translate Text" at AI settings (/en/admin/config/ai/settings) which is what I was expecting to have to configure.
So I configure the Chat at that same URL to use Open AI and gpt-3.5-turbo.

I click the Translate tab again. Hoorah, no errors.

I click on "Translate using gpt-3.5-turbo" to create a Spanish translation. That works.

Proposed resolution

Make the module more resilient to misconfiguration, perhaps providing more helpful messages to guide users to a successful installation.

🐛 Bug report
Status

Active

Version

1.0

Component

Other Submodules

Created by

🇬🇧United Kingdom dunx

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

Merge Requests

Comments & Activities

  • Issue created by @dunx
  • First commit to issue fork.
  • 🇧🇪Belgium wouters_f Leuven

    Thanks for your feedback!
    I'll see if I can make the initial process a bit more seamless.

  • 🇧🇪Belgium wouters_f Leuven

    I've provided some more failsafes.
    If no default chat provider is configured, I'll refrain from showing the links and (and the error).

    It only shows the error message that you should configure the chat model.
    Would you be able to test this and verify that this is better?

    Or you have a proposal to do it differently?

  • 🇬🇧United Kingdom seogow

    The changes make the code more resilient to misconfiguration by:

    1. Properly handling the case when no model is configured.
    2. Properly handling the case when the default model string is empty.
    3. Only attempting to create the translation link when we have a valid model name.

    This aligns with the issue's "Proposed resolution" of making the module more resilient to misconfiguration.

  • 🇬🇧United Kingdom dunx

    I'll test this today.

  • 🇬🇧United Kingdom dunx

    Steps to set up for test

    1. Installed D11 Umami
    2. Installed and enabled key module at current
    3. (Installed and enabled admin_tools)
    4. ddev composer require 'drupal/ai:1.0.x-dev'
    5. ddev composer config repositories.ai vcs https://git.drupalcode.org/issue/ai-3498757.git
    6. ddev composer require drupal/ai:349875-aitranslate-resilience-dev
    7. ddev drush en ai ai_translate -y
    8. No configuration of the ai module or sub-module has been performed.

    Steps to test

    I created an article and then clicked on the Translate tab.
    An error is no longer displayed :)
    Instead I see this helpful error message, which is an improvement.

    I clicked on that link (/en/admin/config/ai/settings).
    There's nothing in any of the Dropdowns as expected as I haven't set Open AI up yet (or any other provider).
    So I click on the "configure" link here.

    And I get the same "Access denied" error as before.

    What I need to do is download and enable the ai_provider_openai module. But I should not see an access denied error, just because I haven't.

    Summary

    The first issue has been fixed, but the second issue remains unresolved.

  • 🇬🇧United Kingdom dunx
  • 🇧🇪Belgium wouters_f Leuven

    Hi Dunx,
    glad this fixed your first "issue".

    Concerning your second issue:
    What you're describing has nothing to do anymore with the ai_translate module.
    You can't configure providers that you haven't installed so the 404 makes sense in some way.

    I'm considering i'm done with this ticket, i cant make the ai_translate submodule more config resilient than what i've proposed.

    I propose the following steps:
    1 Allow Marcus to merge this and reduce the scope to your "issue 1". so the fix can get into the codebase.
    (STEPS: put into review and tested again)

    2 make a separate issue for your second issue, not related to the ai_translate submodule.

    Don;t get me wrong, i agree with that we should make it as easy as possible, but combining issues will just make everything slower.

  • 🇬🇧United Kingdom dunx

    It's not a 404, it's an access denied. But I hear you. Happy to make some improvement with the first issue and much appreciated of course.
    I can raise the second issue separately.

    Will update this to RTBC.

  • 🇬🇧United Kingdom dunx
  • 🇬🇧United Kingdom dunx
  • 🇬🇧United Kingdom dunx

    @wouters_f you said "What you're describing has nothing to do anymore with the ai_translate module. You can't configure providers that you haven't installed so the 404 makes sense in some way."

    Where should I raise this access denied issue then if it's not against this module?

  • 🇧🇪Belgium wouters_f Leuven

    This is a ai module thing so it's the same issue queue, but different component (Ai core)

  • 🇩🇪Germany marcus_johansson

    Hi @dunx - there is already a second issue being worked on here Add useful message on providers page when no provider enabled Active , for the #2, so no need for a new issue for that.

  • Merge request !406Don't show the error → (Merged) created by wouters_f
  • 🇩🇪Germany marcus_johansson

    Since seogow has done code review and dunx has confirmed it solves the issue with AI Translate this is getting merged.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024