Error when adding AI Assistant without default provider set in AI Settings

Created on 5 August 2024, 4 months ago
Updated 30 August 2024, 3 months ago

Problem/Motivation

When the default provider is not set in AI settings for Chat, attempting to add a new assistant (via URL admin/structure/ai_assistant/add) does not automatically select "Open AI" as the LLM Provider.
If a provider is selected from the dropdown, the following error occurs:

TypeError: Drupal\ai\Base\AiProviderClientBase::getAvailableConfiguration(): Argument #2 ($model_id) must be of type string, null given in Drupal\ai\Base\AiProviderClientBase->getAvailableConfiguration() (line 257 of /var/www/html/web/modules/contrib/ai/src/Base/AiProviderClientBase.php).

This error happens because the system is expecting a model to be set, but it isn't.

Steps to reproduce

  1. Go to AI settings and ensure that no default provider is set for Chat.
  2. Try to add a new assistant via the URL: admin/structure/ai_assistant/add.
  3. Notice that the LLM Provider is not automatically selected.
  4. Attempt to select a provider from the dropdown and observe the error.

Proposed resolution

Do not validate the model settings if the model is not set. This issue was fixed in the following commit: https://git.drupalcode.org/project/ai/-/commit/a9f0131a8f39cde920551859f...

Additionally, it is suggested to validate all cases where no default provider is set for any AI services (e.g., Chat, Text to Image, etc.). Users should be able to select a provider even when the default is not set.

Remaining tasks

  • Review and test the provided fix.
  • Update any relevant documentation.
πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany vesnag

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

Comments & Activities

  • Issue created by @vesnag
  • Assigned to marcus_johansson
  • Status changed to Fixed 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States sirkitree

    I am encountering this problem. I did not have a default set for chat and so when creating the assistant I received the error. After finding this issue, I switched to this branch, and saved a default provider, yet when adding a new assistant am receiving the following error:

    
    TypeError: Cannot assign null to property Drupal\ai_assistant_api\Entity\AiAssistant::$rag_enabled of type bool in Drupal\Core\Entity\EntityBase->__construct() (line 63 of core/lib/Drupal/Core/Entity/EntityBase.php).
    Drupal\Core\Config\Entity\ConfigEntityBase->__construct(Array, 'ai_assistant') (Line: 418)
    Drupal\Core\Entity\EntityStorageBase->mapFromStorageRecords(Array) (Line: 186)
    
    

    Happy to create a new issue if you see fit, but this seems relevant.

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

Production build 0.71.5 2024