docs: notebook linting (#14366)

Many jupyter notebooks didn't pass linting. List of these files are
presented in the [tool.ruff.lint.per-file-ignores] section of the
pyproject.toml . Addressed these bugs:
- fixed bugs; added missed imports; updated pyproject.toml
 Only the `document_loaders/tensorflow_datasets.ipyn`,
`cookbook/gymnasium_agent_simulation.ipynb` are not completely fixed.
I'm not sure about imports.

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
Leonid Ganeline 2023-12-07 15:47:48 -08:00 committed by GitHub
parent 52052cc7b9
commit 18aba7fdef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 244 additions and 142 deletions

View File

@ -31,7 +31,7 @@
"source": [
"import re\n",
"\n",
"from IPython.display import Image\n",
"from IPython.display import Image, display\n",
"from steamship import Block, Steamship"
]
},
@ -180,7 +180,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -37,7 +37,8 @@
"source": [
"#!pip install qianfan\n",
"#!pip install bce-python-sdk\n",
"#!pip install elasticsearch == 7.11.0"
"#!pip install elasticsearch == 7.11.0\n",
"#!pip install sentence-transformers"
]
},
{
@ -54,8 +55,10 @@
"metadata": {},
"outputs": [],
"source": [
"import sentence_transformers\n",
"from baidubce.auth.bce_credentials import BceCredentials\n",
"from baidubce.bce_client_configuration import BceClientConfiguration\n",
"from langchain.chains.retrieval_qa import RetrievalQA\n",
"from langchain.document_loaders.baiducloud_bos_directory import BaiduBOSDirectoryLoader\n",
"from langchain.embeddings.huggingface import HuggingFaceEmbeddings\n",
"from langchain.llms.baidu_qianfan_endpoint import QianfanLLMEndpoint\n",
@ -161,15 +164,22 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"version": "3.9.17"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
@ -177,5 +187,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

View File

@ -133,7 +133,7 @@
"from tqdm import tqdm\n",
"\n",
"for i in tqdm(range(len(title_embeddings))):\n",
" title = titles[i].replace(\"'\", \"''\")\n",
" title = song_titles[i].replace(\"'\", \"''\")\n",
" embedding = title_embeddings[i]\n",
" sql_command = (\n",
" f'UPDATE \"Track\" SET \"embeddings\" = ARRAY{embedding} WHERE \"Name\" ='\n",
@ -681,9 +681,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

View File

@ -187,7 +187,7 @@
" for key in path:\n",
" try:\n",
" current = current[key]\n",
" except:\n",
" except KeyError:\n",
" return None\n",
" return current\n",
"\n",

View File

@ -91,7 +91,7 @@
"with patch(\"openai.resources.chat.completions.Completions.create\", side_effect=error):\n",
" try:\n",
" print(openai_llm.invoke(\"Why did the chicken cross the road?\"))\n",
" except:\n",
" except RateLimitError:\n",
" print(\"Hit error\")"
]
},
@ -114,7 +114,7 @@
"with patch(\"openai.resources.chat.completions.Completions.create\", side_effect=error):\n",
" try:\n",
" print(llm.invoke(\"Why did the chicken cross the road?\"))\n",
" except:\n",
" except RateLimitError:\n",
" print(\"Hit error\")"
]
},
@ -156,7 +156,7 @@
"with patch(\"openai.resources.chat.completions.Completions.create\", side_effect=error):\n",
" try:\n",
" print(chain.invoke({\"animal\": \"kangaroo\"}))\n",
" except:\n",
" except RateLimitError:\n",
" print(\"Hit error\")"
]
},
@ -190,10 +190,10 @@
")\n",
"\n",
"chain = prompt | llm\n",
"with patch(\"openai.ChatCompletion.create\", side_effect=error):\n",
"with patch(\"openai.resources.chat.completions.Completions.create\", side_effect=error):\n",
" try:\n",
" print(chain.invoke({\"animal\": \"kangaroo\"}))\n",
" except:\n",
" except RateLimitError:\n",
" print(\"Hit error\")"
]
},
@ -291,7 +291,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -93,7 +93,7 @@
"with patch(\"openai.resources.chat.completions.Completions.create\", side_effect=error):\n",
" try:\n",
" print(openai_llm.invoke(\"Why did the chicken cross the road?\"))\n",
" except:\n",
" except RateLimitError:\n",
" print(\"Hit error\")"
]
},
@ -116,7 +116,7 @@
"with patch(\"openai.resources.chat.completions.Completions.create\", side_effect=error):\n",
" try:\n",
" print(llm.invoke(\"Why did the chicken cross the road?\"))\n",
" except:\n",
" except RateLimitError:\n",
" print(\"Hit error\")"
]
},
@ -158,7 +158,7 @@
"with patch(\"openai.resources.chat.completions.Completions.create\", side_effect=error):\n",
" try:\n",
" print(chain.invoke({\"animal\": \"kangaroo\"}))\n",
" except:\n",
" except RateLimitError:\n",
" print(\"Hit error\")"
]
},

