docs: fix a couple of small indentation errors in the strings (#7951)

Fixed a few indentations I came across in the docs @baskaryan
This commit is contained in:
Jithin James 2023-07-20 19:04:01 +05:30 committed by GitHub
parent 73901ef132
commit 493cbc9410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 29 deletions

View File

@ -36,7 +36,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 1,
"id": "c831e1ce", "id": "c831e1ce",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -59,7 +59,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 2,
"id": "3ad1efdc", "id": "3ad1efdc",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -67,6 +67,14 @@
"from langchain.prompts import StringPromptTemplate\n", "from langchain.prompts import StringPromptTemplate\n",
"from pydantic import BaseModel, validator\n", "from pydantic import BaseModel, validator\n",
"\n", "\n",
"PROMPT = \"\"\"\\\n",
"Given the function name and source code, generate an English language explanation of the function.\n",
"Function Name: {function_name}\n",
"Source Code:\n",
"{source_code}\n",
"Explanation:\n",
"\"\"\"\n",
"\n",
"\n", "\n",
"class FunctionExplainerPromptTemplate(StringPromptTemplate, BaseModel):\n", "class FunctionExplainerPromptTemplate(StringPromptTemplate, BaseModel):\n",
" \"\"\"A custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function.\"\"\"\n", " \"\"\"A custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function.\"\"\"\n",
@ -83,13 +91,9 @@
" source_code = get_source_code(kwargs[\"function_name\"])\n", " source_code = get_source_code(kwargs[\"function_name\"])\n",
"\n", "\n",
" # Generate the prompt to be sent to the language model\n", " # Generate the prompt to be sent to the language model\n",
" prompt = f\"\"\"\n", " prompt = PROMPT.format(\n",
" Given the function name and source code, generate an English language explanation of the function.\n", " function_name=kwargs[\"function_name\"].__name__, source_code=source_code\n",
" Function Name: {kwargs[\"function_name\"].__name__}\n", " )\n",
" Source Code:\n",
" {source_code}\n",
" Explanation:\n",
" \"\"\"\n",
" return prompt\n", " return prompt\n",
"\n", "\n",
" def _prompt_type(self):\n", " def _prompt_type(self):\n",
@ -108,7 +112,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 3,
"id": "bd836cda", "id": "bd836cda",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -116,16 +120,15 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\n", "Given the function name and source code, generate an English language explanation of the function.\n",
" Given the function name and source code, generate an English language explanation of the function.\n", "Function Name: get_source_code\n",
" Function Name: get_source_code\n", "Source Code:\n",
" Source Code:\n", "def get_source_code(function_name):\n",
" def get_source_code(function_name):\n",
" # Get the source code of the function\n", " # Get the source code of the function\n",
" return inspect.getsource(function_name)\n", " return inspect.getsource(function_name)\n",
"\n", "\n",
" Explanation:\n", "Explanation:\n",
" \n" "\n"
] ]
} }
], ],
@ -136,14 +139,6 @@
"prompt = fn_explainer.format(function_name=get_source_code)\n", "prompt = fn_explainer.format(function_name=get_source_code)\n",
"print(prompt)" "print(prompt)"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7f3161c6",
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
@ -162,7 +157,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.11.3" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -4,7 +4,7 @@ Here's the simplest example:
from langchain import PromptTemplate from langchain import PromptTemplate
template = """/ template = """\
You are a naming consultant for new companies. You are a naming consultant for new companies.
What is a good name for a company that makes {product}? What is a good name for a company that makes {product}?
""" """
@ -16,8 +16,8 @@ prompt.format(product="colorful socks")
<CodeOutputBlock lang="python"> <CodeOutputBlock lang="python">
``` ```
You are a naming consultant for new companies. You are a naming consultant for new companies.
What is a good name for a company that makes colorful socks? What is a good name for a company that makes colorful socks?
``` ```
</CodeOutputBlock> </CodeOutputBlock>