docker-utility-pexpect
Harrison Chase 1 year ago committed by GitHub
parent 7e8f832cd6
commit 96db6ed073
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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"

@ -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=" ")

@ -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="<model_name>", anthropic_api_key="my-api-key")
# Simplest invocation, automatically wrapped with HUMAN_PROMPT

@ -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 = ""

@ -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="")
"""

@ -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")
"""

@ -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")
"""

@ -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="")
"""

@ -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")
"""

@ -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")
"""

@ -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"

@ -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="")
"""

@ -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")
"""

@ -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")
"""

@ -22,7 +22,7 @@ class Petals(LLM, BaseModel):
Example:
.. code-block:: python
from langchain import petals
from langchain.llms import petals
petals = Petals()
"""

@ -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")
"""

@ -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 = ""

Loading…
Cancel
Save