Skip to content

Commit 8baf6fb

Browse files
authored
Update examples to fix execution problems (#685)
On the [Getting Started page](https://langchain.readthedocs.io/en/latest/modules/prompts/getting_started.html) for prompt templates, I believe the very last example ```python print(dynamic_prompt.format(adjective=long_string)) ``` should actually be ```python print(dynamic_prompt.format(input=long_string)) ``` The existing example produces `KeyError: 'input'` as expected *** On the [Create a custom prompt template](https://langchain.readthedocs.io/en/latest/modules/prompts/examples/custom_prompt_template.html#id1) page, I believe the line ```python Function Name: {kwargs["function_name"]} ``` should actually be ```python Function Name: {kwargs["function_name"].__name__} ``` The existing example produces the prompt: ``` Given the function name and source code, generate an English language explanation of the function. Function Name: <function get_source_code at 0x7f907bc0e0e0> Source Code: def get_source_code(function_name): # Get the source code of the function return inspect.getsource(function_name) Explanation: ``` *** On the [Example Selectors](https://langchain.readthedocs.io/en/latest/modules/prompts/examples/example_selectors.html) page, the first example does not define `example_prompt`, which is also subtly different from previous example prompts used. For user convenience, I suggest including ```python example_prompt = PromptTemplate( input_variables=["input", "output"], template="Input: {input}\nOutput: {output}", ) ``` in the code to be copy-pasted
1 parent 86dbdb1 commit 8baf6fb

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

docs/modules/prompts/examples/custom_prompt_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class FunctionExplainerPromptTemplate(BasePromptTemplate, BaseModel):
5454
# Generate the prompt to be sent to the language model
5555
prompt = f"""
5656
Given the function name and source code, generate an English language explanation of the function.
57-
Function Name: {kwargs["function_name"]}
57+
Function Name: {kwargs["function_name"].__name__}
5858
Source Code:
5959
{source_code}
6060
Explanation:

docs/modules/prompts/examples/example_selectors.ipynb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"metadata": {},
4949
"outputs": [],
5050
"source": [
51+
"from langchain.prompts import PromptTemplate\n",
5152
"from langchain.prompts.example_selector import LengthBasedExampleSelector"
5253
]
5354
},
@@ -75,6 +76,10 @@
7576
"metadata": {},
7677
"outputs": [],
7778
"source": [
79+
"example_prompt = PromptTemplate(\n",
80+
" input_variables=[\"input\", \"output\"],\n",
81+
" template=\"Input: {input}\\nOutput: {output}\",\n",
82+
")\n",
7883
"example_selector = LengthBasedExampleSelector(\n",
7984
" # These are the examples is has available to choose from.\n",
8085
" examples=examples, \n",

docs/modules/prompts/getting_started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ In contrast, if we provide a very long input, the `LengthBasedExampleSelector` w
211211

212212
```python
213213
long_string = "big and huge and massive and large and gigantic and tall and much much much much much bigger than everything else"
214-
print(dynamic_prompt.format(adjective=long_string))
214+
print(dynamic_prompt.format(input=long_string))
215215
# -> Give the antonym of every input
216216

217217
# -> Word: happy

0 commit comments

Comments
 (0)