langchain support dynamic placeholders inside a string, which able to set placeholders…
Private research annotation
Sign in to add a private research label or note.
- User
langchain support dynamic placeholders inside a string, which able to set placeholders first and then assign values to the placeholders later, for example : prompt_template = PromptTemplate.from_template( "Write a delicious recipe for {dish} with a {flavor} twist." ) formatted_prompt = prompt_template.format(dish="pasta", flavor="spicy")
is it a native python string feature or is it an exclusive feature from langchain?
Assistant
The feature you're referring to is not native to Python strings, but rather a method provided by the
strclass in Python, specifically theformat()method. However, the syntax you used (PromptTemplate.from_template()andformat()) seems to be specific to thelangchainlibrary.Here's how you can achieve the same result using the native Python
strclass:pythonrecipe_template = "Write a delicious recipe for {dish} with a {flavor} twist." formatted_recipe = recipe_template.format(dish="pasta", flavor="spicy") print(formatted_recipe)This will output:
codeWrite a delicious recipe for pasta with a spicy twist.In Python 3.6 and later, you can also use the f-strings feature to achieve the same result:
python