Skip to main content

BasicBedrock

AWS Bedrock provides a variety of foundational models to AWS customers. Each model family requires their own request structure, yet the underlying semantics are roughly common; there is always a field for the textual input prompt, and often there are fields to define maximum desired output, stop words, P, K and Temperature values.

This package aims to abstract away all of that.

For model requests, top_p, top_k, temp, max_tokens, stop_words and prompts are all abstracted away. For model responses, the answer itself is extracted, but the caller can also get the raw dict object passed back by boto3 if they wish.

Design Principles

I designed this around the following design principles:

  • If a paramater is specified, it will be used whenever possible. If not possible, it is (silently) ignored.
  • If a parameter is not specified, but it is required, a default parameter will be used (see below)
  • If a parameter is required to be in a certain format (such as a prompt) this is done by default
  • If multiple parameters are specified (stop_words), but only 0 or 1 are valid, then the first valid one will be used. If none are valid, then the default will be used

Default Parameters

There is no default prompt. The user must always provide their prompt for every call to invoke(). Unless the caller specifies otherwise, the following defaults are used:

top_p: float = 0.5
top_k: int = 125
temp: float = 0.5
max_tokens: int = 250
stop_words: List[str] = []

Usage

Installation

pip install basicbedrock

Example

Rather simple to use. See examples for some usage examples.

import boto3
from basicbedrock import BasicBedrock

session = boto3.session.Session(profile_name="default",region_name="us-west-2")
bb = BasicBedrock(session=session)
model = "anthropic.claude-3-sonnet-20240229-v1:0"
prompt = "Tell me about flowers"
r = bb.invoke(model, prompt)
print(r.get_answer())

Metadata

Release files for basicbedrock 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for basicbedrock 0.2.4
File Size Uploaded
basicbedrock-0.2.4.tar.gz 21.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for basicbedrock 0.2.4
File Interpreter ABI Platform
basicbedrock-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 45.1 kB

Release files / basicbedrock-0.2.4.tar.gz

Download URL basicbedrock-0.2.4.tar.gz
Size 21.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5188f94412bb6bba6baad5e4b20541f4148d65eea275e9e4154c88ea745a21df
BLAKE2b-256 checksum
How to use checksums
8a019ef951faff1d36625a61ab3367930bc228c7c4a371c2076a60566b6f7f33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.8.19

Release files / basicbedrock-0.2.4-py3-none-any.whl

Download URL basicbedrock-0.2.4-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d966f936ec3f2b012c18d9a2077159e91d4641c97323d80c38b6f18a5520c74
BLAKE2b-256 checksum
How to use checksums
b55a66332b561b0bed73fdef9a763cecb4beb3f77c59a5bac5679707035b82dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.8.19

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page