diff --git a/docs/docs/tutorials/llm_chain.ipynb b/docs/docs/tutorials/llm_chain.ipynb index 0b9547568b2..690b51aadda 100644 --- a/docs/docs/tutorials/llm_chain.ipynb +++ b/docs/docs/tutorials/llm_chain.ipynb @@ -39,6 +39,7 @@ "\n", "To install LangChain run:\n", "\n", + "" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "86874822", + "metadata": {}, + "outputs": [], + "source": [ + "# | output: false\n", "\n", - "\n", - "\n", + "# %pip install langchain\n", + "# OR\n", + "# %conda install langchain -c conda-forge" + ] + }, + { + "cell_type": "markdown", + "id": "a546a5bc", + "metadata": {}, + "source": [ "For more details, see our [Installation guide](/docs/how_to/installation).\n", "\n", "### LangSmith\n", @@ -67,17 +87,45 @@ "```shell\n", "export LANGSMITH_TRACING=\"true\"\n", "export LANGSMITH_API_KEY=\"...\"\n", + "export LANGSMITH_PROJECT=\"default\" # or any other project name\n", "```\n", "\n", - "Or, if in a notebook, you can set them with:\n", - "\n", - "```python\n", + "Or, if in a notebook, you can set them with:" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "599bb688", + "metadata": {}, + "outputs": [], + "source": [ "import getpass\n", "import os\n", "\n", + "try:\n", + " # load environment variables from .env file (requires `python-dotenv`)\n", + " from dotenv import load_dotenv\n", + "\n", + " load_dotenv()\n", + "except ImportError:\n", + " pass\n", + "\n", "os.environ[\"LANGSMITH_TRACING\"] = \"true\"\n", - "os.environ[\"LANGSMITH_API_KEY\"] = getpass.getpass()\n", - "```" + "if \"LANGSMITH_API_KEY\" not in os.environ:\n", + " os.environ[\"LANGSMITH_API_KEY\"] = getpass.getpass(\n", + " prompt=\"Enter your LangSmith API key (optional): \"\n", + " )\n", + "if \"LANGSMITH_PROJECT\" not in os.environ:\n", + " os.environ[\"LANGSMITH_PROJECT\"] = getpass.getpass(\n", + " prompt='Enter your LangSmith Project Name (default = \"default\"): '\n", + " )\n", + " if not os.environ.get(\"LANGSMITH_PROJECT\"):\n", + " os.environ[\"LANGSMITH_PROJECT\"] = \"default\"\n", + "if \"OPENAI_API_KEY\" not in os.environ:\n", + " os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\n", + " prompt=\"Enter your OpenAI API key (required if using OpenAI): \"\n", + " )" ] }, { @@ -89,9 +137,11 @@ "\n", "First up, let's learn how to use a language model by itself. LangChain supports many different language models that you can use interchangeably. For details on getting started with a specific model, refer to [supported integrations](/docs/integrations/chat/).\n", "\n", + "" ] }, { diff --git a/docs/scripts/notebook_convert.py b/docs/scripts/notebook_convert.py index fb0e3c80756..33da9a5d30b 100644 --- a/docs/scripts/notebook_convert.py +++ b/docs/scripts/notebook_convert.py @@ -9,9 +9,12 @@ import nbformat from nbconvert.exporters import MarkdownExporter from nbconvert.preprocessors import Preprocessor +HIDE_IN_NB_MAGIC_OPEN = "" + class EscapePreprocessor(Preprocessor): - def preprocess_cell(self, cell, resources, cell_index): + def preprocess_cell(self, cell, resources, index): if cell.cell_type == "markdown": # rewrite .ipynb links to .md cell.source = re.sub( @@ -61,7 +64,7 @@ class ExtractAttachmentsPreprocessor(Preprocessor): outputs are returned in the 'resources' dictionary. """ - def preprocess_cell(self, cell, resources, cell_index): + def preprocess_cell(self, cell, resources, index): """ Apply a transformation on each cell, Parameters @@ -117,11 +120,19 @@ class CustomRegexRemovePreprocessor(Preprocessor): return nb, resources +class UnHidePreprocessor(Preprocessor): + def preprocess_cell(self, cell, resources, index): + cell.source = cell.source.replace(HIDE_IN_NB_MAGIC_OPEN, "") + cell.source = cell.source.replace(HIDE_IN_NB_MAGIC_CLOSE, "") + return cell, resources + + exporter = MarkdownExporter( preprocessors=[ EscapePreprocessor, ExtractAttachmentsPreprocessor, CustomRegexRemovePreprocessor, + UnHidePreprocessor, ], template_name="mdoutput", extra_template_basedirs=["./scripts/notebook_convert_templates"],