Skip to main content

A utility to force AWS Bedrock to apply the given syntax to its response.

Project description

Bedrock Syntaxer

A utility to force AWS Bedrock to apply the given syntax to its response.

Installation

To install the required dependencies, run:

pip install -r requirements.txt

Usage

Function: bedrock_syntaxer

A utility to force Bedrock to apply the given syntax to its response.

Parameters:

  • model_id (str): The model ID of the Bedrock model.
  • messages (list): The messages to send to Bedrock.
  • syntax (str): The syntax to apply to the response.
  • inference_config (dict, optional): The inference configuration to use.
  • region_name (str, optional): The region name of the Bedrock model.

Returns:

  • str: The response from Bedrock with the syntax applied.

Example

from bedrock_syntaxer import bedrock_syntaxer
import json

ACCOUNT_ID = "961341532715"
REGION = "us-east-1"
MODEL_NAME = "claude-3-5-sonnet-20241022-v2:0"
MODEL_ID = f"arn:aws:bedrock:{REGION}:{ACCOUNT_ID}:inference-profile/us.anthropic.{MODEL_NAME}"

prompt = (
    "Write the definition of 3 Filipino word in JSON format. "
    "The words are 'kamusta', 'salamat', and 'paalam'."
    "Use the keys 'word' and 'definition'."
)
messages = [{"role": "user", "content": [{"text": prompt}]}]

response = bedrock_syntaxer(
    model_id=MODEL_ID,
    messages=messages,
    syntax="json",
    region_name=REGION,
)

print(response)

# The response is a JSON string.
response_json = json.loads(response)

Testing

To run the tests, use:

pytest

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

bedrock_syntaxer-0.1.2.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

bedrock_syntaxer-0.1.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bedrock_syntaxer-0.1.2.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.0 Darwin/24.3.0

File hashes

Hashes for bedrock_syntaxer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bd25152d050f3bdae0d2feb1dc428fcaba2683ac79575a276c9223299a4e69ad
MD5 8b99566cf6daac6c77d8e11ab4661221
BLAKE2b-256 a2e92ec0d012d5c49f730b85b10e7b138c16a569cbb1a3fd37b5ce485d2f96b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bedrock_syntaxer-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.0 Darwin/24.3.0

File hashes

Hashes for bedrock_syntaxer-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 14170c4a97a55c9ce3de73a1d4da273f99dc4ff6e8eeb6a52dbd4e4f17eb9230
MD5 ea256dcb1678d3ddb7bb096d0f9f004d
BLAKE2b-256 0f131c253d09d96798e2abd6a5fa765fb5ab332267debc31c34a652a55c4ee79

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