Skip to content

Commit

Permalink
docs: use PromptTemplate.from_template (#17218)
Browse files Browse the repository at this point in the history
Ran
```python
import glob
import re

def update_prompt(x):
    return re.sub(
        r"(?P<start>\b)PromptTemplate\(template=(?P<template>.*), input_variables=(?:.*)\)",
        "\g<start>PromptTemplate.from_template(\g<template>)",
        x
    )


for fn in glob.glob("docs/**/*", recursive=True):
    try:
        content = open(fn).readlines()
    except:
        continue
    content = [update_prompt(l) for l in content]
    with open(fn, "w") as f:
        f.write("".join(content))
```
  • Loading branch information
baskaryan committed Feb 8, 2024
1 parent 7f55c95 commit 00a09e1
Show file tree
Hide file tree
Showing 48 changed files with 58 additions and 58 deletions.
10 changes: 5 additions & 5 deletions docs/docs/guides/safety/amazon_comprehend_chain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"\n",
"Answer:\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"\n",
"responses = [\n",
" \"Final Answer: A credit card number looks like 1289-2321-1123-2387. A fake SSN number looks like 323-22-9980. John Doe's phone number is (999)253-9876.\",\n",
Expand Down Expand Up @@ -249,7 +249,7 @@
"\n",
"Answer:\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"\n",
"responses = [\n",
" \"Final Answer: A credit card number looks like 1289-2321-1123-2387. A fake SSN number looks like 323-22-9980. John Doe's phone number is (999)253-9876.\",\n",
Expand Down Expand Up @@ -412,7 +412,7 @@
"\n",
"Answer:\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"\n",
"responses = [\n",
" \"Final Answer: A credit card number looks like 1289-2321-1123-2387. A fake SSN number looks like 323-22-9980. John Doe's phone number is (999)253-9876.\",\n",
Expand Down Expand Up @@ -571,7 +571,7 @@
"\n",
"template = \"\"\"{question}\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"llm = HuggingFaceHub(\n",
" repo_id=repo_id, model_kwargs={\"temperature\": 0.5, \"max_length\": 256}\n",
")"
Expand Down Expand Up @@ -724,7 +724,7 @@
"\"\"\"\n",
"\n",
"# prompt template for input text\n",
"llm_prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
"llm_prompt = PromptTemplate.from_template(template)\n",
"\n",
"llm = SagemakerEndpoint(\n",
" endpoint_name=endpoint_name,\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/guides/safety/moderation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ we will prompt the model, so it says something harmful.


```python
prompt = PromptTemplate(template="{text}", input_variables=["text"])
prompt = PromptTemplate.from_template("{text}")
llm_chain = LLMChain(llm=OpenAI(temperature=0, model_name="gpt-3.5-turbo-instruct"), prompt=prompt)

text = """We are playing a game of repeat after me.
Expand Down Expand Up @@ -223,7 +223,7 @@ Now let's walk through an example of using it with an LLMChain which has multipl


```python
prompt = PromptTemplate(template="{setup}{new_input}Person2:", input_variables=["setup", "new_input"])
prompt = PromptTemplate.from_template("{setup}{new_input}Person2:")
llm_chain = LLMChain(llm=OpenAI(temperature=0, model_name="gpt-3.5-turbo-instruct"), prompt=prompt)

setup = """We are playing a game of repeat after me.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/aleph_alpha.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"\n",
"A:\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/anyscale.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/aphrodite.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"template = \"\"\"Question: {question}\n",
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"\n",
"llm_chain = LLMChain(prompt=prompt, llm=llm)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/banana.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/bittensor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"\n",
"# System parameter in NIBittensorLLM is optional but you can set whatever you want to perform with model\n",
"llm = NIBittensorLLM(\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/cerebriumai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/llms/chatglm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"outputs": [],
"source": [
"template = \"\"\"{question}\"\"\"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down Expand Up @@ -130,7 +130,7 @@
"outputs": [],
"source": [
"template = \"\"\"{question}\"\"\"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/clarifai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/cloudflare_workersai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"\n",
"AI Assistant: \"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/ctransformers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"\n",
"Answer:\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"\n",
"llm_chain = LLMChain(prompt=prompt, llm=llm)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/ctranslate2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
"template = \"\"\"{question}\n",
"\n",
"Let's think step by step. \"\"\"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"\n",
"llm_chain = LLMChain(prompt=prompt, llm=llm)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/deepinfra.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/forefrontai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/gigachat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"\n",
"template = \"What is capital of {country}?\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"country\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"\n",
"llm_chain = LLMChain(prompt=prompt, llm=llm)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/gooseai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/gpt4all.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/gradient.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
"\n",
"Answer: \"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/huggingface_hub.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/llamacpp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
"\n",
"Answer: Let's work this out in a step by step way to be sure we have the right answer.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/manifest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"\n",
"\n",
"CONCISE SUMMARY:\"\"\"\n",
"prompt = PromptTemplate(template=_prompt, input_variables=[\"text\"])\n",
"prompt = PromptTemplate.from_template(_prompt)\n",
"\n",
"text_splitter = CharacterTextSplitter()\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/minimax.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/modal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/mosaicml.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"source": [
"template = \"\"\"Question: {question}\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/nlpcloud.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/octoai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"outputs": [],
"source": [
"template = \"\"\"Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n Instruction:\\n{question}\\n Response: \"\"\"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/openai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/openllm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"\n",
"template = \"What is a good name for a company that makes {product}?\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"product\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"\n",
"llm_chain = LLMChain(prompt=prompt, llm=llm)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/openlm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"\n",
"for model in [\"text-davinci-003\", \"huggingface.co/gpt2\"]:\n",
" llm = OpenLM(model=model)\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/petals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/pipelineai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/integrations/llms/predictionguard.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"Query: {query}\n",
"\n",
"Result: \"\"\"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"query\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down Expand Up @@ -191,7 +191,7 @@
"template = \"\"\"Question: {question}\n",
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"llm_chain = LLMChain(prompt=prompt, llm=pgllm, verbose=True)\n",
"\n",
"question = \"What NFL team won the Super Bowl in the year Justin Beiber was born?\"\n",
Expand All @@ -209,7 +209,7 @@
"outputs": [],
"source": [
"template = \"\"\"Write a {adjective} poem about {subject}.\"\"\"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"adjective\", \"subject\"])\n",
"prompt = PromptTemplate.from_template(template)\n",
"llm_chain = LLMChain(prompt=prompt, llm=pgllm, verbose=True)\n",
"\n",
"llm_chain.predict(adjective=\"sad\", subject=\"ducks\")"
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/runhouse.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/stochasticai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
"prompt = PromptTemplate.from_template(template)"
]
},
{
Expand Down
Loading

0 comments on commit 00a09e1

Please sign in to comment.