Skip to content

Commit

Permalink
Update examples to prevent confusing missing _type warning (langchain…
Browse files Browse the repository at this point in the history
…-ai#1391)

The YAML and JSON examples of prompt serialization now give a strange
`No '_type' key found, defaulting to 'prompt'` message when you try to
run them yourself or copy the format of the files. The reason for this
harmless warning is that the _type key was not in the config files,
which means they are parsed as a standard prompt.

This could be confusing to new users (like it was confusing to me after
upgrading from 0.0.85 to 0.0.86+ for my few_shot prompts that needed a
_type added to the example_prompt config), so this update includes the
_type key just for clarity.

Obviously this is not critical as the warning is harmless, but it could
be confusing to track down or be interpreted as an error by a new user,
so this update should resolve that.
  • Loading branch information
jasongill authored Mar 2, 2023
1 parent dda5259 commit 1989e7d
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/modules/prompts/examples/example_prompt.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"_type": "prompt",
"input_variables": ["input", "output"],
"template": "Input: {input}\nOutput: {output}"
}
1 change: 1 addition & 0 deletions docs/modules/prompts/examples/few_shot_prompt.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"input_variables": ["adjective"],
"prefix": "Write antonyms for the following words.",
"example_prompt": {
"_type": "prompt",
"input_variables": ["input", "output"],
"template": "Input: {input}\nOutput: {output}"
},
Expand Down
1 change: 1 addition & 0 deletions docs/modules/prompts/examples/few_shot_prompt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ input_variables:
prefix:
Write antonyms for the following words.
example_prompt:
_type: prompt
input_variables:
["input", "output"]
template:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"input_variables": ["adjective"],
"prefix": "Write antonyms for the following words.",
"example_prompt": {
"_type": "prompt",
"input_variables": ["input", "output"],
"template": "Input: {input}\nOutput: {output}"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ input_variables:
prefix:
Write antonyms for the following words.
example_prompt:
_type: prompt
input_variables:
["input", "output"]
template:
Expand Down
10 changes: 9 additions & 1 deletion docs/modules/prompts/examples/prompt_serialization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"_type: prompt\r\n",
"input_variables:\r\n",
" [\"adjective\", \"content\"]\r\n",
"template: \r\n",
Expand Down Expand Up @@ -108,6 +109,7 @@
"output_type": "stream",
"text": [
"{\r\n",
" \"_type\": \"prompt\",\r\n",
" \"input_variables\": [\"adjective\", \"content\"],\r\n",
" \"template\": \"Tell me a {adjective} joke about {content}.\"\r\n",
"}\r\n"
Expand Down Expand Up @@ -156,6 +158,7 @@
"output_type": "stream",
"text": [
"{\r\n",
" \"_type\": \"prompt\",\r\n",
" \"input_variables\": [\"adjective\", \"content\"],\r\n",
" \"template_path\": \"simple_template.txt\"\r\n",
"}\r\n"
Expand Down Expand Up @@ -279,6 +282,7 @@
"prefix: \r\n",
" Write antonyms for the following words.\r\n",
"example_prompt:\r\n",
" _type: prompt\r\n",
" input_variables:\r\n",
" [\"input\", \"output\"]\r\n",
" template:\r\n",
Expand Down Expand Up @@ -346,6 +350,7 @@
"prefix: \r\n",
" Write antonyms for the following words.\r\n",
"example_prompt:\r\n",
" _type: prompt\r\n",
" input_variables:\r\n",
" [\"input\", \"output\"]\r\n",
" template:\r\n",
Expand Down Expand Up @@ -413,6 +418,7 @@
" \"input_variables\": [\"adjective\"],\r\n",
" \"prefix\": \"Write antonyms for the following words.\",\r\n",
" \"example_prompt\": {\r\n",
" \"_type\": \"prompt\",\r\n",
" \"input_variables\": [\"input\", \"output\"],\r\n",
" \"template\": \"Input: {input}\\nOutput: {output}\"\r\n",
" },\r\n",
Expand Down Expand Up @@ -478,6 +484,7 @@
" \"input_variables\": [\"adjective\"],\r\n",
" \"prefix\": \"Write antonyms for the following words.\",\r\n",
" \"example_prompt\": {\r\n",
" \"_type\": \"prompt\",\r\n",
" \"input_variables\": [\"input\", \"output\"],\r\n",
" \"template\": \"Input: {input}\\nOutput: {output}\"\r\n",
" },\r\n",
Expand Down Expand Up @@ -542,6 +549,7 @@
"output_type": "stream",
"text": [
"{\r\n",
" \"_type\": \"prompt\",\r\n",
" \"input_variables\": [\"input\", \"output\"],\r\n",
" \"template\": \"Input: {input}\\nOutput: {output}\" \r\n",
"}\r\n"
Expand Down Expand Up @@ -622,7 +630,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.11.2"
},
"vscode": {
"interpreter": {
Expand Down
1 change: 1 addition & 0 deletions docs/modules/prompts/examples/simple_prompt.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"_type": "prompt",
"input_variables": ["adjective", "content"],
"template": "Tell me a {adjective} joke about {content}."
}
1 change: 1 addition & 0 deletions docs/modules/prompts/examples/simple_prompt.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_type: prompt
input_variables:
["adjective", "content"]
template:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"_type": "prompt",
"input_variables": ["adjective", "content"],
"template_path": "simple_template.txt"
}

0 comments on commit 1989e7d

Please sign in to comment.