Bedrock Bot
This project is a basic CLI-based chat bot that uses Bedrock to resolve questions. It can take input from stdin, CLI arguments or interactively when no parameters have been passed.
Installation
pip install bedrock-bot- You will also need some AWS credentials available in your shell (any usual way works - CLI configured IAM user access key/secret keys, environment variables, etc)
- Bedrock requires you to opt in to models in order to use them
Usage
Usage: bedrock [OPTIONS] [ARGS]...
Options:
-r, --region TEXT The AWS region to use for requests. If no
default region is specified, defaults to us-
east-1
--raw-output TEXT Don't interpret markdown in the AI response
-m, --model [Claude-3-Haiku|Claude-3-Sonnet|Mistral-Large]
The model to use for requests
-v, --verbose Enable verbose logging messages
-i, --input-file FILENAME Read in file(s) to be used in your queries
--help Show this message and exit.
Directly as a chat bot:
$ bedrock
Hello! I am an AI assistant powered by Amazon Bedrock and using the model Claude-3-Haiku. Enter 'quit' or 'exit' at any time to exit. How may I help you today?
(You can clear existing context by starting a query with 'new>' or 'reset>')
> Hi, what is your name?
My name is Claude.
Using CLI arguments:
$ bedrock "Hi, what is your name?"
Hello! I am an AI assistant powered by Amazon Bedrock and using the model Claude-3-Haiku. Enter 'quit' or 'exit' at any time to exit. How may I help you today?
(You can clear existing context by starting a query with 'new>' or 'reset>')
> Hi, what is your name?
My name is Claude. It's nice to meet you!
Using stdin (Note that you can only use this for one-shot questions as input is reserved by your pipe to stdin and is not an interactive TTY any more):
$ echo "Hi, what is your name?" > input-file
$ cat input-file | bedrock
Hello! I am an AI assistant powered by Amazon Bedrock and using the model Claude-3-Haiku. Enter 'quit' or 'exit' at any time to exit. How may I help you today?
(You can clear existing context by starting a query with 'new>' or 'reset>')
> Hi, what is your name?
My name is Claude. I'm an AI created by Anthropic. It's nice to meet you!
Note that you can only do one-shot requests when providing input via stdin
Asking about a file:
$ bedrock --input-file bedrock_bot/models/base_model.py write unit tests using pytest for this file
Hello! I am an AI assistant powered by Amazon Bedrock and using the model Claude-3-Haiku. Enter 'quit' or 'exit' at any time to exit. How may I help you today?
(You can clear existing context by starting a query with 'new>' or 'reset>')
> write unit tests using pytest for this file
To write unit tests for the bedrock_bot/models/base_model.py file using pytest, you can create a test_base_model.py file in the tests directory. Here's an example of how you can structure the tests:
import json
from unittest.mock import patch, MagicMock
import pytest
from bedrock_bot.models.base_model import _BedrockModel, ConversationRole
class TestBedrockModel:
def setup_method(self):
self.model = _BedrockModel("test-model-id")
def test_reset(self):
self.model.append_message(ConversationRole.USER, "Hello")
assert len(self.model.messages) == 1
self.model.reset()
assert len(self.model.messages) == 0
...
Shell auto-complete
Shell auto-complete is also supported.
ZSH
_BEDROCK_COMPLETE=zsh_source bedrock > ~/.bedrock-completion.zsh- Add the following to your
~/.zshrc:source ~/.bedrock-completion.zsh
Bash
_BEDROCK_COMPLETE=bash_source bedrock > ~/.bedrock-completion.bash- Add the following to your
~/.bashrc:source ~/.bedrock-completion.bash
Metadata
Release files for bedrock-bot 1.6.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bedrock_bot-1.6.2.tar.gz | 7.9 kB | Without provenance | Details for bedrock_bot-1.6.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bedrock_bot-1.6.2-py3-none-any.whl | Python 3 | none | any | Details for bedrock_bot-1.6.2-py3-none-any.whl |
Total release size: 18.8 kB
Release files / bedrock_bot-1.6.2.tar.gz
| Download URL | bedrock_bot-1.6.2.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ed143b299d1b8e7e299db8cd32d660c63402c627dfc10fcd2c8588d856ce98c
|
|
BLAKE2b-256 checksum How to use checksums |
3d454744debf73a96a1f16f15be9a74505fb3782a29d57d584a792a9df500863
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.0 CPython/3.10.16 Linux/6.8.0-1021-azure
|
Release files / bedrock_bot-1.6.2-py3-none-any.whl
| Download URL | bedrock_bot-1.6.2-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ada3af0c5bfa81a41d8f6f4e0fa4a95d6ca2aef710898ceb3b64f8cd0aadbd70
|
|
BLAKE2b-256 checksum How to use checksums |
0b3e1e39b33066dd266116d4e54b0c4e8128f821f5c6ded8a9d9fc3f1c95cdbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.0 CPython/3.10.16 Linux/6.8.0-1021-azure
|
Security for bedrock-bot 1.6.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.