AWS bedrock documentation change
Summary
Added documentation about Converse API limitations for specific models and provided code examples for multi-modal input handling with image placeholders
Security assessment
Changes focus on API usage instructions and model-specific limitations without addressing security vulnerabilities or introducing security features
Diff
diff --git a/bedrock/latest/userguide/invoke-imported-model.md b/bedrock/latest/userguide/invoke-imported-model.md index 0f06b18b2..92c7c5626 100644 --- a//bedrock/latest/userguide/invoke-imported-model.md +++ b//bedrock/latest/userguide/invoke-imported-model.md @@ -12,0 +13,6 @@ After your imported model is available in Amazon Bedrock, you can use the model +To interface with your imported model using the messages format, you can call the [Converse](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html) or [ConverseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html) operations. For more information, see [Using the Converse API](./conversation-inference-call.html). + +###### Note + +Converse API is not supported for Qwen2.5, Qwen2-VL, and Qwen2.5-VL models. + @@ -16,0 +23,53 @@ To invoke your imported model, make sure to use the same inference parameters th +###### Note + +When providing multi modal inputs, you will need to include the appropriate placeholders for multi modal tokens in your text prompt. For example, when sending an image input to a Qwen-VL model, the prompt should include `<|vision_start|><|image_pad|><|vision_end|>`. These notations are specific to the model’s tokenizer and can be applied using the following chat template. + + + from transformers import AutoProcessor, AutoTokenizer + + if vision_model: + processor = AutoProcessor.from_pretrained(model) + else: + processor = AutoTokenizer.from_pretrained(model) + + + # Create messages + messages = [ + { + "role": "user", + "content": [ + { + "type": "image", + "image": "base64 encoded image", + }, + { + "type": "text", + "text": "Describe this image.", + }, + ], + } + ] + + # Apply chat template + prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) + """ + prompt = ''' + <|im_start|>system\nYou are a helpful assistant.<|im_end|>\n + <|im_start|>user\n<|vision_start|><|image_pad|><|vision_end|> + Describe this image.<|im_end|>\n<|im_start|>assistant\n''' + """ + + response = client.invoke_model( + modelId=model_id, + body=json.dumps({ + 'prompt': prompt, + 'temperature': temperature, + 'max_gen_len': max_tokens, + 'top_p': top_p, + 'images': ["base64 encoded image"] + }), + accept='application/json', + contentType='application/json' + ) + +