CK Editor AI Assistant throws Bad Request error when using AWS Bedrock Provider

Created on 1 October 2024, 3 months ago

Problem/Motivation

After configuring the AI Assistant in CK Editor to use on of the AWS Bedrock LLMs (using the AWS Bedrock Provider ), when we try to use the Summarize, Generate or Tone actions we get the response "The request could not be completed.". The log message is the following:

Error invoking model response: Error executing "ConverseStream" on "https://bedrock-runtime.us-east-1.amazonaws.com/model/mistral.mistral-sm..."; AWS HTTP error: Client error: `POST https://bedrock-runtime.us-east-1.amazonaws.com/model/mistral.mistral-sm...` resulted in a `400 Bad Request` response: {"message":"1 validation error detected: Value 'system' at 'messages.1.member.role' failed to satisfy constraint: Member (truncated...) ValidationException (client): 1 validation error detected: Value 'system' at 'messages.1.member.role' failed to satisfy constraint: Member must satisfy enum value set: [user, assistant] - @"message":"1 validation error detected: Value 'system' at 'messages.1.member.role' failed to satisfy constraint: Member must satisfy enum value set: [user, assistant]"

Steps to reproduce

  1. Install Drupal AI, Drupal AI CK Editor and AWS Bedrock Provider
  2. Configure AWS Bedrock Provider
  3. Configure AWS Bedrock Authentication in the AI Providers config page
  4. In the AI Settings page, select one of Bedrock's LLMs as default providers
  5. Configure the full html text editor to use the AI Assistant button using one of Bedrock's LLMs as AI provider for the Summarize function
  6. Edit an existing page.
  7. In a field with the full html editor available, click the AI Assistant button and choose Summarize.
  8. Add some text to be summarized and click Summarize. The text "The request could not be completed" will appear in the results text area.

Proposed resolution

In the AI CKEditor submodule, in the doRequest function (line 150 in AiRequest.php), there is a message to include in the prompt that identifies the user as "system".

$messages = new ChatInput([
        new ChatMessage('system', 'You are helpful website assistant for content writing and editing. Do not give responses in the first, second or third person form. Do not add any commentary to the answer.'),
        new ChatMessage('user', $data->prompt),
      ]);

The AWS Bedrock API only accepts "user" or "assistant" as users. Because we need to make it as agnostic as possible, we might want to introduce it as a configuration when selecting the AI Provider in the CK Editor AI Assistant config form.

Remaining tasks

  • Discuss proposed resolution
  • Create MR

User interface changes

TBD

API changes

N/A

Data model changes

TBD

🐛 Bug report
Status

Active

Version

1.0

Component

Other Submodules

Created by

🇵🇹Portugal raqfialho

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

Comments & Activities

Production build 0.71.5 2024