View File

@ -45,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@ -55,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [
{
@ -64,7 +64,7 @@
"AIMessage(content=\" J'aime la programmation.\")"
]
},
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
@ -89,7 +89,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
@ -98,7 +98,7 @@
"AIMessage(content=' プログラミングが大好きです')"
]
},
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
@ -142,7 +142,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {
"tags": []
},
@ -198,7 +198,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@ -212,7 +212,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [
{
@ -221,12 +221,17 @@
"AIMessage(content=' Why do you love programming?')"
]
},
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system = (\n",
" \"You are a helpful assistant that translates {input_language} to {output_language}.\"\n",
")\n",
"human = \"{text}\"\n",
"prompt = ChatPromptTemplate.from_messages([(\"system\", system), (\"human\", human)])\n",
"chain = prompt | chat\n",
"\n",
"asyncio.run(\n",
@ -251,7 +256,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [
{

View File

@ -129,12 +129,6 @@
"**The above request should now appear on your [PromptLayer dashboard](https://www.promptlayer.com).**"
]
},
{
"cell_type": "markdown",
"id": "05e9e2fe",
"metadata": {},
"source": []
},
{
"attachments": {},
"cell_type": "markdown",
@ -152,6 +146,8 @@
"metadata": {},
"outputs": [],
"source": [
"import promptlayer\n",
"\n",
"chat = PromptLayerChatOpenAI(return_pl_id=True)\n",
"chat_results = chat.generate([[HumanMessage(content=\"I am a cat and I want\")]])\n",
"\n",
@ -172,7 +168,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "base",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@ -186,7 +182,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8 (default, Apr 13 2021, 12:59:45) \n[Clang 10.0.0 ]"
"version": "3.10.12"
},
"vscode": {
"interpreter": {

View File

@ -153,7 +153,7 @@
"source": [
"# Now all of the Tortoise's messages will take the AI message class\n",
"# which maps to the 'assistant' role in OpenAI's training format\n",
"alternating_sessions[0][\"messages\"][:3]"
"chat_sessions[0][\"messages\"][:3]"
]
},
{
@ -191,7 +191,7 @@
}
],
"source": [
"training_data = convert_messages_for_finetuning(alternating_sessions)\n",
"training_data = convert_messages_for_finetuning(chat_sessions)\n",
"print(f\"Prepared {len(training_data)} dialogues for training\")"
]
},
@ -416,7 +416,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -23,8 +23,18 @@
"source": [
"from langchain.document_loaders import ArcGISLoader\n",
"\n",
"url = \"https://maps1.vcgov.org/arcgis/rest/services/Beaches/MapServer/7\"\n",
"loader = ArcGISLoader(url)"
"URL = \"https://maps1.vcgov.org/arcgis/rest/services/Beaches/MapServer/7\"\n",
"loader = ArcGISLoader(URL)\n",
"\n",
"docs = loader.load()"
]
},
{
"cell_type": "markdown",
"id": "1e174ebd-bbbd-4a66-a644-51e0df12982d",
"metadata": {},
"source": [
"Let's measure loader latency."
]
},
{
@ -261,7 +271,7 @@
"metadata": {},
"outputs": [],
"source": [
"loader_geom = ArcGISLoader(url, return_geometry=True)"
"loader_geom = ArcGISLoader(URL, return_geometry=True)"
]
},
{

View File

@ -30,6 +30,16 @@
"#!pip install datadog-api-client"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"DD_API_KEY = \"...\"\n",
"DD_APP_KEY = \"...\""
]
},
{
"cell_type": "code",
"execution_count": null,
@ -73,7 +83,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@ -87,10 +97,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.11"
},
"orig_nbformat": 4
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

