diff --git a/docs/modules/document_loaders/examples/notebook.ipynb b/docs/modules/document_loaders/examples/notebook.ipynb index db1a4fdc..07cb4ef6 100644 --- a/docs/modules/document_loaders/examples/notebook.ipynb +++ b/docs/modules/document_loaders/examples/notebook.ipynb @@ -1,7 +1,6 @@ { "cells": [ { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -12,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -21,15 +20,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "loader = NotebookLoader(\"example_data/notebook.ipynb\")" + "loader = NotebookLoader(\"example_data/notebook.ipynb\", include_outputs=True, max_output_length=20, remove_newline=True)" ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -45,17 +43,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[Document(page_content='\\'markdown\\' cell: \\'[\\'# Notebook\\', \\'\\', \\'This notebook covers how to load data from an .ipynb notebook into a format suitable by LangChain.\\']\\'\\n\\n \\'code\\' cell: \\'[\\'from langchain.document_loaders import NotebookLoader\\']\\'\\n\\n \\'code\\' cell: \\'[\\'loader = NotebookLoader(\"example_data/notebook.ipynb\")\\']\\'\\n\\n \\'markdown\\' cell: \\'[\\'`NotebookLoader.load()` loads the `.ipynb` notebook file into a `Document` object.\\', \\'\\', \\'**Parameters**:\\', \\'\\', \\'* `include_outputs` (bool): whether to include cell outputs in the resulting document (default is False).\\', \\'* `max_output_length` (int): the maximum number of characters to include from each cell output (default is 10).\\', \\'* `remove_newline` (bool): whether to remove newline characters from the cell sources and outputs (default is False).\\', \\'* `traceback` (bool): whether to include full traceback (default is False).\\']\\'\\n\\n \\'code\\' cell: \\'[\\'loader.load(include_outputs=True, max_output_length=20, remove_newline=True)\\']\\'\\n\\n', lookup_str='', metadata={'source': 'example_data/notebook.ipynb'}, lookup_index=0)]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "loader.load(include_outputs=True, max_output_length=20, remove_newline=True)" + "loader.load()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -69,9 +85,8 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.1" + "version": "3.9.1" }, - "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "981b6680a42bdb5eb22187741e1607b3aae2cf73db800d1af1f268d1de6a1f70" diff --git a/langchain/document_loaders/notebook.py b/langchain/document_loaders/notebook.py index 53ca5a72..5db545ff 100644 --- a/langchain/document_loaders/notebook.py +++ b/langchain/document_loaders/notebook.py @@ -61,16 +61,23 @@ def remove_newlines(x: Any) -> Any: class NotebookLoader(BaseLoader): """Loader that loads .ipynb notebook files.""" - def __init__(self, path: str): - """Initialize with path.""" - self.file_path = path - - def load( + def __init__( self, + path: str, include_outputs: bool = False, max_output_length: int = 10, remove_newline: bool = False, traceback: bool = False, + ): + """Initialize with path.""" + self.file_path = path + self.include_outputs = include_outputs + self.max_output_length = max_output_length + self.remove_newline = remove_newline + self.traceback = traceback + + def load( + self, ) -> List[Document]: """Load documents.""" try: @@ -87,12 +94,12 @@ class NotebookLoader(BaseLoader): data = pd.json_normalize(d["cells"]) filtered_data = data[["cell_type", "source", "outputs"]] - if remove_newline: + if self.remove_newline: filtered_data = filtered_data.applymap(remove_newlines) text = filtered_data.apply( lambda x: concatenate_cells( - x, include_outputs, max_output_length, traceback + x, self.include_outputs, self.max_output_length, self.traceback ), axis=1, ).str.cat(sep=" ") diff --git a/langchain/llms/anthropic.py b/langchain/llms/anthropic.py index f2e1df4d..a5c57a94 100644 --- a/langchain/llms/anthropic.py +++ b/langchain/llms/anthropic.py @@ -18,7 +18,7 @@ class Anthropic(LLM, BaseModel): Example: .. code-block:: python import anthropic - from langchain import Anthropic + from langchain.llms import Anthropic model = Anthropic(model="", anthropic_api_key="my-api-key") # Simplest invocation, automatically wrapped with HUMAN_PROMPT diff --git a/langchain/llms/bananadev.py b/langchain/llms/bananadev.py index 94440441..03d336c2 100644 --- a/langchain/llms/bananadev.py +++ b/langchain/llms/bananadev.py @@ -22,8 +22,8 @@ class Banana(LLM, BaseModel): Example: .. code-block:: python - from langchain import Banana - cerebrium = Banana(model_key="") + from langchain.llms import Banana + banana = Banana(model_key="") """ model_key: str = "" diff --git a/langchain/llms/cerebriumai.py b/langchain/llms/cerebriumai.py index ca219be1..29f0d2fc 100644 --- a/langchain/llms/cerebriumai.py +++ b/langchain/llms/cerebriumai.py @@ -22,7 +22,7 @@ class CerebriumAI(LLM, BaseModel): Example: .. code-block:: python - from langchain import CerebriumAI + from langchain.llms import CerebriumAI cerebrium = CerebriumAI(endpoint_url="") """ diff --git a/langchain/llms/cohere.py b/langchain/llms/cohere.py index de246e22..66bff40e 100644 --- a/langchain/llms/cohere.py +++ b/langchain/llms/cohere.py @@ -21,7 +21,7 @@ class Cohere(LLM, BaseModel): Example: .. code-block:: python - from langchain import Cohere + from langchain.llms import Cohere cohere = Cohere(model="gptd-instruct-tft", cohere_api_key="my-api-key") """ diff --git a/langchain/llms/deepinfra.py b/langchain/llms/deepinfra.py index c1dce50f..8993a4bf 100644 --- a/langchain/llms/deepinfra.py +++ b/langchain/llms/deepinfra.py @@ -23,7 +23,7 @@ class DeepInfra(LLM, BaseModel): Example: .. code-block:: python - from langchain import DeepInfra + from langchain.llms import DeepInfra di = DeepInfra(model_id="google/flan-t5-xl", deepinfra_api_token="my-api-key") """ diff --git a/langchain/llms/forefrontai.py b/langchain/llms/forefrontai.py index f76003b6..806bcd85 100644 --- a/langchain/llms/forefrontai.py +++ b/langchain/llms/forefrontai.py @@ -18,7 +18,7 @@ class ForefrontAI(LLM, BaseModel): Example: .. code-block:: python - from langchain import ForefrontAI + from langchain.llms import ForefrontAI forefrontai = ForefrontAI(endpoint_url="") """ diff --git a/langchain/llms/gooseai.py b/langchain/llms/gooseai.py index 891d511f..89f17f18 100644 --- a/langchain/llms/gooseai.py +++ b/langchain/llms/gooseai.py @@ -21,7 +21,7 @@ class GooseAI(LLM, BaseModel): Example: .. code-block:: python - from langchain import GooseAI + from langchain.llms import GooseAI gooseai = GooseAI(model_name="gpt-neo-20b") """ diff --git a/langchain/llms/huggingface_hub.py b/langchain/llms/huggingface_hub.py index ef53275d..b9c40988 100644 --- a/langchain/llms/huggingface_hub.py +++ b/langchain/llms/huggingface_hub.py @@ -23,7 +23,7 @@ class HuggingFaceHub(LLM, BaseModel): Example: .. code-block:: python - from langchain import HuggingFaceHub + from langchain.llms import HuggingFaceHub hf = HuggingFaceHub(repo_id="gpt2", huggingfacehub_api_token="my-api-key") """ diff --git a/langchain/llms/huggingface_pipeline.py b/langchain/llms/huggingface_pipeline.py index ee5678c6..1138839c 100644 --- a/langchain/llms/huggingface_pipeline.py +++ b/langchain/llms/huggingface_pipeline.py @@ -25,14 +25,14 @@ class HuggingFacePipeline(LLM, BaseModel): Example using from_model_id: .. code-block:: python - from langchain.llms.huggingface_pipeline import HuggingFacePipeline + from langchain.llms import HuggingFacePipeline hf = HuggingFacePipeline.from_model_id( model_id="gpt2", task="text-generation" ) Example passing pipeline in directly: .. code-block:: python - from langchain.llms.huggingface_pipeline import HuggingFacePipeline + from langchain.llms import HuggingFacePipeline from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline model_id = "gpt2" diff --git a/langchain/llms/modal.py b/langchain/llms/modal.py index b1bd5132..5037858a 100644 --- a/langchain/llms/modal.py +++ b/langchain/llms/modal.py @@ -21,7 +21,7 @@ class Modal(LLM, BaseModel): Example: .. code-block:: python - from langchain import Modal + from langchain.llms import Modal modal = Modal(endpoint_url="") """ diff --git a/langchain/llms/nlpcloud.py b/langchain/llms/nlpcloud.py index 94f0df7d..2c04c419 100644 --- a/langchain/llms/nlpcloud.py +++ b/langchain/llms/nlpcloud.py @@ -16,7 +16,7 @@ class NLPCloud(LLM, BaseModel): Example: .. code-block:: python - from langchain import NLPCloud + from langchain.llms import NLPCloud nlpcloud = NLPCloud(model="gpt-neox-20b") """ diff --git a/langchain/llms/openai.py b/langchain/llms/openai.py index 4f2b37bd..728d5087 100644 --- a/langchain/llms/openai.py +++ b/langchain/llms/openai.py @@ -75,7 +75,7 @@ class BaseOpenAI(BaseLLM, BaseModel): Example: .. code-block:: python - from langchain import OpenAI + from langchain.llms import OpenAI openai = OpenAI(model_name="text-davinci-003") """ diff --git a/langchain/llms/petals.py b/langchain/llms/petals.py index 535d5d1b..bffe59ba 100644 --- a/langchain/llms/petals.py +++ b/langchain/llms/petals.py @@ -22,7 +22,7 @@ class Petals(LLM, BaseModel): Example: .. code-block:: python - from langchain import petals + from langchain.llms import petals petals = Petals() """ diff --git a/langchain/llms/promptlayer_openai.py b/langchain/llms/promptlayer_openai.py index 23cba853..2704218e 100644 --- a/langchain/llms/promptlayer_openai.py +++ b/langchain/llms/promptlayer_openai.py @@ -23,7 +23,7 @@ class PromptLayerOpenAI(OpenAI, BaseModel): Example: .. code-block:: python - from langchain import OpenAI + from langchain.llms import OpenAI openai = OpenAI(model_name="text-davinci-003") """ diff --git a/langchain/llms/stochasticai.py b/langchain/llms/stochasticai.py index 6f2d8b75..21c32b21 100644 --- a/langchain/llms/stochasticai.py +++ b/langchain/llms/stochasticai.py @@ -22,8 +22,8 @@ class StochasticAI(LLM, BaseModel): Example: .. code-block:: python - from langchain import StochasticAI - forefrontai = StochasticAI(api_url="") + from langchain.llms import StochasticAI + stochasticai = StochasticAI(api_url="") """ api_url: str = ""