mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-06 09:55:21 +03:00
13 KiB
13 KiB
In [1]:
# All prompts are loaded through the `load_prompt` function.
from langchain.prompts import load_promptIn [2]:
!cat simple_prompt.yamlinput_variables:
["adjective", "content"]
template:
Tell me a {adjective} joke about {content}.
In [3]:
prompt = load_prompt("simple_prompt.yaml")
print(prompt.format(adjective="funny", content="chickens"))Tell me a funny joke about chickens.
In [4]:
!cat simple_prompt.json{
"input_variables": ["adjective", "content"],
"template": "Tell me a {adjective} joke about {content}."
}
In [5]:
!cat simple_template.txtTell me a {adjective} joke about {content}.In [6]:
!cat simple_prompt_with_template_file.json{
"input_variables": ["adjective", "content"],
"template_path": "simple_template.txt"
}
In [7]:
prompt = load_prompt("simple_prompt_with_template_file.json")
print(prompt.format(adjective="funny", content="chickens"))Tell me a funny joke about chickens.
In [8]:
!cat examples.json[
{"input": "happy", "output": "sad"},
{"input": "tall", "output": "short"}
]
In [9]:
!cat few_shot_prompt.yaml_type: few_shot
input_variables:
["adjective"]
prefix:
Write antonyms for the following words.
example_prompt:
input_variables:
["input", "output"]
template:
"Input: {input}\nOutput: {output}"
examples:
examples.json
suffix:
"Input: {adjective}\nOutput:"
In [10]:
prompt = load_prompt("few_shot_prompt.yaml")
print(prompt.format(adjective="funny"))Write antonyms for the following words. Input: happy Output: sad Input: tall Output: short Input: funny Output:
In [11]:
!cat few_shot_prompt.json{
"_type": "few_shot",
"input_variables": ["adjective"],
"prefix": "Write antonyms for the following words.",
"example_prompt": {
"input_variables": ["input", "output"],
"template": "Input: {input}\nOutput: {output}"
},
"examples": "examples.json",
"suffix": "Input: {adjective}\nOutput:"
}
In [12]:
prompt = load_prompt("few_shot_prompt.json")
print(prompt.format(adjective="funny"))Write antonyms for the following words. Input: happy Output: sad Input: tall Output: short Input: funny Output:
In [13]:
!cat few_shot_prompt_examples_in.json{
"_type": "few_shot",
"input_variables": ["adjective"],
"prefix": "Write antonyms for the following words.",
"example_prompt": {
"input_variables": ["input", "output"],
"template": "Input: {input}\nOutput: {output}"
},
"examples": [
{"input": "happy", "output": "sad"},
{"input": "tall", "output": "short"}
],
"suffix": "Input: {adjective}\nOutput:"
}
In [14]:
prompt = load_prompt("few_shot_prompt_examples_in.json")
print(prompt.format(adjective="funny"))Write antonyms for the following words. Input: happy Output: sad Input: tall Output: short Input: funny Output:
In [15]:
!cat example_prompt.json{
"input_variables": ["input", "output"],
"template": "Input: {input}\nOutput: {output}"
}
In [16]:
!cat few_shot_prompt_example_prompt.json {
"_type": "few_shot",
"input_variables": ["adjective"],
"prefix": "Write antonyms for the following words.",
"example_prompt_path": "example_prompt.json",
"examples": "examples.json",
"suffix": "Input: {adjective}\nOutput:"
}
In [17]:
prompt = load_prompt("few_shot_prompt_example_prompt.json")
print(prompt.format(adjective="funny"))Write antonyms for the following words. Input: happy Output: sad Input: tall Output: short Input: funny Output:
In [ ]: