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": [ "cells": [
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
@ -12,7 +11,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -21,15 +20,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
@ -45,17 +43,35 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"metadata": {}, "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": [ "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": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python 3 (ipykernel)",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -69,9 +85,8 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.11.1" "version": "3.9.1"
}, },
"orig_nbformat": 4,
"vscode": { "vscode": {
"interpreter": { "interpreter": {
"hash": "981b6680a42bdb5eb22187741e1607b3aae2cf73db800d1af1f268d1de6a1f70" "hash": "981b6680a42bdb5eb22187741e1607b3aae2cf73db800d1af1f268d1de6a1f70"

@ -61,16 +61,23 @@ def remove_newlines(x: Any) -> Any:
class NotebookLoader(BaseLoader): class NotebookLoader(BaseLoader):
"""Loader that loads .ipynb notebook files.""" """Loader that loads .ipynb notebook files."""
def __init__(self, path: str): def __init__(
"""Initialize with path."""
self.file_path = path
def load(
self, self,
path: str,
include_outputs: bool = False, include_outputs: bool = False,
max_output_length: int = 10, max_output_length: int = 10,
remove_newline: bool = False, remove_newline: bool = False,
traceback: 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]: ) -> List[Document]:
"""Load documents.""" """Load documents."""
try: try:
@ -87,12 +94,12 @@ class NotebookLoader(BaseLoader):
data = pd.json_normalize(d["cells"]) data = pd.json_normalize(d["cells"])
filtered_data = data[["cell_type", "source", "outputs"]] filtered_data = data[["cell_type", "source", "outputs"]]
if remove_newline: if self.remove_newline:
filtered_data = filtered_data.applymap(remove_newlines) filtered_data = filtered_data.applymap(remove_newlines)
text = filtered_data.apply( text = filtered_data.apply(
lambda x: concatenate_cells( lambda x: concatenate_cells(
x, include_outputs, max_output_length, traceback x, self.include_outputs, self.max_output_length, self.traceback
), ),
axis=1, axis=1,
).str.cat(sep=" ") ).str.cat(sep=" ")

@ -18,7 +18,7 @@ class Anthropic(LLM, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
import anthropic import anthropic
from langchain import Anthropic from langchain.llms import Anthropic
model = Anthropic(model="<model_name>", anthropic_api_key="my-api-key") model = Anthropic(model="<model_name>", anthropic_api_key="my-api-key")
# Simplest invocation, automatically wrapped with HUMAN_PROMPT # Simplest invocation, automatically wrapped with HUMAN_PROMPT

@ -22,8 +22,8 @@ class Banana(LLM, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
from langchain import Banana from langchain.llms import Banana
cerebrium = Banana(model_key="") banana = Banana(model_key="")
""" """
model_key: str = "" model_key: str = ""

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

@ -21,7 +21,7 @@ class Cohere(LLM, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
from langchain import Cohere from langchain.llms import Cohere
cohere = Cohere(model="gptd-instruct-tft", cohere_api_key="my-api-key") cohere = Cohere(model="gptd-instruct-tft", cohere_api_key="my-api-key")
""" """

@ -23,7 +23,7 @@ class DeepInfra(LLM, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
from langchain import DeepInfra from langchain.llms import DeepInfra
di = DeepInfra(model_id="google/flan-t5-xl", di = DeepInfra(model_id="google/flan-t5-xl",
deepinfra_api_token="my-api-key") deepinfra_api_token="my-api-key")
""" """

@ -18,7 +18,7 @@ class ForefrontAI(LLM, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
from langchain import ForefrontAI from langchain.llms import ForefrontAI
forefrontai = ForefrontAI(endpoint_url="") forefrontai = ForefrontAI(endpoint_url="")
""" """

@ -21,7 +21,7 @@ class GooseAI(LLM, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
from langchain import GooseAI from langchain.llms import GooseAI
gooseai = GooseAI(model_name="gpt-neo-20b") gooseai = GooseAI(model_name="gpt-neo-20b")
""" """

@ -23,7 +23,7 @@ class HuggingFaceHub(LLM, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
from langchain import HuggingFaceHub from langchain.llms import HuggingFaceHub
hf = HuggingFaceHub(repo_id="gpt2", huggingfacehub_api_token="my-api-key") hf = HuggingFaceHub(repo_id="gpt2", huggingfacehub_api_token="my-api-key")
""" """

@ -25,14 +25,14 @@ class HuggingFacePipeline(LLM, BaseModel):
Example using from_model_id: Example using from_model_id:
.. code-block:: python .. code-block:: python
from langchain.llms.huggingface_pipeline import HuggingFacePipeline from langchain.llms import HuggingFacePipeline
hf = HuggingFacePipeline.from_model_id( hf = HuggingFacePipeline.from_model_id(
model_id="gpt2", task="text-generation" model_id="gpt2", task="text-generation"
) )
Example passing pipeline in directly: Example passing pipeline in directly:
.. code-block:: python .. code-block:: python
from langchain.llms.huggingface_pipeline import HuggingFacePipeline from langchain.llms import HuggingFacePipeline
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
model_id = "gpt2" model_id = "gpt2"

@ -21,7 +21,7 @@ class Modal(LLM, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
from langchain import Modal from langchain.llms import Modal
modal = Modal(endpoint_url="") modal = Modal(endpoint_url="")
""" """

@ -16,7 +16,7 @@ class NLPCloud(LLM, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
from langchain import NLPCloud from langchain.llms import NLPCloud
nlpcloud = NLPCloud(model="gpt-neox-20b") nlpcloud = NLPCloud(model="gpt-neox-20b")
""" """

@ -75,7 +75,7 @@ class BaseOpenAI(BaseLLM, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
from langchain import OpenAI from langchain.llms import OpenAI
openai = OpenAI(model_name="text-davinci-003") openai = OpenAI(model_name="text-davinci-003")
""" """

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

@ -23,7 +23,7 @@ class PromptLayerOpenAI(OpenAI, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
from langchain import OpenAI from langchain.llms import OpenAI
openai = OpenAI(model_name="text-davinci-003") openai = OpenAI(model_name="text-davinci-003")
""" """

@ -22,8 +22,8 @@ class StochasticAI(LLM, BaseModel):
Example: Example:
.. code-block:: python .. code-block:: python
from langchain import StochasticAI from langchain.llms import StochasticAI
forefrontai = StochasticAI(api_url="") stochasticai = StochasticAI(api_url="")
""" """
api_url: str = "" api_url: str = ""

Loading…
Cancel
Save