View File

@ -65,6 +65,16 @@
"%pip install langchain -q"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ab73cc1-d8e0-4b6d-bb03-9522b112fce5",
"metadata": {},
"outputs": [],
"source": [
"etherscanAPIKey = \"...\""
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -74,7 +74,9 @@
"source": [
"# see https://python.langchain.com/docs/use_cases/summarization for more details\n",
"from langchain.chains.summarize import load_summarize_chain\n",
"from langchain.llms.fake import FakeListLLM\n",
"\n",
"llm = FakeListLLM()\n",
"chain = load_summarize_chain(llm, chain_type=\"map_reduce\")\n",
"chain.run(docs)"
]
@ -96,7 +98,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -166,6 +166,9 @@
}
],
"source": [
"from langchain_core.documents import Document\n",
"\n",
"\n",
"def decode_to_str(item: tf.Tensor) -> str:\n",
" return item.numpy().decode(\"utf-8\")\n",
"\n",

View File

@ -12,6 +12,18 @@
"This example goes over how to use LangChain to interact with [Anyscale Endpoint](https://app.endpoints.anyscale.com/). "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "515070aa-e241-480e-8d9a-afdf52f35322",
"metadata": {},
"outputs": [],
"source": [
"ANYSCALE_API_BASE = \"...\"\n",
"ANYSCALE_API_KEY = \"...\"\n",
"ANYSCALE_MODEL_NAME = \"...\""
]
},
{
"cell_type": "code",
"execution_count": null,
@ -160,7 +172,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
"version": "3.10.12"
},
"vscode": {
"interpreter": {

View File

@ -112,6 +112,24 @@
"## Using NIBittensorLLM with Conversational Agent and Google Search Tool"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from langchain.tools import Tool\n",
"from langchain.utilities import GoogleSearchAPIWrapper\n",
"\n",
"search = GoogleSearchAPIWrapper()\n",
"\n",
"tool = Tool(\n",
" name=\"Google Search\",\n",
" description=\"Search Google for recent results.\",\n",
" func=search.run,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
@ -129,7 +147,7 @@
"\n",
"memory = ConversationBufferMemory(memory_key=\"chat_history\")\n",
"\n",
"\n",
"tools = [tool]\n",
"prefix = \"\"\"Answer prompt based on LLM if there is need to search something then use internet and observe internet result and give accurate reply of user questions also try to use authenticated sources\"\"\"\n",
"suffix = \"\"\"Begin!\n",
" {chat_history}\n",
@ -137,14 +155,14 @@
" {agent_scratchpad}\"\"\"\n",
"\n",
"prompt = ZeroShotAgent.create_prompt(\n",
" tools,\n",
" tools=tools,\n",
" prefix=prefix,\n",
" suffix=suffix,\n",
" input_variables=[\"input\", \"chat_history\", \"agent_scratchpad\"],\n",
")\n",
"\n",
"llm = NIBittensorLLM(\n",
" system_prompt=\"Your task is to determine response based on user prompt\"\n",
" system_prompt=\"Your task is to determine a response based on user prompt\"\n",
")\n",
"\n",
"llm_chain = LLMChain(llm=llm, prompt=prompt)\n",
@ -176,7 +194,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.1"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -33,7 +33,13 @@
"\n",
"```\n",
"pip install mlflow>=2.9\n",
"```"
"```\n",
"\n",
"Also, we need `dbutils` for this example.\n",
"\n",
"```\n",
"pip install dbutils\n",
"```\n"
]
},
{
@ -269,6 +275,8 @@
"\n",
"import os\n",
"\n",
"import dbutils\n",
"\n",
"os.environ[\"DATABRICKS_TOKEN\"] = dbutils.secrets.get(\"myworkspace\", \"api_token\")\n",
"\n",
"llm = Databricks(host=\"myworkspace.cloud.databricks.com\", endpoint_name=\"dolly\")\n",
@ -606,7 +614,7 @@
"widgets": {}
},
"kernelspec": {
"display_name": "llm",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@ -620,10 +628,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
},
"orig_nbformat": 4
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 4
}

