PromptRouter
- class aws_cdk.aws_bedrock_alpha.PromptRouter(props, region)
Bases:
object
(experimental) Amazon Bedrock intelligent prompt routing provides a single serverless endpoint for efficiently routing requests between different foundational models within the same model family.
It can help you optimize for response quality and cost.
Intelligent prompt routing predicts the performance of each model for each request, and dynamically routes each request to the model that it predicts is most likely to give the desired response at the lowest cost.
- See:
https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-routing.html
- Stability:
experimental
- ExampleMetadata:
fixture=default infused
Example:
# Create a prompt router for intelligent model selection prompt_router = bedrock.PromptRouter.from_default_id(bedrock.DefaultPromptRouterIdentifier.ANTHROPIC_CLAUDE_V1, "us-east-1") # Use the prompt router with a prompt variant variant = bedrock.PromptVariant.text( variant_name="variant1", prompt_text="What is the capital of France?", model=prompt_router ) bedrock.Prompt(self, "Prompt", prompt_name="prompt-router-test", variants=[variant] )
- Parameters:
props (
Union
[PromptRouterProps
,Dict
[str
,Any
]])region (
str
)
- Stability:
experimental
Methods
- grant_invoke(grantee)
(experimental) Grants the necessary permissions to invoke this prompt router and all its routing endpoints.
This method grants permissions to:
Get prompt router details (bedrock:GetPromptRouter)
Invoke models through the router (bedrock:InvokeModel)
Use all underlying models and cross-region profiles
- Parameters:
grantee (
IGrantable
) –The IAM principal to grant permissions to.
- Return type:
- Returns:
An IAM Grant object representing the granted permissions
- Stability:
experimental
Attributes
- invokable_arn
(experimental) The ARN used for invoking this prompt router.
This equals to the promptRouterArn property, useful for implementing IBedrockInvokable interface.
- Stability:
experimental
- prompt_router_arn
(experimental) The ARN of the prompt router.
- Stability:
experimental
- Attribute:
true
- prompt_router_id
(experimental) The ID of the prompt router.
- Stability:
experimental
- Attribute:
true
- routing_endpoints
(experimental) The inference endpoints (cross-region profiles) that this router will route to.
These are created automatically based on the routing models and region.
- Stability:
experimental
Static Methods
- classmethod from_default_id(default_router, region)
(experimental) Creates a PromptRouter from a default router identifier.
- Parameters:
default_router (
DefaultPromptRouterIdentifier
) –The default router configuration to use.
region (
str
) –The AWS region where the router will be used.
- Return type:
- Returns:
A new PromptRouter instance configured with the default settings
- Stability:
experimental