aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

bedrock-runtime invoke-model : enable write to stdout instead of file

Open jeffgardnerdev opened this issue 1 year ago • 1 comments

Describe the feature

The bedrock-runtime invoke-model command should allow passing back the full response in stdout instead of only writing to a file via the outfile positional argument.

Use Case

Having the model response written to a file is not ideal for most practical use cases and requires immediately reading back the file contents in order to use the response.

Proposed Solution

Options:

  • Simply remove the outfile positional argument and always write the full model response to stdout. This would be a breaking change.
  • If need to continue supporting the outfile positional argument, a couple of options:
    • Allow the command to omit the outfile positional argument, in which case the response will be written to stdout.
    • The s3 cp command has a special "-" value that can be used in place of one of the path arguments to indicate the response should be a local file stream written to stdout. Implement a similar capability for this command.

Other Information

No response

Acknowledgements

  • [X] I may be able to implement this feature request
  • [X] This feature might incur a breaking change

CLI version used

2.14.5

Environment details (OS name and version, etc.)

macOS Ventura 13.4.1

jeffgardnerdev avatar Dec 02 '23 18:12 jeffgardnerdev

I agree this would be great. As a workaround in the meantime, I noticed on my system I can use /dev/stdout as the filename and I get the response to the stdout.

Example

$ aws bedrock-runtime invoke-model --model-id amazon.titan-text-express-v1 \
--body '{"inputText":"Write  a project description which will be used by a freelancer platform so that users can bid on it, the prompt is below in inverted commas. Description should be of 500 letters. The response should enchance the vocabulary, fix grammatical errors, should not ask for contact information, should not contain any placeholders and return only the description and nothing else.\\nCreate a logo for a fashion brand","textGenerationConfig":{"maxTokenCount":2048,"stopSequences":["User:"],"temperature":0.2,"topP":0.9}}' \
--cli-binary-format raw-in-base64-out \
/dev/stdout

{"inputTextTokenCount":82,"results":[{"tokenCount":141,"outputText":"\nWe are seeking a talented freelancer to create a captivating logo for our fashion brand. The logo should embody our brand's essence and appeal to our target audience. It should be modern, stylish, and memorable. We are open to creative ideas and welcome your unique perspective. The successful freelancer will have a strong understanding of design principles and be able to translate our vision into a visually appealing logo. The deadline for the project is [insert deadline], and we expect the freelancer to provide regular updates and work collaboratively throughout the process. If you are passionate about fashion and design and have the skills to create a stunning logo, we would love to hear from you.\n\nThank you for your interest in this project.","completionReason":"FINISH"}]}{
    "contentType": "application/json"
}

tomfotherby avatar Feb 20 '24 14:02 tomfotherby

Hi @jeffgardnerdev, thanks for reaching out. Unfortunately, this restriction is required. The output of InvokeModel has the potential to be enormous, to the point of crashing the terminal. The outfile requirement is a safety measure for this and other reasons. As @tomfotherby mentioned, it is possible to set stdout as a workaround, but this isn't something we can officially support.

RyanFitzSimmonsAK avatar May 22 '24 20:05 RyanFitzSimmonsAK

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar May 22 '24 20:05 github-actions[bot]