View File

@ -28,7 +28,6 @@
"cell_type": "markdown",
"id": "b50f0598",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
@ -113,7 +112,6 @@
"cell_type": "markdown",
"id": "4bf59c12",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
@ -231,6 +229,7 @@
"metadata": {},
"outputs": [],
"source": [
"import langchain\n",
"from langchain.cache import UpstashRedisCache\n",
"from upstash_redis import Redis\n",
"\n",
@ -1589,7 +1588,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.1"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -289,7 +289,7 @@
"source": [
"pipeline = load_pipeline()\n",
"llm = SelfHostedPipeline.from_pipeline(\n",
" pipeline=pipeline, hardware=gpu, model_reqs=model_reqs\n",
" pipeline=pipeline, hardware=gpu, model_reqs=[\"pip:./\", \"transformers\", \"torch\"]\n",
")"
]
},
@ -308,6 +308,8 @@
"metadata": {},
"outputs": [],
"source": [
"import pickle\n",
"\n",
"rh.blob(pickle.dumps(pipeline), path=\"models/pipeline.pkl\").save().to(\n",
" gpu, path=\"models\"\n",
")\n",
@ -332,7 +334,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -54,6 +54,15 @@
"Also you'll need to create a [Activeloop]((https://activeloop.ai/)) account."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ORG_ID = \"...\""
]
},
{
"cell_type": "code",
"execution_count": null,

View File

@ -160,6 +160,8 @@
"outputs": [],
"source": [
"# Create Elasticsearch connection\n",
"from elasticsearch import Elasticsearch\n",
"\n",
"es_connection = Elasticsearch(\n",
" hosts=[\"https://es_cluster_url:port\"], basic_auth=(\"user\", \"password\")\n",
")"
@ -259,9 +261,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
}

View File

@ -20,6 +20,8 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"# Set API key\n",
"embaas_api_key = \"YOUR_API_KEY\"\n",
"# or set environment variable\n",
@ -139,9 +141,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}

View File

