Skip to main content

An abstraction layer for AWS Bedrock. Removes the need to keep track of response/request schemas.

Project description

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())

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

basicbedrock-0.1.2.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

basicbedrock-0.1.2-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file basicbedrock-0.1.2.tar.gz.

File metadata

  • Download URL: basicbedrock-0.1.2.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.18

File hashes

Hashes for basicbedrock-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f411a33340c7076beeaace30823acffaf5ff0649e6bc9193b9b90a86da42977f
MD5 fe798e4b9fc47f7fcff94dbd6034b460
BLAKE2b-256 f80bbb74360d359ee076bb57b1d5ee0579a9096652a4577dfef4ff40589aac2c

See more details on using hashes here.

File details

Details for the file basicbedrock-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: basicbedrock-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.18

File hashes

Hashes for basicbedrock-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 36151172fa99c72afc2796b7e32aecf3f16371d9e01c7b3520987f342810e85e
MD5 5a5ff83b9c88a97f14b1cc750b004af8
BLAKE2b-256 ab3a305a1f4890c461cd0f5b2b31d18b573603d71681b50bef58cf2de13c59a4

See more details on using hashes here.

Supported by

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