n8n icon indicating copy to clipboard operation
n8n copied to clipboard

AWS bedrock (titan model)

Open johnongit opened this issue 1 year ago • 5 comments

Describe the bug The Bedrock model node in n8n does not seem to submit user prompts properly when interfacing with the AWS Bedrock Chat model.

To Reproduce Steps to create a simple workflow with a basic LLM chain based on AWS Bedrock Chat model:

  1. Use amazon.titan-text-express-v1 as the model.
  2. Submit a prompt in the chat node.

The Titan express model returns a malformed output: "bonjour, comment puis-je vous aider?\n\nHuman: comment puis-je trouver un travail\nAssistant: il existe plusieurs moyens de trouver un travail. Vous"

This issue arises because n8n uses "Human:" and "Assistant:" prefixes, which differ from the ones documented by AWS ("User:" and "Bot:"). Reference: Amazon Titan Text Prompt Engineering Guidelines (see page 5).

Expected behavior n8n should use the prefix format documented by AWS to ensure compatibility and proper functioning.

Environment (please complete the following information):

  • OS: Pop!_OS 22.04
  • n8n Version: 1.20.0 (Docker image from docker.n8n.io/n8nio/n8n)
  • Node.js Version: [as per Docker image]
  • Database system: SQLite
  • Operation mode: [e.g., own; operation modes are own, main, and queue. Default is main]

johnongit avatar Jan 03 '24 16:01 johnongit

Hey @johnongit,

Thanks for the report we are going to take a look into this soon, It could be that something has changed in Langchain and we need to do a quick update to allow for it.

Joffcom avatar Jan 04 '24 08:01 Joffcom

Just upgraded a local n8n to last Langchainjs (v0.0.214) and works fine with aws bedrock - titan model

pmoralesp avatar Jan 04 '24 11:01 pmoralesp

hi @pmoralesp I would love to see how did you upgraded langchainjs.

johnongit avatar Jan 04 '24 17:01 johnongit

hi @pmoralesp I would love to see how did you upgraded langchainjs.

Hi @johnongit. This was the steps on my machine:

  1. Clone this repo
  2. Go to packages/@n8n/nodes-langchain/
  3. Run npm install [email protected]
  4. Go to root folder
  5. Run npm run build && npm run dev

I hope it is useful.

pmoralesp avatar Jan 04 '24 18:01 pmoralesp

Thank you @pmoralesp. I'm encountering several issues while trying to implement your steps in my setup.

Here's what I did based on Docker:

  1. Clone this repo
  2. Go to packages/@n8n/nodes-langchain/
  3. Run npm install [email protected]
  4. Built docker image docker build -t n8n-custom:patch-langchain -f docker/images/n8n-custom/Dockerfile .

I'm not realy sure that [email protected] fix the issue. I've tried a really simple workflow Capture d’écran du 2024-01-07 10-45-40

The Bedrock logs returned the following: "modelId": "amazon.titan-text-express-v1", "input": { "inputContentType": "application/json", "inputBodyJson": { "inputText": "\n\nHuman: Repond en français.\nQ: Salut, tu connais bitcoin ?\nA: \n\nAssistant: ", "textGenerationConfig": { "maxTokenCount": 50, "temperature": 0 } }, "inputTokenCount": 32 } The model returns an inconsistent answer due to the prefixes 'Human:' and 'Assistant:'.

When I try with the AWS playground, I get this: User: Salut, tu connais bitcoin ?\n\nBot:

johnongit avatar Jan 07 '24 09:01 johnongit

We have recently updated Langchain again to a later release, Is this issue still occuring?

Joffcom avatar Mar 25 '24 17:03 Joffcom