@ -131,6 +131,8 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"# if you are behind an explicit proxy, you can use the OPENAI_PROXY environment variable to pass through\n",
"os.environ[\"OPENAI_PROXY\"] = \"http://proxy.yourcompany.com:8080\""
]
@ -138,7 +140,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.11.1 64-bit",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@ -152,7 +154,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
"version": "3.10.12"
},
"vscode": {
"interpreter": {

View File

@ -225,6 +225,8 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"# if you are behind an explicit proxy, you can use the OPENAI_PROXY environment variable to pass through\n",
"os.environ[\"OPENAI_PROXY\"] = \"http://proxy.yourcompany.com:8080\""
]
@ -246,7 +248,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
"version": "3.10.12"
},
"vscode": {
"interpreter": {

View File

@ -101,8 +101,10 @@
"# Or you can try the options below to display the image inline in this notebook\n",
"\n",
"try:\n",
" import google.colab\n",
"\n",
" IN_COLAB = True\n",
"except:\n",
"except ImportError:\n",
" IN_COLAB = False\n",
"\n",
"if IN_COLAB:\n",

View File

@ -187,7 +187,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
"version": "3.10.12"
},
"vscode": {
"interpreter": {

View File

@ -104,6 +104,8 @@
},
"outputs": [],
"source": [
"from IPython.display import display\n",
"\n",
"display(im)"
]
},
@ -232,7 +234,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -145,6 +145,8 @@
"metadata": {},
"outputs": [],
"source": [
"import awadb\n",
"\n",
"awadb_client = awadb.Client()\n",
"ret = awadb_client.Load(\"langchain_awadb\")\n",
"if ret:\n",
@ -178,7 +180,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -78,6 +78,7 @@
"outputs": [],
"source": [
"from langchain.document_loaders import TextLoader\n",
"from langchain.text_splitter import CharacterTextSplitter\n",
"\n",
"loader = TextLoader(\"../../../state_of_the_union.txt\")\n",
"documents = loader.load()\n",
@ -145,15 +146,22 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"version": "3.9.17"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
@ -161,5 +169,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

View File

@ -52,6 +52,9 @@
"metadata": {},
"outputs": [],
"source": [
"import getpass\n",
"import os\n",
"\n",
"os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"OpenAI API Key:\")"
]
},

View File

@ -99,7 +99,7 @@
"outputs": [],
"source": [
"results = ndb.similarity_search(\"Who was inspired by Ada Lovelace?\")\n",
"print(res.page_content)"
"print(results[0].page_content)"
]
}
],
@ -119,7 +119,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -344,7 +344,7 @@
"metadata": {},
"outputs": [],
"source": [
"#!pip install requests requests-aws4auth"
"#!pip install boto3 requests requests-aws4auth"
]
},
{
@ -362,6 +362,8 @@
},
"outputs": [],
"source": [
"import boto3\n",
"from opensearchpy import RequestsHttpConnection\n",
"from requests_aws4auth import AWS4Auth\n",
"\n",
"service = \"aoss\" # must set the service as 'aoss'\n",
@ -404,6 +406,16 @@
"## Using AOS (Amazon OpenSearch Service)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4b02cd8d-f182-476b-935a-737f9c05d8e4",
"metadata": {},
"outputs": [],
"source": [
"#!pip install boto3"
]
},
{
"cell_type": "code",
"execution_count": null,
@ -419,7 +431,9 @@
},
"outputs": [],
"source": [
"# This is just an example to show how to use AOS , you need to set proper values.\n",
"# This is just an example to show how to use Amazon OpenSearch Service, you need to set proper values.\n",
"import boto3\n",
"from opensearchpy import RequestsHttpConnection\n",
"\n",
"service = \"es\" # must set the service as 'es'\n",
"region = \"us-east-2\"\n",

View File

@ -13,6 +13,16 @@
"We want it to be much more conversational."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7b9e9ef1-dc3c-4253-bd8b-5e95637bfe33",
"metadata": {},
"outputs": [],
"source": [
"OPENAI_API_KEY = \"...\""
]
},
{
"cell_type": "code",
"execution_count": 1,
@ -575,7 +585,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.1"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -27,6 +27,10 @@
}
],
"source": [
"from langchain.chains.llm import LLMChain\n",
"from langchain.chat_models.openai import ChatOpenAI\n",
"from langchain_core.prompts import PromptTemplate\n",
"\n",
"chat = ChatOpenAI(temperature=0)\n",
"prompt_template = \"Tell me a {adjective} joke\"\n",
"llm_chain = LLMChain(llm=chat, prompt=PromptTemplate.from_template(prompt_template))\n",
@ -174,7 +178,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.10.12"
},
"vscode": {
"interpreter": {

View File

@ -19,6 +19,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.embeddings import OpenAIEmbeddings\n",
"from langchain.retrievers import BM25Retriever, EnsembleRetriever\n",
"from langchain.vectorstores import FAISS"
]
@ -81,7 +82,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@ -95,10 +96,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
},
"orig_nbformat": 4
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

View File

@ -55,8 +55,8 @@
" TextLoader(\"../../state_of_the_union.txt\"),\n",
"]\n",
"docs = []\n",
"for l in loaders:\n",
" docs.extend(l.load())\n",
"for loader in loaders:\n",
" docs.extend(loader.load())\n",
"text_splitter = RecursiveCharacterTextSplitter(chunk_size=10000)\n",
"docs = text_splitter.split_documents(docs)"
]
@ -601,7 +601,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -61,8 +61,8 @@
" TextLoader(\"../../state_of_the_union.txt\"),\n",
"]\n",
"docs = []\n",
"for l in loaders:\n",
" docs.extend(l.load())"
"for loader in loaders:\n",
" docs.extend(loader.load())"
]
},
{
@ -432,7 +432,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.10.12"
}
},
"nbformat": 4,

View File

@ -74,48 +74,5 @@ extend-exclude = [
# These files were failing the listed rules at the time ruff was adopted for notebooks.
# Don't require them to change at once, though we should look into them eventually.
"cookbook/gymnasium_agent_simulation.ipynb" = ["F821"]
"cookbook/multi_modal_output_agent.ipynb" = ["F821"]
"cookbook/multi_modal_RAG_chroma.ipynb" = ["F821"]
"cookbook/qianfan_baidu_elasticesearch_RAG.ipynb" = ["F821"]
"cookbook/retrieval_in_sql.ipynb" = ["F821"]
"cookbook/wikibase_agent.ipynb" = ["E722"]
"docs/docs/expression_language/how_to/configure.ipynb" = ["F821"]
"docs/docs/expression_language/how_to/fallbacks.ipynb" = ["E722"]
"docs/docs/guides/fallbacks.ipynb" = ["E722"]
"docs/docs/integrations/chat_loaders/imessage.ipynb" = ["F821"]
"docs/docs/integrations/chat_loaders/langsmith_dataset.ipynb" = ["F821"]
"docs/docs/integrations/chat/google_vertex_ai_palm.ipynb" = ["F821"]
"docs/docs/integrations/chat/promptlayer_chatopenai.ipynb" = ["F821"]
"docs/docs/integrations/document_loaders/arcgis.ipynb" = ["F821"]
"docs/docs/integrations/document_loaders/datadog_logs.ipynb" = ["F821"]
"docs/docs/integrations/document_loaders/embaas.ipynb" = ["F821"]
"docs/docs/integrations/document_loaders/etherscan.ipynb" = ["F821"]
"docs/docs/integrations/document_loaders/larksuite.ipynb" = ["F821"]
"docs/docs/integrations/document_loaders/tensorflow_datasets.ipynb" = ["F821"]
"docs/docs/integrations/llms/anyscale.ipynb" = ["F821"]
"docs/docs/integrations/llms/bittensor.ipynb" = ["F821"]
"docs/docs/integrations/llms/databricks.ipynb" = ["F821"]
"docs/docs/integrations/llms/llm_caching.ipynb" = ["F821"]
"docs/docs/integrations/llms/runhouse.ipynb" = ["F821"]
"docs/docs/integrations/retrievers/Activeloop DeepMemory+LangChain.ipynb" = ["F821"]
"docs/docs/integrations/text_embedding/cohere.ipynb" = ["F821"]
"docs/docs/integrations/text_embedding/elasticsearch.ipynb" = ["F821"]
"docs/docs/integrations/text_embedding/embaas.ipynb" = ["F821"]
"docs/docs/integrations/text_embedding/jina.ipynb" = ["F821"]
"docs/docs/integrations/text_embedding/localai.ipynb" = ["F821"]
"docs/docs/integrations/text_embedding/openai.ipynb" = ["F821"]
"docs/docs/integrations/tools/dalle_image_generator.ipynb" = ["E722"]
"docs/docs/integrations/tools/gradio_tools.ipynb" = ["F821"]
"docs/docs/integrations/vectorstores/async_faiss.ipynb" = ["F821"]
"docs/docs/integrations/vectorstores/awadb.ipynb" = ["F821"]
"docs/docs/integrations/vectorstores/baiducloud_vector_search.ipynb" = ["F821"]
"docs/docs/integrations/vectorstores/faiss.ipynb" = ["F821"]
"docs/docs/integrations/vectorstores/mongodb_atlas.ipynb" = ["F821"]
"docs/docs/integrations/vectorstores/nucliadb.ipynb" = ["F821"]
"docs/docs/integrations/vectorstores/opensearch.ipynb" = ["F821"]
"docs/docs/modules/agents/agent_types/chat_conversation_agent.ipynb" = ["F821"]
"docs/docs/modules/chains/how_to/call_methods.ipynb" = ["F821"]
"docs/docs/modules/data_connection/retrievers/ensemble.ipynb" = ["F821"]
"docs/docs/modules/data_connection/retrievers/multi_vector.ipynb" = ["E741"]
"docs/docs/modules/data_connection/retrievers/parent_document_retriever.ipynb" = ["E741"]
"docs/docs/modules/data_connection/text_embedding/caching_embeddings.ipynb" = ["F821"]