langchain/docs/scripts
Really Him fbd2e10703
docs: hide jsx in llm chain tutorial (#30187)
## **Description:** 
The Jupyter notebooks in the docs section are extremely useful and
critical for widespread adoption of LangChain amongst new developers.
However, because they are also converted to MDX and used to build the
HTML for the Docusaurus site, they contain JSX code that degrades
readability when opened in a "notebook" setting (local notebook server,
google colab, etc.). For instance, here we see the website, with a nice
React tab component for installation instructions (`pip` vs `conda`):

![Screenshot 2025-03-07 at 2 07
15 PM](https://github.com/user-attachments/assets/a528d618-f5a0-4d2e-9aed-16d4b8148b5a)

Now, here is the same notebook viewed in colab:

![Screenshot 2025-03-07 at 2 08
41 PM](https://github.com/user-attachments/assets/87acf5b7-a3e0-46ac-8126-6cac6eb93586)

Note that the text following "To install LangChain run:" contains
snippets of JSX code that is (i) confusing, (ii) bad for readability,
(iii) potentially misleading for a novice developer, who might take it
literally to mean that "to install LangChain I should run `import Tabs
from...`" and then an ill-formed command which mixes the `pip` and
`conda` installation instructions.

Ideally, we would like to have a system that presents a
similar/equivalent UI when viewing the notebooks on the documentation
site, or when interacting with them in a notebook setting - or, at a
minimum, we should not present ill-formed JSX snippets to someone trying
to execute the notebooks. As the documentation itself states, running
the notebooks yourself is a great way to learn the tools. Therefore,
these distracting and ill-formed snippets are contrary to that goal.

## **Fixes:**
* Comment out the JSX code inside the notebook
`docs/tutorials/llm_chain` with a special directive `<!-- HIDE_IN_NB`
(closed with `HIDE_IN_NB -->`). This makes the JSX code "invisible" when
viewed in a notebook setting.
* Add a custom preprocessor that runs process_cell and just erases these
comment strings. This makes sure they are rendered when converted to
MDX.
* Minor tweak: Refactor some of the Markdown instructions into an
executable codeblock for better experience when running as a notebook.
* Minor tweak: Optionally try to get the environment variables from a
`.env` file in the repo so the user doesn't have to enter it every time.
Depends on the user installing `python-dotenv` and adding their own
`.env` file.
* Add an environment variable for "LANGSMITH_PROJECT"
(default="default"), per the LangSmith docs, so a local user can target
a specific project in their LangSmith account.

**NOTE:** If this PR is approved, and the maintainers agree with the
general goal of aligning the notebook execution experience and the doc
site UI, I would plan to implement this on the rest of the JSX snippets
that are littered in the notebooks.

**NOTE:** I wasn't able to/don't know how to run the linkcheck Makefile
commands.

- [X] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/

---------

Co-authored-by: Really Him <hesereallyhim@proton.me>
2025-03-26 14:22:33 -04:00
..
notebook_convert_templates/mdoutput docs, standard-tests: how to standard test a custom tool, imports (#27931) 2024-11-15 10:49:14 -08:00
append_related_links.py docs: fix more links (#27598) 2024-10-23 21:26:38 -04:00
arxiv_references.py templates,docs: leave templates in v0.2 (#27952) 2024-11-07 22:23:48 +00:00
cache_data.py docs: run how-to guides in CI (#27615) 2024-10-30 12:35:38 -04:00
check_imports.py docs: format (#21132) 2024-04-30 23:32:41 +00:00
check_templates.py community: Add OpenGradient integration (Toolkit) (#30190) 2025-03-09 18:08:07 -04:00
check-broken-links.js ci[minor]: Bump LC scripts package, add retry option (#19285) 2024-03-19 10:42:59 -07:00
create_chat_model_docstring_tables.py docs: BaseChatModel key methods table (#23238) 2024-06-20 21:00:22 -07:00
document_loader_feat_table.py docs: reorganize contributing docs (#27649) 2024-10-25 22:41:54 +00:00
execute_notebooks.sh infra: migrate to uv (#29566) 2025-02-06 13:36:26 -05:00
generate_api_reference_links.py docs: more useful vercel warnings (#28699) 2024-12-13 03:07:24 +00:00
kv_store_feat_table.py docs: fix more broken links (#27806) 2024-10-31 19:46:39 +00:00
notebook_convert.py docs: hide jsx in llm chain tutorial (#30187) 2025-03-26 14:22:33 -04:00
packages_yml_get_downloads.py packages: update counts, add command (#29789) 2025-02-13 20:45:25 +00:00
partner_deps_list.py docs: more useful vercel warnings (#28699) 2024-12-13 03:07:24 +00:00
partner_pkg_table.py docs: fix partner package table build for packages with no download stats (#29871) 2025-02-19 11:05:57 +13:00
prepare_notebooks_for_ci.py Switch graphqa example in docs to langgraph (#28574) 2024-12-09 14:46:00 -05:00
resolve_local_links.py docs: edit links, direct for notebooks (#22051) 2024-05-24 19:44:46 +00:00
tool_feat_table.py docs: Add AgentQL provider doc, tool/toolkit doc and documentloader doc (#30144) 2025-03-11 21:57:40 -04:00
update_cassettes.sh infra: migrate to uv (#29566) 2025-02-06 13:36:26 -05:00
vectorstore_feat_table.py [docs]: vector store integration pages (#24858) 2024-08-06 17:20:27 +00:00