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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bedrock_syntaxer-0.1.1.tar.gz.
File metadata
- Download URL: bedrock_syntaxer-0.1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
704375c3a67fa9c7c8ad81e64bc01b23efbaddb249356806b36610a52a7bea4f
|
|
| MD5 |
8366ce5b5db554144730cd8cf1d93511
|
|
| BLAKE2b-256 |
c8b84d2577e0f36cfdce30f033c42919eff0fe88a5fd3eb9b93e19aecc0f80da
|
File details
Details for the file bedrock_syntaxer-0.1.1-py3-none-any.whl.
File metadata
- Download URL: bedrock_syntaxer-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea17fdbd9acdb49a23638c2a15d689cd1a0a60c16da1bfc41b31579d1dc6e1d9
|
|
| MD5 |
46eebd1426b637cd19615344bf64d154
|
|
| BLAKE2b-256 |
af44e315e87c2e16c7312bdcf89ccfff01e3778c3509dc85f3b21567a14b2bd6
|