You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bedrock: roles must alternate between "user" and "assistant", but found multiple "user" roles in a row error after the silent change to combine consecutive turns
#565
Consecutive user or assistant turns in your request will be combined into a single turn.
This change does not seem to be active for Bedrock yet. The code below returns a ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/:
awaitclient.messages.create({max_tokens: 1,stream: false,messages: [{role: 'user',content: 'What is the color of'},{role: 'user',content: 'the sky?'},],model: 'anthropic.claude-3-sonnet-20240229-v1:0',});
Using @anthropic-ai/bedrock-sdk 0.10.4 and @anthropic-ai/sdk 0.29.2, but the error seems to come from Bedrock rather than the SDK.
The text was updated successfully, but these errors were encountered:
dandv
changed the title
Bedrock: roles must alternate between "user" and "assistant", but found multiple "user" roles in a row error after the silent change to combining consecutive turns
Bedrock: roles must alternate between "user" and "assistant", but found multiple "user" roles in a row error after the silent change to combine consecutive turns
Oct 19, 2024
I get this error with sdk 0.32.1, not with bedrock.
51 | for (let i = 1; i < result.length; i++) {
52 | if (result[i].role === result[i-1].role) {
> 53 | throw new Error('Invalid message sequence - messages must alternate between user and assistant');
| ^
54 | }
55 | }
56 |
To clarify, I'm seeing different behaviors from Anthropic and Bedrock on the same prompt with identical consecutive roles.
importAnthropicfrom'@anthropic-ai/sdk';importAnthropicBedrockfrom'@anthropic-ai/bedrock-sdk';constclientAnthropic=newAnthropic();constclientBedrock=newAnthropicBedrock();consthaiku={anthropic: 'claude-3-haiku-20240307',bedrock: 'anthropic.claude-3-haiku-20240307-v1:0',};asyncfunctionconsecutiveRoles(client: Anthropic|AnthropicBedrock,model=haiku.anthropic){constresponse=awaitclient.messages.create({max_tokens: 1,stream: false,messages: [{role: 'user',content: 'What is the color of'},{role: 'user',content: 'the sky? Answer with only one word.'},],
model,});console.log('Response content: ',response.content);}awaitconsecutiveRoles(clientAnthropic,haiku.anthropic);// [ { type: 'text', text: 'Blue' } ]awaitconsecutiveRoles(clientBedrock,haiku.bedrock);// Error: 400 messages: roles must alternate between "user" and "assistant", but found multiple "user" roles in a row
Per the Messages API docs that "Consecutive user or assistant turns in your request will be combined into a single turn.", it seems that Bedrock might not be running the same version of the API handlers.
The Messages API docs now state,
This change does not seem to be active for Bedrock yet. The code below returns a
ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/
:Using
@anthropic-ai/bedrock-sdk
0.10.4 and@anthropic-ai/sdk
0.29.2, but the error seems to come from Bedrock rather than the SDK.The text was updated successfully, but these errors were encountered: