Skip to content

A helper library that seamlessly integrates LangChain prompt templates with Amazon Bedrock's Prompt Management API, enabling efficient cross-platform prompt handling.

License

Notifications You must be signed in to change notification settings

aldente0630/bedrock-langchain-prompt-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bedrock LangChain Prompt Converter

picture
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.

Usage

1. Creating a Chat Prompt Template

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}"),
    ]
)

2. Initializing the Prompt Manager

Initialize the PromptManager with your AWS region:

from src import PromptManager

prompt_manager = PromptManager(
    {
        "region_name": "us-west-2"
    }
)

3. Creating a Prompt

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,
)

4. Creating a Prompt Version

Create a new version of the prompt:

prompt_manager.create_prompt_version()

5. Retrieving a Prompt

Retrieve a specific version of a prompt:

retrieved_prompt = prompt_manager.get_prompt(name="astronomical_questions", prompt_version=1)

6. Deleting a Prompt

Delete a prompt when it's no longer needed:

prompt_manager.delete_prompt()

Additional Resources

License

MIT License

About

A helper library that seamlessly integrates LangChain prompt templates with Amazon Bedrock's Prompt Management API, enabling efficient cross-platform prompt handling.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages