Skip to main content

Converse with your favorite Amazon Bedrock LLM from the command line.

Project description

Ask Amazon Bedrock

Converse with your favorite Amazon Bedrock large language model from the command line.

This tool is a wrapper around the low-level Amazon Bedrock APIs and Langchain. Its main added value is that it locally persists AWS account and model configuration to enable quick and easy interaction.

Installation

⚠️ Requires Python >= 3.9

⚠️ Requires a working AWS CLI setup configured with a profile that allows Amazon Bedrock access. See CLI documentation for details.

pip install ask-bedrock

You can also build/run this project locally, see Building and Running Locally.

Usage

Activating models

Before you can use this command line tool, you need to request model access through the AWS Console in a region where Bedrock is available: Switch to the region where you want to run Bedrock, go to ”Model access“, click “Edit”, activate the models you wish to use, and then click “Save changes”.

Invocation

To start a conversation, simply enter the following command:

ask-bedrock converse

Upon the first run, you will be led through a configuration flow. To learn more about configuration options, see the Configuration section below.

If you’re fully configured, the tool will show you a >>> prompt and you can start interacting with the configured model.

Multi-line prompts can be wrapped into <<< >>> blocks.

To end your interaction, hit Ctrl + D. Note that the conversation will be lost.

Pricing

Note that using Ask Amazon Bedrock incurs AWS fees. For more information, see Amazon Bedrock pricing. Consider using a dedicated AWS account and AWS Budgets to control costs.

Configuration

Ask Amazon Bedrock stores your user configuration in $HOME/.config/ask-bedrock/config.yaml. This file may contain several sets of configuration (contexts). For instance, you can use contexts to switch between different models. Use the --context parameter to select the context you'd like to use. The default context is default.

If no configuration is found for a selected context, a new one is created. If you want to change an existing config, use

ask-bedrock configure --context mycontext

You can also create or edit the configuration file yourself in $HOME/.config/ask-bedrock/config.yaml:

contexts:
  default:
    region: ""                  # an AWS region where you have activated Bedrock
    aws_profile: ""             # a profile from your ~/.aws/config file
    model_id: ""                # a Bedrock model, e.g. "ai21.j2-ultra-v1"
    model_params: "{}"          # a JSON object with parameters for the selected model

Model parameters

This JSON is passed to Langchain during client setup (as model_kwargs). The schema depends on the model that is used. Have a look at the examples.

If you want to configure multiple lines, model parameters can be wrapped in <<< >>>.

Building and Running Locally

pip install build
python -m build
python ask_bedrock/main.py converse

Feedback

As this tool is still early stage, we are very interested in hearing about your experience. Please take one minute to take a little survey: https://pulse.aws/survey/GTRWNHT1

Troubleshooting

Q: I’m getting the following error during invocation: “ValueError: Error raised by bedrock service: An error occurred (AccessDeniedException) when calling the InvokeModel operation: Your account is not authorized to invoke this API operation.”

A: You may have selected a model that is currently not yet activated for public usage. It may have been listed it in the selection of available models, but unfortunately some models (such as Amazon Titan) aren’t yet available via API.


Q: The model responses are cut off mid-sentence.

A: Configure the model to allow for longer response. Use model parameters (see above) for this. Claude for example would take the following model parameters: {"max_tokens_to_sample": 3000}


Q: I'm getting an error that is not listed here.

A: Use the --debug option to find out more about the error. If you cannot solve it, create an issue.

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ask-bedrock-0.0.7.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

ask_bedrock-0.0.7-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file ask-bedrock-0.0.7.tar.gz.

File metadata

  • Download URL: ask-bedrock-0.0.7.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ask-bedrock-0.0.7.tar.gz
Algorithm Hash digest
SHA256 d1d0c38b9478da1ee078ddf31e134b18ec9981e6e30156cf227d3d87c9acb12a
MD5 4bd2a1f52f45c875f98616400a4dda56
BLAKE2b-256 fa0b8988492f7b07c442ef6d364c265a29ace332fd19b9c30b9ad3e567c59799

See more details on using hashes here.

File details

Details for the file ask_bedrock-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: ask_bedrock-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ask_bedrock-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 42e0093208802eaba48e8508141f82a47d6b449ffa13c41a1cf7c57c06ab5728
MD5 f9039957f999a16b878750f1e77b715c
BLAKE2b-256 74d9a833f8e06fdec6d36da3d07b22c1114f3e40bb7dd62654a982045e2f6e95

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page