|
1 | 1 | require "langchain" |
2 | 2 |
|
3 | 3 | # Create a prompt with one input variable |
4 | | -prompt = Langchain::Prompt::PromptTemplate.new(template: "Tell me a {adjective} joke.", input_variables: ["adjective"]) |
| 4 | +prompt = LangChain::Prompt::PromptTemplate.new(template: "Tell me a {adjective} joke.", input_variables: ["adjective"]) |
5 | 5 | prompt.format(adjective: "funny") # "Tell me a funny joke." |
6 | 6 |
|
7 | 7 | # Create a prompt with multiple input variables |
8 | | -prompt = Langchain::Prompt::PromptTemplate.new(template: "Tell me a {adjective} joke about {content}.", input_variables: ["adjective", "content"]) |
| 8 | +prompt = LangChain::Prompt::PromptTemplate.new(template: "Tell me a {adjective} joke about {content}.", input_variables: ["adjective", "content"]) |
9 | 9 | prompt.format(adjective: "funny", content: "chickens") # "Tell me a funny joke about chickens." |
10 | 10 |
|
11 | 11 | # Creating a PromptTemplate using just a prompt and no input_variables |
12 | | -prompt = Langchain::Prompt::PromptTemplate.from_template("Tell me a {adjective} joke about {content}.") |
| 12 | +prompt = LangChain::Prompt::PromptTemplate.from_template("Tell me a {adjective} joke about {content}.") |
13 | 13 | prompt.input_variables # ["adjective", "content"] |
14 | 14 | prompt.format(adjective: "funny", content: "chickens") # "Tell me a funny joke about chickens." |
15 | 15 |
|
16 | 16 | # Save prompt template to JSON file |
17 | 17 | prompt.save(file_path: "spec/fixtures/prompt/prompt_template.json") |
18 | 18 |
|
19 | 19 | # Loading a new prompt template using a JSON file |
20 | | -prompt = Langchain::Prompt.load_from_path(file_path: "spec/fixtures/prompt/prompt_template.json") |
| 20 | +prompt = LangChain::Prompt.load_from_path(file_path: "spec/fixtures/prompt/prompt_template.json") |
21 | 21 | prompt.input_variables # ["adjective", "content"] |
22 | 22 |
|
23 | 23 | # Loading a new prompt template using a YAML file |
24 | | -prompt = Langchain::Prompt.load_from_path(file_path: "spec/fixtures/prompt/prompt_template.yaml") |
| 24 | +prompt = LangChain::Prompt.load_from_path(file_path: "spec/fixtures/prompt/prompt_template.yaml") |
25 | 25 | prompt.input_variables # ["adjective", "content"] |
0 commit comments