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
I filed this a few months ago (#399) and it turns out it's not a Bedrock issue, and not limited to max_tokens 1.
When Claude doesn't return anything, the content array is empty. This breaks the assumption that the content array will contain an object with a text field. The correct output should be
[{type: 'text',text: ''}]
Repro:
importaxiosfrom'axios';import'dotenv/config';interfaceMessage{role: string;content: string;}asyncfunctionapiCallMessages(messages: Message[],model: string){constsampleRequest={
messages,max_tokens: 4096,// required, maximum
model,};letparsed,response;response=awaitaxios.post('https://api.anthropic.com/v1/messages',sampleRequest,{headers: {'x-api-key': process.env.ANTHROPIC_API_KEYasstring,'anthropic-version': '2023-06-01',// required by the Messages API, optional for Text Completions'anthropic-beta': 'messages-2023-12-15',// required to use the Messages API while in beta'anthropic-sdk': `anthropic-sheets/0.8.1`,},})asRecord<string,string>;returnresponse.data;}constprompt='Who is the best basketball player of all time? Please choose one specific player and be brief.';letresponse=awaitapiCallMessages([{role: 'user',content: prompt},{role: 'assistant',content: 'Stephen'},],'claude-3-haiku-20240307');console.log(response['content']);// 'Curry...'response=awaitapiCallMessages([{role: 'user',content: prompt},{role: 'assistant',content: 'Stephen Curry.'},],'claude-3-haiku-20240307');console.log(response['content']);// <-- [], which is an error
The text was updated successfully, but these errors were encountered:
Where is it documented that content should always be a non-empty array? This may be a bug in the documentation, or a misunderstanding of the API's contract.
Either way, this does not sound like a bug in the SDK, so I'm going to go ahead and close this issue.
When Claude doesn't return anything, the content array is empty. This breaks the assumption that the content array will contain an object with a text field. The correct output should be
[ { type: 'text', text: '' } ]
@rattrayalex is correct, that is not a valid assumption and this is the expected behavior for empty responses and matches the behavior on input where "content": [{"type": "text", "text": ""}] will give you an error.
Unrelated note:
'anthropic-beta': 'messages-2023-12-15', // required to use the Messages API while in beta
Messages API is now GA and you no longer need this header.
I filed this a few months ago (#399) and it turns out it's not a Bedrock issue, and not limited to max_tokens 1.
When Claude doesn't return anything, the
content
array is empty. This breaks the assumption that the content array will contain an object with atext
field. The correct output should beRepro:
The text was updated successfully, but these errors were encountered: