Skip to main content

Bedrock Converse API Data Types

Project description

Amazon Bedrock Converse API Data Types

PyPI version release PyPI - Python Version Pydantic v2

This project is a Pydantic implementation of Amazon Bedrock Runtime Converse API Data Types.

Example Usage

from bedrock_types import ConverseResponse

...

response = client.converse(
    modelId=model_id,
    messages=messages,
    system=system_prompts,
    inferenceConfig=inference_config,
    additionalModelRequestFields=additional_model_fields,
)

parsed = ConverseResponse.model_validate(response)
print(parsed.model_dump_json(indent=4, exclude_unset=True))
print(parsed.ResponseMetadata)

Output

ResponseMetadata={'RequestId': '427c73bb-df2d-4c1a-8744-db1b5b3c4897', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Thu, 13 Jun 2024 09:11:25 GMT', 'content-type': 'application/json', 'content-length': '247', 'connection': 'keep-alive', 'x-amzn-requestid': '427c73bb-df2d-4c1a-8744-db1b5b3c4897'}, 'RetryAttempts': 0} additionalModelResponseFields=None metrics=ConverseMetrics(latencyMs=740) output=ConverseOutput(message=Message(content=[ContentBlock(image=None, text="Why don't scientists trust atoms? Because they make up everything!", toolResult=None, toolUse=None)], role='assistant')) stopReason='end_turn' usage=TokenUsage(inputTokens=22, outputTokens=16, totalTokens=38)
{
    "ResponseMetadata": {
        "RequestId": "427c73bb-df2d-4c1a-8744-db1b5b3c4897",
        "HTTPStatusCode": 200,
        "HTTPHeaders": {
            "date": "Thu, 13 Jun 2024 09:11:25 GMT",
            "content-type": "application/json",
            "content-length": "247",
            "connection": "keep-alive",
            "x-amzn-requestid": "427c73bb-df2d-4c1a-8744-db1b5b3c4897"
        },
        "RetryAttempts": 0
    },
    "metrics": {
        "latencyMs": 740
    },
    "output": {
        "message": {
            "content": [
                {
                    "text": "Why don't scientists trust atoms? Because they make up everything!"
                }
            ],
            "role": "assistant"
        }
    },
    "stopReason": "end_turn",
    "usage": {
        "inputTokens": 22,
        "outputTokens": 16,
        "totalTokens": 38
    }
}
{'RequestId': '427c73bb-df2d-4c1a-8744-db1b5b3c4897', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Thu, 13 Jun 2024 09:11:25 GMT', 'content-type': 'application/json', 'content-length': '247', 'connection': 'keep-alive', 'x-amzn-requestid': '427c73bb-df2d-4c1a-8744-db1b5b3c4897'}, 'RetryAttempts': 0}

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_types-0.1.3.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

bedrock_types-0.1.3-py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 3

Supported by

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