Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first message must use the "user" role error with Bedrock but not with Anthropic #622

Open
dandv opened this issue Dec 6, 2024 · 0 comments

Comments

@dandv
Copy link
Contributor

dandv commented Dec 6, 2024

In addition to the minor difference in behavior between the 1P Anthropic and 3P Bedrock Messages endpoint in #565, there is also a difference in how they handle: Assistant as the first role (succeeds on Anthropic but fails on Bedrock):

import Anthropic from '@anthropic-ai/sdk';
import AnthropicBedrock from '@anthropic-ai/bedrock-sdk';

const clientAnthropic = new Anthropic();
const clientBedrock = new AnthropicBedrock();

const haiku = {
  anthropic: 'claude-3-haiku-20240307',
  bedrock: 'anthropic.claude-3-haiku-20240307-v1:0',
};

async function assistantFirstRole(client: Anthropic | AnthropicBedrock, model = haiku.anthropic) {
  const response = await client.messages.create({
    max_tokens: 1,
    stream: false,
    messages: [
      { role: 'assistant', content: 'How can I help?' },
      { role: 'user', content: 'What is the color of the sky? Answer with only one word.' },
    ],
    model,
  });
  console.log('Response content: ', response.content);
}

await assistantFirstRole(clientAnthropic, haiku.anthropic);  // [ { type: 'text', text: 'Blue' } ]
await assistantFirstRole(clientBedrock, haiku.bedrock);  // Error: 400 messages: first message must use the "user" role
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant