load_promptPromptTemplate‚ÄãThis section covers examples for loading a PromptTemplate.Loading from YAML‚ÄãThis shows an example of loading a PromptTemplate from YAML.cat simple_prompt.yaml    _type: prompt    input_variables:        ["adjective", "content"]    template:         Tell me a {adjective} joke about {content}.prompt = load_prompt("simple_prompt.yaml")print(prompt.format(adjective="funny", content="chickens"))    Tell me a funny joke about chickens.Loading from JSON‚ÄãThis shows an example of loading a PromptTemplate from JSON.cat simple_prompt.json    {        "_type": "prompt",        "input_variables": ["adjective", "content"],        "template": "Tell me a {adjective} joke about {content}."    }prompt = load_prompt("simple_prompt.json")print(prompt.format(adjective="funny", content="chickens"))Tell me a funny joke about chickens.Loading template from a file‚ÄãThis shows an example of storing the template in a separate file and then referencing it in the config. Notice that the key changes from template to template_path.cat simple_template.txt    Tell me a {adjective} joke about {content}.cat simple_prompt_with_template_file.json    {        "_type": "prompt",        "input_variables": ["adjective", "content"],        "template_path": "simple_template.txt"    }prompt = load_prompt("simple_prompt_with_template_file.json")print(prompt.format(adjective="funny", content="chickens"))    Tell me a funny joke about chickens.FewShotPromptTemplate‚ÄãThis section covers examples for loading few-shot prompt templates.Examples‚ÄãThis shows an example of what examples stored as json might look like.cat examples.json    [        {"input": "happy", "output": "sad"},        {"input": "tall", "output": "short"}    ]And here is what the same examples stored as yaml might look like.cat examples.yaml    - input: happy      output: sad    - input: tall      output: shortLoading from YAML‚ÄãThis shows an example of loading a few-shot example from YAML.cat
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options.
It is often preferable to store prompts not as python code but as files. This can make it easy to share, store, and version prompts. This notebook covers how to do that in LangChain, walking through all the different types of prompts and the different serialization options. ->: load_promptPromptTemplate‚ÄãThis section covers examples for loading a PromptTemplate.Loading from YAML‚ÄãThis shows an example of loading a PromptTemplate from YAML.cat simple_prompt.yaml    _type: prompt    input_variables:        ["adjective", "content"]    template:         Tell me a {adjective} joke about {content}.prompt = load_prompt("simple_prompt.yaml")print(prompt.format(adjective="funny", content="chickens"))    Tell me a funny joke about chickens.Loading from JSON‚ÄãThis shows an example of loading a PromptTemplate from JSON.cat simple_prompt.json    {        "_type": "prompt",        "input_variables": ["adjective", "content"],        "template": "Tell me a {adjective} joke about {content}."    }prompt = load_prompt("simple_prompt.json")print(prompt.format(adjective="funny", content="chickens"))Tell me a funny joke about chickens.Loading template from a file‚ÄãThis shows an example of storing the template in a separate file and then referencing it in the config. Notice that the key changes from template to template_path.cat simple_template.txt    Tell me a {adjective} joke about {content}.cat simple_prompt_with_template_file.json    {        "_type": "prompt",        "input_variables": ["adjective", "content"],        "template_path": "simple_template.txt"    }prompt = load_prompt("simple_prompt_with_template_file.json")print(prompt.format(adjective="funny", content="chickens"))    Tell me a funny joke about chickens.FewShotPromptTemplate‚ÄãThis section covers examples for loading few-shot prompt templates.Examples‚ÄãThis shows an example of what examples stored as json might look like.cat examples.json    [        {"input": "happy", "output": "sad"},        {"input": "tall", "output": "short"}    ]And here is what the same examples stored as yaml might look like.cat examples.yaml    - input: happy      output: sad    - input: tall      output: shortLoading from YAML‚ÄãThis shows an example of loading a few-shot example from YAML.cat