diff --git a/cookbook/multi_modal_output_agent.ipynb b/cookbook/multi_modal_output_agent.ipynb index 22c8f8750..71f39e31a 100644 --- a/cookbook/multi_modal_output_agent.ipynb +++ b/cookbook/multi_modal_output_agent.ipynb @@ -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, diff --git a/cookbook/qianfan_baidu_elasticesearch_RAG.ipynb b/cookbook/qianfan_baidu_elasticesearch_RAG.ipynb index 2efea3d1d..f0d1822b1 100644 --- a/cookbook/qianfan_baidu_elasticesearch_RAG.ipynb +++ b/cookbook/qianfan_baidu_elasticesearch_RAG.ipynb @@ -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 } diff --git a/cookbook/retrieval_in_sql.ipynb b/cookbook/retrieval_in_sql.ipynb index adf43b4cb..cd3209950 100644 --- a/cookbook/retrieval_in_sql.ipynb +++ b/cookbook/retrieval_in_sql.ipynb @@ -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 } diff --git a/cookbook/wikibase_agent.ipynb b/cookbook/wikibase_agent.ipynb index e5f2110aa..b44df0c1b 100644 --- a/cookbook/wikibase_agent.ipynb +++ b/cookbook/wikibase_agent.ipynb @@ -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", diff --git a/docs/docs/expression_language/how_to/fallbacks.ipynb b/docs/docs/expression_language/how_to/fallbacks.ipynb index d7a47a439..575d13fbd 100644 --- a/docs/docs/expression_language/how_to/fallbacks.ipynb +++ b/docs/docs/expression_language/how_to/fallbacks.ipynb @@ -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, diff --git a/docs/docs/guides/fallbacks.ipynb b/docs/docs/guides/fallbacks.ipynb index 93666dd7a..11107e4ff 100644 --- a/docs/docs/guides/fallbacks.ipynb +++ b/docs/docs/guides/fallbacks.ipynb @@ -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\")" ] }, diff --git a/docs/docs/integrations/chat/google_vertex_ai_palm.ipynb b/docs/docs/integrations/chat/google_vertex_ai_palm.ipynb index 0858988f0..b22691b5b 100644 --- a/docs/docs/integrations/chat/google_vertex_ai_palm.ipynb +++ b/docs/docs/integrations/chat/google_vertex_ai_palm.ipynb @@ -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": [ { diff --git a/docs/docs/integrations/chat/promptlayer_chatopenai.ipynb b/docs/docs/integrations/chat/promptlayer_chatopenai.ipynb index 623bfbe1a..2b53e329e 100644 --- a/docs/docs/integrations/chat/promptlayer_chatopenai.ipynb +++ b/docs/docs/integrations/chat/promptlayer_chatopenai.ipynb @@ -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": { diff --git a/docs/docs/integrations/chat_loaders/imessage.ipynb b/docs/docs/integrations/chat_loaders/imessage.ipynb index 3e6e3a941..eb6a0edb3 100644 --- a/docs/docs/integrations/chat_loaders/imessage.ipynb +++ b/docs/docs/integrations/chat_loaders/imessage.ipynb @@ -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, diff --git a/docs/docs/integrations/document_loaders/arcgis.ipynb b/docs/docs/integrations/document_loaders/arcgis.ipynb index 1ebf5f4b7..d9fe93802 100644 --- a/docs/docs/integrations/document_loaders/arcgis.ipynb +++ b/docs/docs/integrations/document_loaders/arcgis.ipynb @@ -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)" ] }, { diff --git a/docs/docs/integrations/document_loaders/datadog_logs.ipynb b/docs/docs/integrations/document_loaders/datadog_logs.ipynb index ed80b15b8..7fb3e4ec3 100644 --- a/docs/docs/integrations/document_loaders/datadog_logs.ipynb +++ b/docs/docs/integrations/document_loaders/datadog_logs.ipynb @@ -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 } diff --git a/docs/docs/integrations/document_loaders/etherscan.ipynb b/docs/docs/integrations/document_loaders/etherscan.ipynb index 45e9fe3c0..187b33350 100644 --- a/docs/docs/integrations/document_loaders/etherscan.ipynb +++ b/docs/docs/integrations/document_loaders/etherscan.ipynb @@ -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, diff --git a/docs/docs/integrations/document_loaders/larksuite.ipynb b/docs/docs/integrations/document_loaders/larksuite.ipynb index 2877050aa..363d0540f 100644 --- a/docs/docs/integrations/document_loaders/larksuite.ipynb +++ b/docs/docs/integrations/document_loaders/larksuite.ipynb @@ -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, diff --git a/docs/docs/integrations/document_loaders/tensorflow_datasets.ipynb b/docs/docs/integrations/document_loaders/tensorflow_datasets.ipynb index 9cf6d3934..7c145a68e 100644 --- a/docs/docs/integrations/document_loaders/tensorflow_datasets.ipynb +++ b/docs/docs/integrations/document_loaders/tensorflow_datasets.ipynb @@ -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", diff --git a/docs/docs/integrations/llms/anyscale.ipynb b/docs/docs/integrations/llms/anyscale.ipynb index a610cb548..d18434a0c 100644 --- a/docs/docs/integrations/llms/anyscale.ipynb +++ b/docs/docs/integrations/llms/anyscale.ipynb @@ -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": { diff --git a/docs/docs/integrations/llms/bittensor.ipynb b/docs/docs/integrations/llms/bittensor.ipynb index 509768676..d00b4a998 100644 --- a/docs/docs/integrations/llms/bittensor.ipynb +++ b/docs/docs/integrations/llms/bittensor.ipynb @@ -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, diff --git a/docs/docs/integrations/llms/databricks.ipynb b/docs/docs/integrations/llms/databricks.ipynb index 1033a1e71..4e4a5fd18 100644 --- a/docs/docs/integrations/llms/databricks.ipynb +++ b/docs/docs/integrations/llms/databricks.ipynb @@ -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 } diff --git a/docs/docs/integrations/llms/llm_caching.ipynb b/docs/docs/integrations/llms/llm_caching.ipynb index bcff9775a..53272bacc 100644 --- a/docs/docs/integrations/llms/llm_caching.ipynb +++ b/docs/docs/integrations/llms/llm_caching.ipynb @@ -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, diff --git a/docs/docs/integrations/llms/runhouse.ipynb b/docs/docs/integrations/llms/runhouse.ipynb index c56912061..a536214ff 100644 --- a/docs/docs/integrations/llms/runhouse.ipynb +++ b/docs/docs/integrations/llms/runhouse.ipynb @@ -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, diff --git a/docs/docs/integrations/retrievers/Activeloop DeepMemory+LangChain.ipynb b/docs/docs/integrations/retrievers/Activeloop DeepMemory+LangChain.ipynb index b088fc89c..367491ee1 100644 --- a/docs/docs/integrations/retrievers/Activeloop DeepMemory+LangChain.ipynb +++ b/docs/docs/integrations/retrievers/Activeloop DeepMemory+LangChain.ipynb @@ -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, diff --git a/docs/docs/integrations/text_embedding/elasticsearch.ipynb b/docs/docs/integrations/text_embedding/elasticsearch.ipynb index 97922eff7..e7e376249 100644 --- a/docs/docs/integrations/text_embedding/elasticsearch.ipynb +++ b/docs/docs/integrations/text_embedding/elasticsearch.ipynb @@ -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 -} \ No newline at end of file +} diff --git a/docs/docs/integrations/text_embedding/embaas.ipynb b/docs/docs/integrations/text_embedding/embaas.ipynb index 9fff92d3a..85abc083f 100644 --- a/docs/docs/integrations/text_embedding/embaas.ipynb +++ b/docs/docs/integrations/text_embedding/embaas.ipynb @@ -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 } diff --git a/docs/docs/integrations/text_embedding/localai.ipynb b/docs/docs/integrations/text_embedding/localai.ipynb index e14e4ef56..97def1fee 100644 --- a/docs/docs/integrations/text_embedding/localai.ipynb +++ b/docs/docs/integrations/text_embedding/localai.ipynb @@ -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": { diff --git a/docs/docs/integrations/text_embedding/openai.ipynb b/docs/docs/integrations/text_embedding/openai.ipynb index 7dbf174ce..d25005c30 100644 --- a/docs/docs/integrations/text_embedding/openai.ipynb +++ b/docs/docs/integrations/text_embedding/openai.ipynb @@ -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": { diff --git a/docs/docs/integrations/tools/dalle_image_generator.ipynb b/docs/docs/integrations/tools/dalle_image_generator.ipynb index c5c0db01b..adbb8c277 100644 --- a/docs/docs/integrations/tools/dalle_image_generator.ipynb +++ b/docs/docs/integrations/tools/dalle_image_generator.ipynb @@ -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", diff --git a/docs/docs/integrations/tools/google_search.ipynb b/docs/docs/integrations/tools/google_search.ipynb index 4d4f6af27..e94f7036b 100644 --- a/docs/docs/integrations/tools/google_search.ipynb +++ b/docs/docs/integrations/tools/google_search.ipynb @@ -187,7 +187,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.1" + "version": "3.10.12" }, "vscode": { "interpreter": { diff --git a/docs/docs/integrations/tools/gradio_tools.ipynb b/docs/docs/integrations/tools/gradio_tools.ipynb index 8201086b1..6337825c0 100644 --- a/docs/docs/integrations/tools/gradio_tools.ipynb +++ b/docs/docs/integrations/tools/gradio_tools.ipynb @@ -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, diff --git a/docs/docs/integrations/vectorstores/awadb.ipynb b/docs/docs/integrations/vectorstores/awadb.ipynb index 81dfd05c8..6a3030843 100644 --- a/docs/docs/integrations/vectorstores/awadb.ipynb +++ b/docs/docs/integrations/vectorstores/awadb.ipynb @@ -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, diff --git a/docs/docs/integrations/vectorstores/baiducloud_vector_search.ipynb b/docs/docs/integrations/vectorstores/baiducloud_vector_search.ipynb index 3bdda14ce..5785907ae 100644 --- a/docs/docs/integrations/vectorstores/baiducloud_vector_search.ipynb +++ b/docs/docs/integrations/vectorstores/baiducloud_vector_search.ipynb @@ -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 } diff --git a/docs/docs/integrations/vectorstores/mongodb_atlas.ipynb b/docs/docs/integrations/vectorstores/mongodb_atlas.ipynb index d656e336a..1e5ac484e 100644 --- a/docs/docs/integrations/vectorstores/mongodb_atlas.ipynb +++ b/docs/docs/integrations/vectorstores/mongodb_atlas.ipynb @@ -52,6 +52,9 @@ "metadata": {}, "outputs": [], "source": [ + "import getpass\n", + "import os\n", + "\n", "os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"OpenAI API Key:\")" ] }, diff --git a/docs/docs/integrations/vectorstores/nucliadb.ipynb b/docs/docs/integrations/vectorstores/nucliadb.ipynb index 913db5a79..3ba5ef0b6 100644 --- a/docs/docs/integrations/vectorstores/nucliadb.ipynb +++ b/docs/docs/integrations/vectorstores/nucliadb.ipynb @@ -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, diff --git a/docs/docs/integrations/vectorstores/opensearch.ipynb b/docs/docs/integrations/vectorstores/opensearch.ipynb index 945bc75e7..51852f237 100644 --- a/docs/docs/integrations/vectorstores/opensearch.ipynb +++ b/docs/docs/integrations/vectorstores/opensearch.ipynb @@ -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", diff --git a/docs/docs/modules/agents/agent_types/chat_conversation_agent.ipynb b/docs/docs/modules/agents/agent_types/chat_conversation_agent.ipynb index 2ed15e825..9db66672d 100644 --- a/docs/docs/modules/agents/agent_types/chat_conversation_agent.ipynb +++ b/docs/docs/modules/agents/agent_types/chat_conversation_agent.ipynb @@ -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, diff --git a/docs/docs/modules/chains/how_to/call_methods.ipynb b/docs/docs/modules/chains/how_to/call_methods.ipynb index 4f51ff179..1c68de43c 100644 --- a/docs/docs/modules/chains/how_to/call_methods.ipynb +++ b/docs/docs/modules/chains/how_to/call_methods.ipynb @@ -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": { diff --git a/docs/docs/modules/data_connection/retrievers/ensemble.ipynb b/docs/docs/modules/data_connection/retrievers/ensemble.ipynb index f17250709..be3fdd4ba 100644 --- a/docs/docs/modules/data_connection/retrievers/ensemble.ipynb +++ b/docs/docs/modules/data_connection/retrievers/ensemble.ipynb @@ -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 } diff --git a/docs/docs/modules/data_connection/retrievers/multi_vector.ipynb b/docs/docs/modules/data_connection/retrievers/multi_vector.ipynb index 912998b3f..ca451cefc 100644 --- a/docs/docs/modules/data_connection/retrievers/multi_vector.ipynb +++ b/docs/docs/modules/data_connection/retrievers/multi_vector.ipynb @@ -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, diff --git a/docs/docs/modules/data_connection/retrievers/parent_document_retriever.ipynb b/docs/docs/modules/data_connection/retrievers/parent_document_retriever.ipynb index 793037145..fede507bf 100644 --- a/docs/docs/modules/data_connection/retrievers/parent_document_retriever.ipynb +++ b/docs/docs/modules/data_connection/retrievers/parent_document_retriever.ipynb @@ -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, diff --git a/pyproject.toml b/pyproject.toml index fb7c59786..617e0b881 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] +