Bedrock LangChain Prompt Converter is a helper library that seamlessly integrates LangChain prompt templates with Amazon Bedrock's Prompt Management API, enabling efficient cross-platform prompt handling.
NOTE: Currently FewShotPromptTemplate and FewShotChatMessagePromptTemplate are not supported.
Create a ChatPromptTemplate using LangChain:
from langchain_core.prompts import (
ChatPromptTemplate,
HumanMessagePromptTemplate,
SystemMessagePromptTemplate,
)
chat_prompt = ChatPromptTemplate.from_messages(
[
SystemMessagePromptTemplate.from_template(
"This system can answer astronomical questions."
),
HumanMessagePromptTemplate.from_template("{user_input}"),
]
)
Initialize the PromptManager with your AWS region:
from src import PromptManager
prompt_manager = PromptManager(
{
"region_name": "us-west-2"
}
)
Use the prompt manager to create a new prompt in Amazon Bedrock:
from src import ChatModelId
prompt_manager.create_prompt(
chat_prompt,
"astronomical_questions",
model_id=ChatModelId.CLAUDE_V3_5_SONNET.value,
)
Create a new version of the prompt:
prompt_manager.create_prompt_version()
Retrieve a specific version of a prompt:
retrieved_prompt = prompt_manager.get_prompt(name="astronomical_questions", prompt_version=1)
Delete a prompt when it's no longer needed:
prompt_manager.delete_prompt()