From 9ffca3b92a465fd6eba01416ea34a0eb1458ac4f Mon Sep 17 00:00:00 2001 From: Bagatur <22008038+baskaryan@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:49:10 -0800 Subject: [PATCH] docs[patch], templates[patch]: Import from core (#14575) Update imports to use core for the low-hanging fruit changes. Ran following ```bash git grep -l 'langchain.schema.runnable' {docs,templates,cookbook} | xargs sed -i '' 's/langchain\.schema\.runnable/langchain_core.runnables/g' git grep -l 'langchain.schema.output_parser' {docs,templates,cookbook} | xargs sed -i '' 's/langchain\.schema\.output_parser/langchain_core.output_parsers/g' git grep -l 'langchain.schema.messages' {docs,templates,cookbook} | xargs sed -i '' 's/langchain\.schema\.messages/langchain_core.messages/g' git grep -l 'langchain.schema.chat_histry' {docs,templates,cookbook} | xargs sed -i '' 's/langchain\.schema\.chat_history/langchain_core.chat_history/g' git grep -l 'langchain.schema.prompt_template' {docs,templates,cookbook} | xargs sed -i '' 's/langchain\.schema\.prompt_template/langchain_core.prompts/g' git grep -l 'from langchain.pydantic_v1' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.pydantic_v1/from langchain_core.pydantic_v1/g' git grep -l 'from langchain.tools.base' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.tools\.base/from langchain_core.tools/g' git grep -l 'from langchain.chat_models.base' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.chat_models.base/from langchain_core.language_models.chat_models/g' git grep -l 'from langchain.llms.base' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.llms\.base\ /from langchain_core.language_models.llms\ /g' git grep -l 'from langchain.embeddings.base' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.embeddings\.base/from langchain_core.embeddings/g' git grep -l 'from langchain.vectorstores.base' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.vectorstores\.base/from langchain_core.vectorstores/g' git grep -l 'from langchain.agents.tools' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.agents\.tools/from langchain_core.tools/g' git grep -l 'from langchain.schema.output' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.output\ /from langchain_core.outputs\ /g' git grep -l 'from langchain.schema.embeddings' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.embeddings/from langchain_core.embeddings/g' git grep -l 'from langchain.schema.document' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.document/from langchain_core.documents/g' git grep -l 'from langchain.schema.agent' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.agent/from langchain_core.agents/g' git grep -l 'from langchain.schema.prompt ' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.prompt\ /from langchain_core.prompt_values /g' git grep -l 'from langchain.schema.language_model' {docs,templates,cookbook} | xargs sed -i '' 's/from langchain\.schema\.language_model/from langchain_core.language_models/g' ``` --- cookbook/LLaMA2_sql_chat.ipynb | 6 +++--- cookbook/Multi_modal_RAG.ipynb | 8 ++++---- cookbook/Semi_Structured_RAG.ipynb | 6 +++--- cookbook/Semi_structured_and_multi_modal_RAG.ipynb | 6 +++--- .../Semi_structured_multi_modal_RAG_LLaMA2.ipynb | 6 +++--- cookbook/advanced_rag_eval.ipynb | 10 +++++----- cookbook/docugami_xml_kg_rag.ipynb | 6 +++--- cookbook/extraction_openai_tools.ipynb | 10 +++++----- cookbook/multi_modal_QA.ipynb | 2 +- cookbook/multi_modal_RAG_chroma.ipynb | 6 +++--- cookbook/openai_v1_cookbook.ipynb | 6 +++--- cookbook/plan_and_execute_agent.ipynb | 2 +- cookbook/rag_fusion.ipynb | 2 +- cookbook/retrieval_in_sql.ipynb | 6 +++--- cookbook/rewrite.ipynb | 6 +++--- .../selecting_llms_based_on_context_length.ipynb | 4 ++-- cookbook/stepback-qa.ipynb | 4 ++-- .../cookbook/code_writing.ipynb | 2 +- .../cookbook/embedding_router.ipynb | 4 ++-- .../docs/expression_language/cookbook/memory.ipynb | 2 +- .../cookbook/multiple_chains.ipynb | 2 +- .../cookbook/prompt_llm_parser.ipynb | 4 ++-- .../expression_language/cookbook/retrieval.ipynb | 11 +++++------ .../docs/expression_language/cookbook/sql_db.ipynb | 4 ++-- docs/docs/expression_language/cookbook/tools.ipynb | 4 ++-- docs/docs/expression_language/get_started.ipynb | 6 +++--- docs/docs/expression_language/how_to/binding.ipynb | 2 +- .../expression_language/how_to/configure.ipynb | 4 ++-- .../expression_language/how_to/fallbacks.ipynb | 2 +- .../expression_language/how_to/functions.ipynb | 6 +++--- .../expression_language/how_to/generators.ipynb | 2 +- docs/docs/expression_language/how_to/map.ipynb | 10 +++++----- .../how_to/message_history.ipynb | 8 ++++---- .../expression_language/how_to/passthrough.ipynb | 6 +++--- docs/docs/expression_language/how_to/routing.ipynb | 6 +++--- docs/docs/expression_language/interface.ipynb | 6 +++--- docs/docs/expression_language/why.ipynb | 2 +- docs/docs/guides/fallbacks.ipynb | 2 +- .../qa_privacy_protection.ipynb | 4 ++-- docs/docs/guides/pydantic_compatibility.md | 4 ++-- .../integrations/chat/baidu_qianfan_endpoint.ipynb | 2 +- docs/docs/integrations/chat/fireworks.ipynb | 2 +- .../integrations/chat/pai_eas_chat_endpoint.ipynb | 2 +- docs/docs/integrations/chat_loaders/facebook.ipynb | 2 +- docs/docs/integrations/chat_loaders/imessage.ipynb | 2 +- .../chat_loaders/langsmith_llm_runs.ipynb | 4 ++-- .../integrations/document_loaders/docugami.ipynb | 2 +- .../document_transformers/nuclia_transformer.ipynb | 2 +- docs/docs/integrations/llms/databricks.ipynb | 2 +- docs/docs/integrations/llms/opaqueprompts.ipynb | 4 ++-- docs/docs/integrations/llms/volcengine_maas.ipynb | 2 +- docs/docs/integrations/providers/databricks.md | 2 +- docs/docs/integrations/retrievers/cohere.ipynb | 2 +- .../integrations/retrievers/fleet_context.ipynb | 4 ++-- docs/docs/integrations/vectorstores/astradb.ipynb | 6 +++--- docs/docs/integrations/vectorstores/weaviate.ipynb | 4 ++-- .../agents/agent_types/openai_assistants.ipynb | 2 +- docs/docs/modules/agents/how_to/agent_iter.ipynb | 2 +- .../modules/agents/how_to/agent_structured.ipynb | 2 +- docs/docs/modules/agents/index.ipynb | 4 ++-- docs/docs/modules/agents/tools/custom_tools.ipynb | 2 +- docs/docs/modules/chains/document/map_reduce.ipynb | 4 ++-- docs/docs/modules/chains/document/map_rerank.ipynb | 6 +++--- docs/docs/modules/chains/document/refine.ipynb | 2 +- docs/docs/modules/chains/document/stuff.ipynb | 2 +- docs/docs/modules/chains/foundational/router.ipynb | 10 +++++----- .../chains/foundational/sequential_chains.ipynb | 2 +- docs/docs/modules/chains/how_to/custom_chain.ipynb | 2 +- .../modules/chains/how_to/openai_functions.ipynb | 2 +- .../modules/data_connection/retrievers/index.ipynb | 2 +- .../data_connection/retrievers/multi_vector.ipynb | 4 ++-- docs/docs/modules/model_io/chat/index.ipynb | 2 +- docs/docs/modules/model_io/llms/custom_llm.ipynb | 2 +- .../modules/model_io/output_parsers/index.ipynb | 2 +- .../output_parsers/output_fixing_parser.mdx | 2 +- .../modules/model_io/output_parsers/pydantic.ipynb | 2 +- .../model_io/prompts/prompt_templates/index.ipynb | 2 +- .../prompt_templates/msg_prompt_templates.mdx | 2 +- docs/docs/use_cases/data_generation.ipynb | 2 +- docs/docs/use_cases/extraction.ipynb | 2 +- .../question_answering/code_understanding.ipynb | 2 +- .../conversational_retrieval_agents.ipynb | 2 +- docs/docs/use_cases/question_answering/index.ipynb | 10 +++++----- docs/docs/use_cases/tagging.ipynb | 2 +- docs/scripts/model_feat_table.py | 4 ++-- .../anthropic_iterative_search/chain.py | 6 +++--- .../anthropic_iterative_search/output_parser.py | 2 +- .../anthropic_iterative_search/retriever_agent.py | 4 ++-- .../basic_critique_revise/chain.py | 4 ++-- .../cassandra_entomology_rag/__init__.py | 4 ++-- .../cassandra_synonym_caching/__init__.py | 2 +- .../chain-of-note-wiki/chain_of_note_wiki/chain.py | 4 ++-- .../chat-bot-feedback/chat_bot_feedback/chain.py | 2 +- templates/csv-agent/csv_agent/agent.py | 2 +- .../elastic_query_generator/chain.py | 2 +- .../extraction_anthropic_functions/chain.py | 2 +- .../extraction_openai_functions/chain.py | 2 +- .../hybrid_search_weaviate/chain.py | 4 ++-- templates/hyde/hyde/chain.py | 6 +++--- .../mongo_parent_document_retrieval/chain.py | 8 ++++---- templates/neo4j-advanced-rag/ingest.py | 2 +- .../neo4j-advanced-rag/neo4j_advanced_rag/chain.py | 6 +++--- templates/neo4j-cypher-ft/neo4j_cypher_ft/chain.py | 6 +++--- .../neo4j_cypher_memory/chain.py | 6 +++--- templates/neo4j-cypher/neo4j_cypher/chain.py | 6 +++--- .../neo4j-generation/neo4j_generation/utils.py | 2 +- templates/neo4j-parent/neo4j_parent/chain.py | 6 +++--- .../neo4j_vector_memory/chain.py | 6 +++--- .../openai_functions_agent/agent.py | 4 ++-- .../openai_functions_tool_retrieval_agent/agent.py | 8 ++++---- .../pii_protected_chatbot/chain.py | 8 ++++---- .../pirate_speak_configurable/chain.py | 2 +- templates/plate-chain/plate_chain/chain.py | 4 ++-- .../rag-astradb/astradb_entomology_rag/__init__.py | 4 ++-- templates/rag-aws-bedrock/rag_aws_bedrock/chain.py | 6 +++--- templates/rag-aws-kendra/rag_aws_kendra/chain.py | 6 +++--- .../rag_chroma_multi_modal/chain.py | 10 +++++----- .../rag-chroma-private/rag_chroma_private/chain.py | 6 +++--- templates/rag-chroma/rag_chroma/chain.py | 6 +++--- .../rag_codellama_fireworks/chain.py | 6 +++--- .../rag_conversation_zep/chain.py | 14 +++++++------- .../rag-conversation/rag_conversation/chain.py | 6 +++--- .../rag-elasticsearch/rag_elasticsearch/chain.py | 4 ++-- templates/rag-fusion/rag_fusion/chain.py | 4 ++-- .../chain.py | 8 ++++---- .../rag_google_cloud_vertexai_search/chain.py | 6 +++--- templates/rag-gpt-crawler/rag_gpt_crawler/chain.py | 6 +++--- .../rag_matching_engine/chain.py | 6 +++--- .../rag_momento_vector_index/chain.py | 6 +++--- templates/rag-mongo/rag_mongo/chain.py | 10 +++++----- .../rag_multi_index_fusion/chain.py | 6 +++--- .../rag_multi_index_router/chain.py | 6 +++--- .../rag_ollama_multi_query/chain.py | 6 +++--- templates/rag-opensearch/rag_opensearch/chain.py | 6 +++--- .../rag_pinecone_multi_query/chain.py | 6 +++--- .../rag_pinecone_rerank/chain.py | 6 +++--- templates/rag-pinecone/rag_pinecone/chain.py | 6 +++--- templates/rag-redis/rag_redis/chain.py | 6 +++--- templates/rag-self-query/rag_self_query/chain.py | 4 ++-- .../rag_semi_structured/chain.py | 8 ++++---- .../rag-singlestoredb/rag_singlestoredb/chain.py | 6 +++--- templates/rag-supabase/rag_supabase/chain.py | 6 +++--- .../rag_timescale_conversation/chain.py | 6 +++--- .../rag_timescale_hybrid_search_time/chain.py | 4 ++-- .../rag_vectara_multiquery/chain.py | 6 +++--- templates/rag-vectara/rag_vectara/chain.py | 6 +++--- templates/rag-weaviate/rag_weaviate/chain.py | 6 +++--- .../research-assistant/research_assistant/chain.py | 4 ++-- .../research_assistant/search/web.py | 8 ++++---- .../research_assistant/writer.py | 4 ++-- templates/retrieval-agent/retrieval_agent/chain.py | 4 ++-- .../rewrite_retrieve_read/chain.py | 6 +++--- .../self-query-qdrant/self_query_qdrant/chain.py | 6 +++--- .../self_query_supabase/chain.py | 2 +- .../skeleton_of_thought/chain.py | 6 +++--- .../solo_performance_prompting_agent/agent.py | 2 +- templates/sql-llama2/sql_llama2/chain.py | 6 +++--- templates/sql-llamacpp/sql_llamacpp/chain.py | 6 +++--- templates/sql-ollama/sql_ollama/chain.py | 6 +++--- templates/sql-pgvector/sql_pgvector/chain.py | 6 +++--- .../stepback_qa_prompting/chain.py | 4 ++-- .../summarize_anthropic/chain.py | 2 +- templates/xml-agent/xml_agent/agent.py | 2 +- 163 files changed, 368 insertions(+), 369 deletions(-) diff --git a/cookbook/LLaMA2_sql_chat.ipynb b/cookbook/LLaMA2_sql_chat.ipynb index 61e3d5a7654af..3fd6a5dc5cc95 100644 --- a/cookbook/LLaMA2_sql_chat.ipynb +++ b/cookbook/LLaMA2_sql_chat.ipynb @@ -164,8 +164,8 @@ ")\n", "\n", "# Chain to query\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "sql_response = (\n", " RunnablePassthrough.assign(schema=get_schema)\n", @@ -293,7 +293,7 @@ "memory = ConversationBufferMemory(return_messages=True)\n", "\n", "# Chain to query with memory\n", - "from langchain.schema.runnable import RunnableLambda\n", + "from langchain_core.runnables import RunnableLambda\n", "\n", "sql_chain = (\n", " RunnablePassthrough.assign(\n", diff --git a/cookbook/Multi_modal_RAG.ipynb b/cookbook/Multi_modal_RAG.ipynb index ca6f879c70d3e..d540b4a0bec61 100644 --- a/cookbook/Multi_modal_RAG.ipynb +++ b/cookbook/Multi_modal_RAG.ipynb @@ -200,7 +200,7 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", + "from langchain_core.output_parsers import StrOutputParser\n", "\n", "\n", "# Generate summaries of text elements\n", @@ -270,7 +270,7 @@ "import base64\n", "import os\n", "\n", - "from langchain.schema.messages import HumanMessage\n", + "from langchain_core.messages import HumanMessage\n", "\n", "\n", "def encode_image(image_path):\n", @@ -355,9 +355,9 @@ "\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.retrievers.multi_vector import MultiVectorRetriever\n", - "from langchain.schema.document import Document\n", "from langchain.storage import InMemoryStore\n", "from langchain.vectorstores import Chroma\n", + "from langchain_core.documents import Document\n", "\n", "\n", "def create_multi_vector_retriever(\n", @@ -442,7 +442,7 @@ "import re\n", "\n", "from IPython.display import HTML, display\n", - "from langchain.schema.runnable import RunnableLambda, RunnablePassthrough\n", + "from langchain_core.runnables import RunnableLambda, RunnablePassthrough\n", "from PIL import Image\n", "\n", "\n", diff --git a/cookbook/Semi_Structured_RAG.ipynb b/cookbook/Semi_Structured_RAG.ipynb index c1d8823f976f3..91820b69d2fd0 100644 --- a/cookbook/Semi_Structured_RAG.ipynb +++ b/cookbook/Semi_Structured_RAG.ipynb @@ -237,7 +237,7 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser" + "from langchain_core.output_parsers import StrOutputParser" ] }, { @@ -320,9 +320,9 @@ "\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.retrievers.multi_vector import MultiVectorRetriever\n", - "from langchain.schema.document import Document\n", "from langchain.storage import InMemoryStore\n", "from langchain.vectorstores import Chroma\n", + "from langchain_core.documents import Document\n", "\n", "# The vectorstore to use to index the child chunks\n", "vectorstore = Chroma(collection_name=\"summaries\", embedding_function=OpenAIEmbeddings())\n", @@ -374,7 +374,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "# Prompt template\n", "template = \"\"\"Answer the question based only on the following context, which can include text and tables:\n", diff --git a/cookbook/Semi_structured_and_multi_modal_RAG.ipynb b/cookbook/Semi_structured_and_multi_modal_RAG.ipynb index 459258ce3cc7d..3c618e45d6728 100644 --- a/cookbook/Semi_structured_and_multi_modal_RAG.ipynb +++ b/cookbook/Semi_structured_and_multi_modal_RAG.ipynb @@ -213,7 +213,7 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser" + "from langchain_core.output_parsers import StrOutputParser" ] }, { @@ -375,9 +375,9 @@ "\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.retrievers.multi_vector import MultiVectorRetriever\n", - "from langchain.schema.document import Document\n", "from langchain.storage import InMemoryStore\n", "from langchain.vectorstores import Chroma\n", + "from langchain_core.documents import Document\n", "\n", "# The vectorstore to use to index the child chunks\n", "vectorstore = Chroma(collection_name=\"summaries\", embedding_function=OpenAIEmbeddings())\n", @@ -646,7 +646,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "# Prompt template\n", "template = \"\"\"Answer the question based only on the following context, which can include text and tables:\n", diff --git a/cookbook/Semi_structured_multi_modal_RAG_LLaMA2.ipynb b/cookbook/Semi_structured_multi_modal_RAG_LLaMA2.ipynb index 27a53120e36e0..5d43158455f8f 100644 --- a/cookbook/Semi_structured_multi_modal_RAG_LLaMA2.ipynb +++ b/cookbook/Semi_structured_multi_modal_RAG_LLaMA2.ipynb @@ -211,7 +211,7 @@ "source": [ "from langchain.chat_models import ChatOllama\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser" + "from langchain_core.output_parsers import StrOutputParser" ] }, { @@ -378,9 +378,9 @@ "\n", "from langchain.embeddings import GPT4AllEmbeddings\n", "from langchain.retrievers.multi_vector import MultiVectorRetriever\n", - "from langchain.schema.document import Document\n", "from langchain.storage import InMemoryStore\n", "from langchain.vectorstores import Chroma\n", + "from langchain_core.documents import Document\n", "\n", "# The vectorstore to use to index the child chunks\n", "vectorstore = Chroma(\n", @@ -532,7 +532,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "# Prompt template\n", "template = \"\"\"Answer the question based only on the following context, which can include text and tables:\n", diff --git a/cookbook/advanced_rag_eval.ipynb b/cookbook/advanced_rag_eval.ipynb index 7d0494469df62..2ca2048f5dbc9 100644 --- a/cookbook/advanced_rag_eval.ipynb +++ b/cookbook/advanced_rag_eval.ipynb @@ -162,7 +162,7 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", + "from langchain_core.output_parsers import StrOutputParser\n", "\n", "# Prompt\n", "prompt_text = \"\"\"You are an assistant tasked with summarizing tables and text for retrieval. \\\n", @@ -202,7 +202,7 @@ "import os\n", "from io import BytesIO\n", "\n", - "from langchain.schema.messages import HumanMessage\n", + "from langchain_core.messages import HumanMessage\n", "from PIL import Image\n", "\n", "\n", @@ -273,8 +273,8 @@ "from base64 import b64decode\n", "\n", "from langchain.retrievers.multi_vector import MultiVectorRetriever\n", - "from langchain.schema.document import Document\n", "from langchain.storage import InMemoryStore\n", + "from langchain_core.documents import Document\n", "\n", "\n", "def create_multi_vector_retriever(\n", @@ -475,7 +475,7 @@ "source": [ "from operator import itemgetter\n", "\n", - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "# Prompt\n", "template = \"\"\"Answer the question based only on the following context, which can include text and tables:\n", @@ -521,7 +521,7 @@ "import re\n", "\n", "from langchain.schema import Document\n", - "from langchain.schema.runnable import RunnableLambda\n", + "from langchain_core.runnables import RunnableLambda\n", "\n", "\n", "def looks_like_base64(sb):\n", diff --git a/cookbook/docugami_xml_kg_rag.ipynb b/cookbook/docugami_xml_kg_rag.ipynb index 43383a47493f6..ba85e37612785 100644 --- a/cookbook/docugami_xml_kg_rag.ipynb +++ b/cookbook/docugami_xml_kg_rag.ipynb @@ -476,7 +476,7 @@ " HumanMessagePromptTemplate,\n", " SystemMessagePromptTemplate,\n", ")\n", - "from langchain.schema.output_parser import StrOutputParser" + "from langchain_core.output_parsers import StrOutputParser" ] }, { @@ -547,9 +547,9 @@ "\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.retrievers.multi_vector import MultiVectorRetriever\n", - "from langchain.schema.document import Document\n", "from langchain.storage import InMemoryStore\n", "from langchain.vectorstores.chroma import Chroma\n", + "from langchain_core.documents import Document\n", "\n", "\n", "def build_retriever(text_elements, tables, table_summaries):\n", @@ -605,7 +605,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "system_prompt = SystemMessagePromptTemplate.from_template(\n", " \"You are a helpful assistant that answers questions based on provided context. Your provided context can include text or tables, \"\n", diff --git a/cookbook/extraction_openai_tools.ipynb b/cookbook/extraction_openai_tools.ipynb index b9e78b96c1f20..23a8c1f2d7b66 100644 --- a/cookbook/extraction_openai_tools.ipynb +++ b/cookbook/extraction_openai_tools.ipynb @@ -23,7 +23,7 @@ "\n", "from langchain.chains.openai_tools import create_extraction_chain_pydantic\n", "from langchain.chat_models import ChatOpenAI\n", - "from langchain.pydantic_v1 import BaseModel" + "from langchain_core.pydantic_v1 import BaseModel" ] }, { @@ -151,11 +151,11 @@ "\n", "from langchain.output_parsers.openai_tools import PydanticToolsParser\n", "from langchain.utils.openai_functions import convert_pydantic_to_openai_tool\n", - "from langchain.schema.runnable import Runnable\n", - "from langchain.pydantic_v1 import BaseModel\n", + "from langchain_core.runnables import Runnable\n", + "from langchain_core.pydantic_v1 import BaseModel\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.messages import SystemMessage\n", - "from langchain.schema.language_model import BaseLanguageModel\n", + "from langchain_core.messages import SystemMessage\n", + "from langchain_core.language_models import BaseLanguageModel\n", "\n", "_EXTRACTION_TEMPLATE = \"\"\"Extract and save the relevant entities mentioned \\\n", "in the following passage together with their properties.\n", diff --git a/cookbook/multi_modal_QA.ipynb b/cookbook/multi_modal_QA.ipynb index c886212cde90b..2c52034e2c264 100644 --- a/cookbook/multi_modal_QA.ipynb +++ b/cookbook/multi_modal_QA.ipynb @@ -92,7 +92,7 @@ "outputs": [], "source": [ "from langchain.chat_models import ChatOpenAI\n", - "from langchain.schema.messages import HumanMessage, SystemMessage" + "from langchain_core.messages import HumanMessage, SystemMessage" ] }, { diff --git a/cookbook/multi_modal_RAG_chroma.ipynb b/cookbook/multi_modal_RAG_chroma.ipynb index 48b5d39025021..5a3908a0b6d51 100644 --- a/cookbook/multi_modal_RAG_chroma.ipynb +++ b/cookbook/multi_modal_RAG_chroma.ipynb @@ -316,9 +316,9 @@ "from operator import itemgetter\n", "\n", "from langchain.chat_models import ChatOpenAI\n", - "from langchain.schema.messages import HumanMessage, SystemMessage\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnableLambda, RunnablePassthrough\n", + "from langchain_core.messages import HumanMessage, SystemMessage\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnableLambda, RunnablePassthrough\n", "\n", "\n", "def prompt_func(data_dict):\n", diff --git a/cookbook/openai_v1_cookbook.ipynb b/cookbook/openai_v1_cookbook.ipynb index 15c3b6557374b..a8bcc2cf541fa 100644 --- a/cookbook/openai_v1_cookbook.ipynb +++ b/cookbook/openai_v1_cookbook.ipynb @@ -29,7 +29,7 @@ "outputs": [], "source": [ "from langchain.chat_models import ChatOpenAI\n", - "from langchain.schema.messages import HumanMessage, SystemMessage" + "from langchain_core.messages import HumanMessage, SystemMessage" ] }, { @@ -252,7 +252,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.agent import AgentFinish\n", + "from langchain_core.agents import AgentFinish\n", "\n", "\n", "def execute_agent(agent, tools, input):\n", @@ -457,8 +457,8 @@ "\n", "from langchain.output_parsers.openai_tools import PydanticToolsParser\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.pydantic_v1 import BaseModel, Field\n", "from langchain.utils.openai_functions import convert_pydantic_to_openai_tool\n", + "from langchain_core.pydantic_v1 import BaseModel, Field\n", "\n", "\n", "class GetCurrentWeather(BaseModel):\n", diff --git a/cookbook/plan_and_execute_agent.ipynb b/cookbook/plan_and_execute_agent.ipynb index 2fa14881e3854..e37ee550be1ed 100644 --- a/cookbook/plan_and_execute_agent.ipynb +++ b/cookbook/plan_and_execute_agent.ipynb @@ -29,11 +29,11 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.agents.tools import Tool\n", "from langchain.chains import LLMMathChain\n", "from langchain.chat_models import ChatOpenAI\n", "from langchain.llms import OpenAI\n", "from langchain.utilities import DuckDuckGoSearchAPIWrapper\n", + "from langchain_core.tools import Tool\n", "from langchain_experimental.plan_and_execute import (\n", " PlanAndExecute,\n", " load_agent_executor,\n", diff --git a/cookbook/rag_fusion.ipynb b/cookbook/rag_fusion.ipynb index aae35fec33178..f7823fb18cb5d 100644 --- a/cookbook/rag_fusion.ipynb +++ b/cookbook/rag_fusion.ipynb @@ -87,7 +87,7 @@ "outputs": [], "source": [ "from langchain.chat_models import ChatOpenAI\n", - "from langchain.schema.output_parser import StrOutputParser" + "from langchain_core.output_parsers import StrOutputParser" ] }, { diff --git a/cookbook/retrieval_in_sql.ipynb b/cookbook/retrieval_in_sql.ipynb index cd3209950f3e5..1a4c27a689d92 100644 --- a/cookbook/retrieval_in_sql.ipynb +++ b/cookbook/retrieval_in_sql.ipynb @@ -268,8 +268,8 @@ "outputs": [], "source": [ "from langchain.chat_models import ChatOpenAI\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "db = SQLDatabase.from_uri(\n", " CONNECTION_STRING\n", @@ -324,7 +324,7 @@ "source": [ "import re\n", "\n", - "from langchain.schema.runnable import RunnableLambda\n", + "from langchain_core.runnables import RunnableLambda\n", "\n", "\n", "def replace_brackets(match):\n", diff --git a/cookbook/rewrite.ipynb b/cookbook/rewrite.ipynb index 5eabc2c26a5bf..4faf2babcc54d 100644 --- a/cookbook/rewrite.ipynb +++ b/cookbook/rewrite.ipynb @@ -33,9 +33,9 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", - "from langchain.utilities import DuckDuckGoSearchAPIWrapper" + "from langchain.utilities import DuckDuckGoSearchAPIWrapper\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough" ] }, { diff --git a/cookbook/selecting_llms_based_on_context_length.ipynb b/cookbook/selecting_llms_based_on_context_length.ipynb index 8556854acddb3..58976419b5304 100644 --- a/cookbook/selecting_llms_based_on_context_length.ipynb +++ b/cookbook/selecting_llms_based_on_context_length.ipynb @@ -19,8 +19,8 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import PromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.prompt import PromptValue" + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.prompt_values import PromptValue" ] }, { diff --git a/cookbook/stepback-qa.ipynb b/cookbook/stepback-qa.ipynb index f94922ef04131..920d0001a2b2b 100644 --- a/cookbook/stepback-qa.ipynb +++ b/cookbook/stepback-qa.ipynb @@ -25,8 +25,8 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate, FewShotChatMessagePromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnableLambda" + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnableLambda" ] }, { diff --git a/docs/docs/expression_language/cookbook/code_writing.ipynb b/docs/docs/expression_language/cookbook/code_writing.ipynb index 005043629fea5..5da7992c73525 100644 --- a/docs/docs/expression_language/cookbook/code_writing.ipynb +++ b/docs/docs/expression_language/cookbook/code_writing.ipynb @@ -21,7 +21,7 @@ "from langchain.prompts import (\n", " ChatPromptTemplate,\n", ")\n", - "from langchain.schema.output_parser import StrOutputParser\n", + "from langchain_core.output_parsers import StrOutputParser\n", "from langchain_experimental.utilities import PythonREPL" ] }, diff --git a/docs/docs/expression_language/cookbook/embedding_router.ipynb b/docs/docs/expression_language/cookbook/embedding_router.ipynb index 98d33ff4f3119..2123963b71aea 100644 --- a/docs/docs/expression_language/cookbook/embedding_router.ipynb +++ b/docs/docs/expression_language/cookbook/embedding_router.ipynb @@ -22,9 +22,9 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.prompts import PromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnableLambda, RunnablePassthrough\n", "from langchain.utils.math import cosine_similarity\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnableLambda, RunnablePassthrough\n", "\n", "physics_template = \"\"\"You are a very smart physics professor. \\\n", "You are great at answering questions about physics in a concise and easy to understand manner. \\\n", diff --git a/docs/docs/expression_language/cookbook/memory.ipynb b/docs/docs/expression_language/cookbook/memory.ipynb index 726fec5be11be..a5fcbbb8c2e43 100644 --- a/docs/docs/expression_language/cookbook/memory.ipynb +++ b/docs/docs/expression_language/cookbook/memory.ipynb @@ -22,7 +22,7 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.memory import ConversationBufferMemory\n", "from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder\n", - "from langchain.schema.runnable import RunnableLambda, RunnablePassthrough\n", + "from langchain_core.runnables import RunnableLambda, RunnablePassthrough\n", "\n", "model = ChatOpenAI()\n", "prompt = ChatPromptTemplate.from_messages(\n", diff --git a/docs/docs/expression_language/cookbook/multiple_chains.ipynb b/docs/docs/expression_language/cookbook/multiple_chains.ipynb index c380d29f1bde4..01a98cea328c3 100644 --- a/docs/docs/expression_language/cookbook/multiple_chains.ipynb +++ b/docs/docs/expression_language/cookbook/multiple_chains.ipynb @@ -69,7 +69,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "prompt1 = ChatPromptTemplate.from_template(\n", " \"generate a {attribute} color. Return the name of the color and nothing else:\"\n", diff --git a/docs/docs/expression_language/cookbook/prompt_llm_parser.ipynb b/docs/docs/expression_language/cookbook/prompt_llm_parser.ipynb index 81fd0ec05795d..9f6bae10cfcf1 100644 --- a/docs/docs/expression_language/cookbook/prompt_llm_parser.ipynb +++ b/docs/docs/expression_language/cookbook/prompt_llm_parser.ipynb @@ -191,7 +191,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.output_parser import StrOutputParser\n", + "from langchain_core.output_parsers import StrOutputParser\n", "\n", "chain = prompt | model | StrOutputParser()" ] @@ -327,7 +327,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.runnable import RunnableParallel, RunnablePassthrough\n", + "from langchain_core.runnables import RunnableParallel, RunnablePassthrough\n", "\n", "map_ = RunnableParallel(foo=RunnablePassthrough())\n", "chain = (\n", diff --git a/docs/docs/expression_language/cookbook/retrieval.ipynb b/docs/docs/expression_language/cookbook/retrieval.ipynb index aef5c1fb6374f..f914170aa8633 100644 --- a/docs/docs/expression_language/cookbook/retrieval.ipynb +++ b/docs/docs/expression_language/cookbook/retrieval.ipynb @@ -41,9 +41,9 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnableLambda, RunnablePassthrough\n", - "from langchain.vectorstores import FAISS" + "from langchain.vectorstores import FAISS\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnableLambda, RunnablePassthrough" ] }, { @@ -171,9 +171,8 @@ "outputs": [], "source": [ "from langchain.schema import format_document\n", - "from langchain.schema.messages import get_buffer_string\n", - "from langchain.schema.runnable import RunnableParallel\n", - "from langchain_core.messages import AIMessage, HumanMessage" + "from langchain_core.messages import AIMessage, HumanMessage, get_buffer_string\n", + "from langchain_core.runnables import RunnableParallel" ] }, { diff --git a/docs/docs/expression_language/cookbook/sql_db.ipynb b/docs/docs/expression_language/cookbook/sql_db.ipynb index dc5e134b3a463..8e872655ecd54 100644 --- a/docs/docs/expression_language/cookbook/sql_db.ipynb +++ b/docs/docs/expression_language/cookbook/sql_db.ipynb @@ -94,8 +94,8 @@ "outputs": [], "source": [ "from langchain.chat_models import ChatOpenAI\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "model = ChatOpenAI()\n", "\n", diff --git a/docs/docs/expression_language/cookbook/tools.ipynb b/docs/docs/expression_language/cookbook/tools.ipynb index d13dece3c9f15..c0f6a99794dee 100644 --- a/docs/docs/expression_language/cookbook/tools.ipynb +++ b/docs/docs/expression_language/cookbook/tools.ipynb @@ -29,8 +29,8 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.tools import DuckDuckGoSearchRun" + "from langchain.tools import DuckDuckGoSearchRun\n", + "from langchain_core.output_parsers import StrOutputParser" ] }, { diff --git a/docs/docs/expression_language/get_started.ipynb b/docs/docs/expression_language/get_started.ipynb index 39c04a9f61a29..0f09acb73f004 100644 --- a/docs/docs/expression_language/get_started.ipynb +++ b/docs/docs/expression_language/get_started.ipynb @@ -49,7 +49,7 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", + "from langchain_core.output_parsers import StrOutputParser\n", "\n", "prompt = ChatPromptTemplate.from_template(\"tell me a short joke about {topic}\")\n", "model = ChatOpenAI()\n", @@ -326,9 +326,9 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnableParallel, RunnablePassthrough\n", "from langchain.vectorstores import DocArrayInMemorySearch\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnableParallel, RunnablePassthrough\n", "\n", "vectorstore = DocArrayInMemorySearch.from_texts(\n", " [\"harrison worked at kensho\", \"bears like to eat honey\"],\n", diff --git a/docs/docs/expression_language/how_to/binding.ipynb b/docs/docs/expression_language/how_to/binding.ipynb index 19efcef0162ce..6f9978bcc10ee 100644 --- a/docs/docs/expression_language/how_to/binding.ipynb +++ b/docs/docs/expression_language/how_to/binding.ipynb @@ -22,7 +22,7 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", "from langchain.schema import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough" + "from langchain_core.runnables import RunnablePassthrough" ] }, { diff --git a/docs/docs/expression_language/how_to/configure.ipynb b/docs/docs/expression_language/how_to/configure.ipynb index c36bd7e5ad533..5b7804697665f 100644 --- a/docs/docs/expression_language/how_to/configure.ipynb +++ b/docs/docs/expression_language/how_to/configure.ipynb @@ -43,7 +43,7 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import PromptTemplate\n", - "from langchain.schema.runnable import ConfigurableField\n", + "from langchain_core.runnables import ConfigurableField\n", "\n", "model = ChatOpenAI(temperature=0).configurable_fields(\n", " temperature=ConfigurableField(\n", @@ -265,7 +265,7 @@ "source": [ "from langchain.chat_models import ChatAnthropic, ChatOpenAI\n", "from langchain.prompts import PromptTemplate\n", - "from langchain.schema.runnable import ConfigurableField" + "from langchain_core.runnables import ConfigurableField" ] }, { diff --git a/docs/docs/expression_language/how_to/fallbacks.ipynb b/docs/docs/expression_language/how_to/fallbacks.ipynb index 575d13fbd7452..cc3578106a37d 100644 --- a/docs/docs/expression_language/how_to/fallbacks.ipynb +++ b/docs/docs/expression_language/how_to/fallbacks.ipynb @@ -216,7 +216,7 @@ "source": [ "# First let's create a chain with a ChatModel\n", "# We add in a string output parser here so the outputs between the two are the same type\n", - "from langchain.schema.output_parser import StrOutputParser\n", + "from langchain_core.output_parsers import StrOutputParser\n", "\n", "chat_prompt = ChatPromptTemplate.from_messages(\n", " [\n", diff --git a/docs/docs/expression_language/how_to/functions.ipynb b/docs/docs/expression_language/how_to/functions.ipynb index d1849ff0a7b3e..0d092a19db80b 100644 --- a/docs/docs/expression_language/how_to/functions.ipynb +++ b/docs/docs/expression_language/how_to/functions.ipynb @@ -34,7 +34,7 @@ "\n", "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.runnable import RunnableLambda\n", + "from langchain_core.runnables import RunnableLambda\n", "\n", "\n", "def length_function(text):\n", @@ -103,8 +103,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnableConfig" + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnableConfig" ] }, { diff --git a/docs/docs/expression_language/how_to/generators.ipynb b/docs/docs/expression_language/how_to/generators.ipynb index 8f0010c6c7ce5..627be2248c251 100644 --- a/docs/docs/expression_language/how_to/generators.ipynb +++ b/docs/docs/expression_language/how_to/generators.ipynb @@ -34,7 +34,7 @@ "\n", "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts.chat import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", + "from langchain_core.output_parsers import StrOutputParser\n", "\n", "prompt = ChatPromptTemplate.from_template(\n", " \"Write a comma-separated list of 5 animals similar to: {animal}\"\n", diff --git a/docs/docs/expression_language/how_to/map.ipynb b/docs/docs/expression_language/how_to/map.ipynb index 71c22a0b0e2d0..02e431899e822 100644 --- a/docs/docs/expression_language/how_to/map.ipynb +++ b/docs/docs/expression_language/how_to/map.ipynb @@ -47,9 +47,9 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", "from langchain.vectorstores import FAISS\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "vectorstore = FAISS.from_texts(\n", " [\"harrison worked at kensho\"], embedding=OpenAIEmbeddings()\n", @@ -131,9 +131,9 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", "from langchain.vectorstores import FAISS\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "vectorstore = FAISS.from_texts(\n", " [\"harrison worked at kensho\"], embedding=OpenAIEmbeddings()\n", @@ -194,7 +194,7 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.runnable import RunnableParallel\n", + "from langchain_core.runnables import RunnableParallel\n", "\n", "model = ChatOpenAI()\n", "joke_chain = ChatPromptTemplate.from_template(\"tell me a joke about {topic}\") | model\n", diff --git a/docs/docs/expression_language/how_to/message_history.ipynb b/docs/docs/expression_language/how_to/message_history.ipynb index 77991cb66bd77..96999ffd000b1 100644 --- a/docs/docs/expression_language/how_to/message_history.ipynb +++ b/docs/docs/expression_language/how_to/message_history.ipynb @@ -132,8 +132,8 @@ "from langchain.chat_models import ChatAnthropic\n", "from langchain.memory.chat_message_histories import RedisChatMessageHistory\n", "from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder\n", - "from langchain.schema.chat_history import BaseChatMessageHistory\n", - "from langchain.schema.runnable.history import RunnableWithMessageHistory" + "from langchain_core.chat_history import BaseChatMessageHistory\n", + "from langchain_core.runnables.history import RunnableWithMessageHistory" ] }, { @@ -292,8 +292,8 @@ } ], "source": [ - "from langchain.schema.messages import HumanMessage\n", - "from langchain.schema.runnable import RunnableParallel\n", + "from langchain_core.messages import HumanMessage\n", + "from langchain_core.runnables import RunnableParallel\n", "\n", "chain = RunnableParallel({\"output_message\": ChatAnthropic(model=\"claude-2\")})\n", "chain_with_history = RunnableWithMessageHistory(\n", diff --git a/docs/docs/expression_language/how_to/passthrough.ipynb b/docs/docs/expression_language/how_to/passthrough.ipynb index 4dc42d2e66c5b..7615b7a0a5b1e 100644 --- a/docs/docs/expression_language/how_to/passthrough.ipynb +++ b/docs/docs/expression_language/how_to/passthrough.ipynb @@ -46,7 +46,7 @@ } ], "source": [ - "from langchain.schema.runnable import RunnableParallel, RunnablePassthrough\n", + "from langchain_core.runnables import RunnableParallel, RunnablePassthrough\n", "\n", "runnable = RunnableParallel(\n", " passed=RunnablePassthrough(),\n", @@ -100,9 +100,9 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", "from langchain.vectorstores import FAISS\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "vectorstore = FAISS.from_texts(\n", " [\"harrison worked at kensho\"], embedding=OpenAIEmbeddings()\n", diff --git a/docs/docs/expression_language/how_to/routing.ipynb b/docs/docs/expression_language/how_to/routing.ipynb index e8242635d5f3b..b78cff2629ec1 100644 --- a/docs/docs/expression_language/how_to/routing.ipynb +++ b/docs/docs/expression_language/how_to/routing.ipynb @@ -53,7 +53,7 @@ "source": [ "from langchain.chat_models import ChatAnthropic\n", "from langchain.prompts import PromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser" + "from langchain_core.output_parsers import StrOutputParser" ] }, { @@ -164,7 +164,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.runnable import RunnableBranch\n", + "from langchain_core.runnables import RunnableBranch\n", "\n", "branch = RunnableBranch(\n", " (lambda x: \"anthropic\" in x[\"topic\"].lower(), anthropic_chain),\n", @@ -279,7 +279,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.runnable import RunnableLambda\n", + "from langchain_core.runnables import RunnableLambda\n", "\n", "full_chain = {\"topic\": chain, \"question\": lambda x: x[\"question\"]} | RunnableLambda(\n", " route\n", diff --git a/docs/docs/expression_language/interface.ipynb b/docs/docs/expression_language/interface.ipynb index 39023210d6036..30432b671b9e2 100644 --- a/docs/docs/expression_language/interface.ipynb +++ b/docs/docs/expression_language/interface.ipynb @@ -660,9 +660,9 @@ ], "source": [ "from langchain.embeddings import OpenAIEmbeddings\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", "from langchain.vectorstores import FAISS\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "template = \"\"\"Answer the question based only on the following context:\n", "{context}\n", @@ -920,7 +920,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.runnable import RunnableParallel\n", + "from langchain_core.runnables import RunnableParallel\n", "\n", "chain1 = ChatPromptTemplate.from_template(\"tell me a joke about {topic}\") | model\n", "chain2 = (\n", diff --git a/docs/docs/expression_language/why.ipynb b/docs/docs/expression_language/why.ipynb index 2b8c85e6b0117..66c78087aded1 100644 --- a/docs/docs/expression_language/why.ipynb +++ b/docs/docs/expression_language/why.ipynb @@ -44,7 +44,7 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", + "from langchain_core.output_parsers import StrOutputParser\n", "\n", "\n", "prompt = ChatPromptTemplate.from_template(\"Tell me a short joke about {topic}\")\n", diff --git a/docs/docs/guides/fallbacks.ipynb b/docs/docs/guides/fallbacks.ipynb index 11107e4ffe994..cde2b709271c4 100644 --- a/docs/docs/guides/fallbacks.ipynb +++ b/docs/docs/guides/fallbacks.ipynb @@ -181,7 +181,7 @@ "source": [ "# First let's create a chain with a ChatModel\n", "# We add in a string output parser here so the outputs between the two are the same type\n", - "from langchain.schema.output_parser import StrOutputParser\n", + "from langchain_core.output_parsers import StrOutputParser\n", "\n", "chat_prompt = ChatPromptTemplate.from_messages(\n", " [\n", diff --git a/docs/docs/guides/privacy/presidio_data_anonymization/qa_privacy_protection.ipynb b/docs/docs/guides/privacy/presidio_data_anonymization/qa_privacy_protection.ipynb index 2de1e36c7923e..fe68b361d79c0 100644 --- a/docs/docs/guides/privacy/presidio_data_anonymization/qa_privacy_protection.ipynb +++ b/docs/docs/guides/privacy/presidio_data_anonymization/qa_privacy_protection.ipynb @@ -666,8 +666,8 @@ "\n", "from langchain.chat_models.openai import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import (\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import (\n", " RunnableLambda,\n", " RunnableParallel,\n", " RunnablePassthrough,\n", diff --git a/docs/docs/guides/pydantic_compatibility.md b/docs/docs/guides/pydantic_compatibility.md index fb93921675e88..7ea57543a76ff 100644 --- a/docs/docs/guides/pydantic_compatibility.md +++ b/docs/docs/guides/pydantic_compatibility.md @@ -73,7 +73,7 @@ CustomTool( **YES** ```python -from langchain.tools.base import Tool +from langchain_core.tools import Tool from pydantic.v1 import BaseModel, Field # <-- Uses v1 namespace class CalculatorInput(BaseModel): @@ -90,7 +90,7 @@ Tool.from_function( # <-- tool uses v1 namespace **NO** ```python -from langchain.tools.base import Tool +from langchain_core.tools import Tool from pydantic import BaseModel, Field # <-- Uses v2 namespace class CalculatorInput(BaseModel): diff --git a/docs/docs/integrations/chat/baidu_qianfan_endpoint.ipynb b/docs/docs/integrations/chat/baidu_qianfan_endpoint.ipynb index 65f7826815686..9506fa5a77ae7 100644 --- a/docs/docs/integrations/chat/baidu_qianfan_endpoint.ipynb +++ b/docs/docs/integrations/chat/baidu_qianfan_endpoint.ipynb @@ -71,7 +71,7 @@ "import os\n", "\n", "from langchain.chat_models import QianfanChatEndpoint\n", - "from langchain.chat_models.base import HumanMessage\n", + "from langchain_core.language_models.chat_models import HumanMessage\n", "\n", "os.environ[\"QIANFAN_AK\"] = \"your_ak\"\n", "os.environ[\"QIANFAN_SK\"] = \"your_sk\"\n", diff --git a/docs/docs/integrations/chat/fireworks.ipynb b/docs/docs/integrations/chat/fireworks.ipynb index a0a3932bc5ef5..5428039f44ea2 100644 --- a/docs/docs/integrations/chat/fireworks.ipynb +++ b/docs/docs/integrations/chat/fireworks.ipynb @@ -159,7 +159,7 @@ "from langchain.chat_models import ChatFireworks\n", "from langchain.memory import ConversationBufferMemory\n", "from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder\n", - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "llm = ChatFireworks(\n", " model=\"accounts/fireworks/models/llama-v2-13b-chat\",\n", diff --git a/docs/docs/integrations/chat/pai_eas_chat_endpoint.ipynb b/docs/docs/integrations/chat/pai_eas_chat_endpoint.ipynb index 395d64775f66e..7a93f922710f9 100644 --- a/docs/docs/integrations/chat/pai_eas_chat_endpoint.ipynb +++ b/docs/docs/integrations/chat/pai_eas_chat_endpoint.ipynb @@ -41,7 +41,7 @@ "import os\n", "\n", "from langchain.chat_models import PaiEasChatEndpoint\n", - "from langchain.chat_models.base import HumanMessage\n", + "from langchain_core.language_models.chat_models import HumanMessage\n", "\n", "os.environ[\"EAS_SERVICE_URL\"] = \"Your_EAS_Service_URL\"\n", "os.environ[\"EAS_SERVICE_TOKEN\"] = \"Your_EAS_Service_Token\"\n", diff --git a/docs/docs/integrations/chat_loaders/facebook.ipynb b/docs/docs/integrations/chat_loaders/facebook.ipynb index 4173f5f9d1cc3..92a3ef63e2e28 100644 --- a/docs/docs/integrations/chat_loaders/facebook.ipynb +++ b/docs/docs/integrations/chat_loaders/facebook.ipynb @@ -516,7 +516,7 @@ "outputs": [], "source": [ "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", + "from langchain_core.output_parsers import StrOutputParser\n", "\n", "prompt = ChatPromptTemplate.from_messages(\n", " [\n", diff --git a/docs/docs/integrations/chat_loaders/imessage.ipynb b/docs/docs/integrations/chat_loaders/imessage.ipynb index eb6a0edb3ce83..ffd6f2f3c4faa 100644 --- a/docs/docs/integrations/chat_loaders/imessage.ipynb +++ b/docs/docs/integrations/chat_loaders/imessage.ipynb @@ -360,7 +360,7 @@ "outputs": [], "source": [ "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", + "from langchain_core.output_parsers import StrOutputParser\n", "\n", "prompt = ChatPromptTemplate.from_messages(\n", " [\n", diff --git a/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb b/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb index cae7535545915..a911e141ee858 100644 --- a/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb +++ b/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb @@ -72,7 +72,7 @@ "source": [ "from enum import Enum\n", "\n", - "from langchain.pydantic_v1 import BaseModel, Field\n", + "from langchain_core.pydantic_v1 import BaseModel, Field\n", "\n", "\n", "class Operation(Enum):\n", @@ -135,8 +135,8 @@ "source": [ "from pprint import pprint\n", "\n", - "from langchain.pydantic_v1 import BaseModel\n", "from langchain.utils.openai_functions import convert_pydantic_to_openai_function\n", + "from langchain_core.pydantic_v1 import BaseModel\n", "\n", "openai_function_def = convert_pydantic_to_openai_function(Calculator)\n", "pprint(openai_function_def)" diff --git a/docs/docs/integrations/document_loaders/docugami.ipynb b/docs/docs/integrations/document_loaders/docugami.ipynb index ad8cd6fa6fec1..ee36e8f2a59bd 100644 --- a/docs/docs/integrations/document_loaders/docugami.ipynb +++ b/docs/docs/integrations/document_loaders/docugami.ipynb @@ -472,7 +472,7 @@ "from typing import Dict, List\n", "\n", "from langchain.document_loaders import DocugamiLoader\n", - "from langchain.schema.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "loader = DocugamiLoader(docset_id=\"zo954yqy53wp\")\n", "loader.include_xml_tags = (\n", diff --git a/docs/docs/integrations/document_transformers/nuclia_transformer.ipynb b/docs/docs/integrations/document_transformers/nuclia_transformer.ipynb index a497813e1bdaa..3ca7ccef310ec 100644 --- a/docs/docs/integrations/document_transformers/nuclia_transformer.ipynb +++ b/docs/docs/integrations/document_transformers/nuclia_transformer.ipynb @@ -74,7 +74,7 @@ "import asyncio\n", "\n", "from langchain.document_transformers.nuclia_text_transform import NucliaTextTransformer\n", - "from langchain.schema.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "\n", "async def process():\n", diff --git a/docs/docs/integrations/llms/databricks.ipynb b/docs/docs/integrations/llms/databricks.ipynb index 4e4a5fd18f0a5..4c4ba91fc5e3e 100644 --- a/docs/docs/integrations/llms/databricks.ipynb +++ b/docs/docs/integrations/llms/databricks.ipynb @@ -80,7 +80,7 @@ ], "source": [ "from langchain.chat_models import ChatDatabricks\n", - "from langchain.schema.messages import HumanMessage\n", + "from langchain_core.messages import HumanMessage\n", "from mlflow.deployments import get_deploy_client\n", "\n", "client = get_deploy_client(\"databricks\")\n", diff --git a/docs/docs/integrations/llms/opaqueprompts.ipynb b/docs/docs/integrations/llms/opaqueprompts.ipynb index 4df00fee77e96..7af61e5ab7fc3 100644 --- a/docs/docs/integrations/llms/opaqueprompts.ipynb +++ b/docs/docs/integrations/llms/opaqueprompts.ipynb @@ -174,8 +174,8 @@ "outputs": [], "source": [ "import langchain.utilities.opaqueprompts as op\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "prompt = (PromptTemplate.from_template(prompt_template),)\n", "llm = OpenAI()\n", diff --git a/docs/docs/integrations/llms/volcengine_maas.ipynb b/docs/docs/integrations/llms/volcengine_maas.ipynb index c34cde60c0bc3..c78d8d82cff97 100644 --- a/docs/docs/integrations/llms/volcengine_maas.ipynb +++ b/docs/docs/integrations/llms/volcengine_maas.ipynb @@ -40,7 +40,7 @@ "source": [ "from langchain.llms import VolcEngineMaasLLM\n", "from langchain.prompts import PromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser" + "from langchain_core.output_parsers import StrOutputParser" ] }, { diff --git a/docs/docs/integrations/providers/databricks.md b/docs/docs/integrations/providers/databricks.md index 7c8aa4c8fa64e..d3db485ae0134 100644 --- a/docs/docs/integrations/providers/databricks.md +++ b/docs/docs/integrations/providers/databricks.md @@ -31,7 +31,7 @@ Databricks External Models ```python from langchain.chat_models import ChatDatabricks -from langchain.schema.messages import HumanMessage +from langchain_core.messages import HumanMessage from mlflow.deployments import get_deploy_client diff --git a/docs/docs/integrations/retrievers/cohere.ipynb b/docs/docs/integrations/retrievers/cohere.ipynb index f8be6ceb0fff5..3562bb6b7afe0 100644 --- a/docs/docs/integrations/retrievers/cohere.ipynb +++ b/docs/docs/integrations/retrievers/cohere.ipynb @@ -21,7 +21,7 @@ "source": [ "from langchain.chat_models import ChatCohere\n", "from langchain.retrievers import CohereRagRetriever\n", - "from langchain.schema.document import Document" + "from langchain_core.documents import Document" ] }, { diff --git a/docs/docs/integrations/retrievers/fleet_context.ipynb b/docs/docs/integrations/retrievers/fleet_context.ipynb index a01e44318f13f..d5e97c04e71fe 100644 --- a/docs/docs/integrations/retrievers/fleet_context.ipynb +++ b/docs/docs/integrations/retrievers/fleet_context.ipynb @@ -192,7 +192,7 @@ "data": { "text/plain": [ "[Document(page_content='Vector store-backed retriever | πŸ¦œοΈπŸ”— Langchain\\n# Vector store-backed retriever A vector store retriever is a retriever that uses a vector store to retrieve documents. It is a lightweight wrapper around the vector store class to make it conform to the retriever interface. It uses the search methods implemented by a vector store, like similarity search and MMR, to query the texts in the vector store. Once you construct a vector store, it\\'s very easy to construct a retriever. Let\\'s walk through an example.Once you construct a vector store, it\\'s very easy to construct a retriever. Let\\'s walk through an example. ``` from langchain.document_loaders import TextLoaderloader = TextLoader(\\'../../../state_of_the_union.txt\\') ``` ``` from langchain.text_splitter import CharacterTextSplitterfrom langchain.vectorstores import FAISSfrom langchain.embeddings import OpenAIEmbeddingsdocuments = loader.load()text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)texts = text_splitter.split_documents(documents)embeddings = OpenAIEmbeddings()db = FAISS.from_documents(texts, embeddings) ``` ``` Exiting: Cleaning up .chroma directory ``` ``` retriever = db.as_retriever() ``` ``` docs = retriever.get_relevant_documents(\"what did he say about ketanji brown jackson\") ``` ## Maximum marginal relevance retrieval[\\u200b](#maximum-marginal-relevance-retrieval) By default, the vector store retriever uses similarity search.If the underlying vector store supports maximum marginal relevance search, you can specify that as the search type. ``` retriever = db.as_retriever(search_type=\"mmr\") ``` ``` docs = retriever.get_relevant_documents(\"what did he say about ketanji brown jackson\") ``` ## Similarity score threshold retrieval[\\u200b](#similarity-score-threshold-retrieval) You can also a retrieval method that sets a similarity score threshold and only returns documents with a score above that threshold. ``` retriever = db.as_retriever(search_type=\"similarity_score_threshold\", search_kwargs={\"score_threshold\": .5}) ``` ``` docs = retriever.get_relevant_documents(\"what did he say about ketanji brown jackson\") ``` ## Specifying top k[\\u200b](#specifying-top-k) You can also specify search kwargs like `k` to use when doing retrieval.``` retriever = db.as_retriever(search_kwargs={\"k\": 1}) ``` ``` docs = retriever.get_relevant_documents(\"what did he say about ketanji brown jackson\") ``` ``` len(docs) ``` ``` 1 ```', metadata={'title': 'Vector store-backed retriever | πŸ¦œοΈπŸ”— Langchain', 'type': None, 'url': 'https://python.langchain.com/docs/modules/data_connection/retrievers/vectorstore', 'id': 'c153ebd9-2611-4a43-9db6-daa1f5f214f6'}),\n", - " Document(page_content='MultiVector Retriever | πŸ¦œοΈπŸ”— Langchain\\n# MultiVector Retriever It can often be beneficial to store multiple vectors per document. There are multiple use cases where this is beneficial. LangChain has a base `MultiVectorRetriever` which makes querying this type of setup easy. A lot of the complexity lies in how to create the multiple vectors per document. This notebook covers some of the common ways to create those vectors and use the `MultiVectorRetriever`. The methods to create multiple vectors per document include: - Smaller chunks: split a document into smaller chunks, and embed those (this is ParentDocumentRetriever). - Summary: create a summary for each document, embed that along with (or instead of) the document. - Hypothetical questions: create hypothetical questions that each document would be appropriate to answer, embed those along with (or instead of) the document. Note that this also enables another method of adding embeddings - manually.Note that this also enables another method of adding embeddings - manually. This is great because you can explicitly add questions or queries that should lead to a document being recovered, giving you more control. ``` from langchain.retrievers.multi_vector import MultiVectorRetriever ``` ``` from langchain.vectorstores import Chromafrom langchain.embeddings import OpenAIEmbeddingsfrom langchain.text_splitter import RecursiveCharacterTextSplitterfrom langchain.storage import InMemoryStorefrom langchain.document_loaders import TextLoader ``` ``` loaders = [ TextLoader(\\'../../paul_graham_essay.txt\\'), TextLoader(\\'../../state_of_the_union.txt\\'),]docs = []for l in loaders: docs.extend(l.load())text_splitter = RecursiveCharacterTextSplitter(chunk_size=10000)docs = text_splitter.split_documents(docs) ``` ## Smaller chunks[\\u200b](#smaller-chunks) Often times it can be useful to retrieve larger chunks of information, but embed smaller chunks.This allows for embeddings to capture the semantic meaning as closely as possible, but for as much context as possible to be passed downstream. Note that this is what the `ParentDocumentRetriever` does. Here we show what is going on under the hood.``` # The vectorstore to use to index the child chunksvectorstore = Chroma( collection_name=\"full_documents\", embedding_function=OpenAIEmbeddings())# The storage layer for the parent documentsstore = InMemoryStore()id_key = \"doc_id\"# The retriever (empty to start)retriever = MultiVectorRetriever( vectorstore=vectorstore, docstore=store, id_key=id_key,)import uuiddoc_ids = [str(uuid.uuid4()) for _ in docs] ``` ``` # The splitter to use to create smaller chunkschild_text_splitter = RecursiveCharacterTextSplitter(chunk_size=400) ``` ``` sub_docs = []for i, doc in enumerate(docs): _id = doc_ids[i] _sub_docs = child_text_splitter.split_documents([doc]) for _doc in _sub_docs: _doc.metadata[id_key] = _id sub_docs.extend(_sub_docs) ``` ``` retriever.vectorstore.add_documents(sub_docs)retriever.docstore.mset(list(zip(doc_ids, docs))) ``` ``` # Vectorstore alone retrieves the small chunksretriever.vectorstore.similarity_search(\"justice breyer\")[0] ``` ``` Document(page_content=\\'Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyerβ€”an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court.Justice Breyer, thank you for your service. \\\\n\\\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\', metadata={\\'doc_id\\': \\'10e9cbc0-4ba5-4d79-a09b-c033d1ba7b01\\', \\'source\\': \\'../../state_of_the_union.txt\\'}) ``` ``` # Retriever returns larger chunkslen(retriever.get_relevant_documents(\"justice breyer\")[0].page_content) ``` ``` 9874 ``` ## Summary[\\u200b](#summary) Oftentimes a summary may be able to distill more accurately what a chunk is about, leading to better retrieval. Here we show how to create summaries, and then embed those.``` from langchain.chat_models import ChatOpenAIfrom langchain.prompts import ChatPromptTemplatefrom langchain.schema.output_parser import StrOutputParserimport uuidfrom langchain.schema.document import Document ``` ``` chain = ( {\"doc\": lambda x: x.page_content} | ChatPromptTemplate.from_template(\"Summarize the following document:\\\\n\\\\n{doc}\") | ChatOpenAI(max_retries=0) | StrOutputParser()) ``` ``` summaries = chain.batch(docs, {\"max_concurrency\": 5}) ``` ``` # The vectorstore to use to index the child chunksvectorstore = Chroma( collection_name=\"summaries\", embedding_function=OpenAIEmbeddings())# The storage layer for the parent documentsstore = InMemoryStore()id_key = \"doc_id\"# The retriever (empty to start)retriever = MultiVectorRetriever( vectorstore=vectorstore, docstore=store, id_key=id_key,)doc_ids = [str(uuid.uuid4()) for _ in docs] ``` ``` summary_docs = [Document(page_content=s,metadata={id_key: doc_ids[i]}) for i, s in enumerate(summaries)] ``` ``` retriever.vectorstore.add_documents(summary_docs)retriever.docstore.mset(list(zip(doc_ids, docs))) ``` ``` # # We can also add the original chunks to the vectorstore if we so want# for i, doc in enumerate(docs):# doc.metadata[id_key] = doc_ids[i]# retriever.vectorstore.add_documents(docs) ``` ``` sub_docs = vectorstore.similarity_search(\"justice breyer\") ``` ``` sub_docs[0] ``` ``` Document(page_content=\"The document is a transcript of a speech given by the President of the United States.The President discusses several important issues and initiatives, including the nomination of a Supreme Court Justice, border security and immigration reform, protecting women\\'s rights, advancing LGBTQ+ equality, bipartisan legislation, addressing the opioid epidemic and mental health, supporting veterans, investigating the health effects of burn pits on military personnel, ending cancer, and the strength and resilience of the American people. \", metadata={\\'doc_id\\': \\'79fa2e9f-28d9-4372-8af3-2caf4f1de312\\'}) ``` ``` retrieved_docs = retriever.get_relevant_documents(\"justice breyer\") ``` ``` len(retrieved_docs[0].page_content) ``` ``` 9194 ``` ## Hypothetical Queries[\\u200b](#hypothetical-queries) An LLM can also be used to generate a list of hypothetical questions that could be asked of a particular document.These questions can then be embedded ``` functions = [ { \"name\": \"hypothetical_questions\", \"description\": \"Generate hypothetical questions\", \"parameters\": { \"type\": \"object\", \"properties\": { \"questions\": { \"type\": \"array\", \"items\": { \"type\": \"string\" }, }, }, \"required\": [\"questions\"] } } ] ``` ``` from langchain.output_parsers.openai_functions import JsonKeyOutputFunctionsParserchain = ( {\"doc\": lambda x: x.page_content} # Only asking for 3 hypothetical questions, but this could be adjusted | ChatPromptTemplate.from_template(\"Generate a list of 3 hypothetical questions that the below document could be used to answer:\\\\n\\\\n{doc}\") | ChatOpenAI(max_retries=0, model=\"gpt-4\").bind(functions=functions, function_call={\"name\": \"hypothetical_questions\"}) | JsonKeyOutputFunctionsParser(key_name=\"questions\")) ``` ``` chain.invoke(docs[0]) ``` ``` [\"What was the author\\'s initial impression of philosophy as a field of study, and how did it change when they got to college?\", \\'Why did the author decide to switch their focus to Artificial Intelligence (AI)? \\', \"What led to the author\\'s disillusionment with the field of AI as it was practiced at the time?\"]``` ``` hypothetical_questions = chain.batch(docs, {\"max_concurrency\": 5}) ``` ``` # The vectorstore to use to index the child chunksvectorstore = Chroma( collection_name=\"hypo-questions\", embedding_function=OpenAIEmbeddings())# The storage layer for the parent documentsstore = InMemoryStore()id_key = \"doc_id\"# The retriever (empty to start)retriever = MultiVectorRetriever( vectorstore=vectorstore, docstore=store, id_key=id_key,)doc_ids = [str(uuid.uuid4()) for _ in docs] ``` ``` question_docs = []for i, question_list in enumerate(hypothetical_questions): question_docs.extend([Document(page_content=s,metadata={id_key: doc_ids[i]}) for s in question_list]) ``` ``` retriever.vectorstore.add_documents(question_docs)retriever.docstore.mset(list(zip(doc_ids, docs))) ``` ``` sub_docs = vectorstore.similarity_search(\"justice breyer\") ``` ``` sub_docs ``` ``` [Document(page_content=\"What is the President\\'s stance on immigration reform?\", metadata={\\'doc_id\\': \\'505d73e3-8350-46ec-a58e-3af032f04ab3\\'}), Document(page_content=\"What is the President\\'s stance on immigration reform? \", metadata={\\'doc_id\\': \\'1c9618f0-7660-4b4f-a37c-509cbbbf6dba\\'}), Document(page_content=\"What is the President\\'s stance on immigration reform? \", metadata={\\'doc_id\\': \\'82c08209-b904-46a8-9532-edd2380950b7\\'}), Document(page_content=\\'What measures is the President proposing to protect the rights of LGBTQ+ Americans? \\', metadata={\\'doc_id\\': \\'82c08209-b904-46a8-9532-edd2380950b7\\'})] ``` ``` retrieved_docs = retriever.get_relevant_documents(\"justice breyer\") ``` ``` len(retrieved_docs[0].page_content) ``` ``` 9194 ```', metadata={'title': 'MultiVector Retriever | πŸ¦œοΈπŸ”— Langchain', 'type': None, 'url': 'https://python.langchain.com/docs/modules/data_connection/retrievers/multi_vector', 'id': 'beec5531-16a7-453c-80ab-c5628e0236ce'}),\n", + " Document(page_content='MultiVector Retriever | πŸ¦œοΈπŸ”— Langchain\\n# MultiVector Retriever It can often be beneficial to store multiple vectors per document. There are multiple use cases where this is beneficial. LangChain has a base `MultiVectorRetriever` which makes querying this type of setup easy. A lot of the complexity lies in how to create the multiple vectors per document. This notebook covers some of the common ways to create those vectors and use the `MultiVectorRetriever`. The methods to create multiple vectors per document include: - Smaller chunks: split a document into smaller chunks, and embed those (this is ParentDocumentRetriever). - Summary: create a summary for each document, embed that along with (or instead of) the document. - Hypothetical questions: create hypothetical questions that each document would be appropriate to answer, embed those along with (or instead of) the document. Note that this also enables another method of adding embeddings - manually.Note that this also enables another method of adding embeddings - manually. This is great because you can explicitly add questions or queries that should lead to a document being recovered, giving you more control. ``` from langchain.retrievers.multi_vector import MultiVectorRetriever ``` ``` from langchain.vectorstores import Chromafrom langchain.embeddings import OpenAIEmbeddingsfrom langchain.text_splitter import RecursiveCharacterTextSplitterfrom langchain.storage import InMemoryStorefrom langchain.document_loaders import TextLoader ``` ``` loaders = [ TextLoader(\\'../../paul_graham_essay.txt\\'), TextLoader(\\'../../state_of_the_union.txt\\'),]docs = []for l in loaders: docs.extend(l.load())text_splitter = RecursiveCharacterTextSplitter(chunk_size=10000)docs = text_splitter.split_documents(docs) ``` ## Smaller chunks[\\u200b](#smaller-chunks) Often times it can be useful to retrieve larger chunks of information, but embed smaller chunks.This allows for embeddings to capture the semantic meaning as closely as possible, but for as much context as possible to be passed downstream. Note that this is what the `ParentDocumentRetriever` does. Here we show what is going on under the hood.``` # The vectorstore to use to index the child chunksvectorstore = Chroma( collection_name=\"full_documents\", embedding_function=OpenAIEmbeddings())# The storage layer for the parent documentsstore = InMemoryStore()id_key = \"doc_id\"# The retriever (empty to start)retriever = MultiVectorRetriever( vectorstore=vectorstore, docstore=store, id_key=id_key,)import uuiddoc_ids = [str(uuid.uuid4()) for _ in docs] ``` ``` # The splitter to use to create smaller chunkschild_text_splitter = RecursiveCharacterTextSplitter(chunk_size=400) ``` ``` sub_docs = []for i, doc in enumerate(docs): _id = doc_ids[i] _sub_docs = child_text_splitter.split_documents([doc]) for _doc in _sub_docs: _doc.metadata[id_key] = _id sub_docs.extend(_sub_docs) ``` ``` retriever.vectorstore.add_documents(sub_docs)retriever.docstore.mset(list(zip(doc_ids, docs))) ``` ``` # Vectorstore alone retrieves the small chunksretriever.vectorstore.similarity_search(\"justice breyer\")[0] ``` ``` Document(page_content=\\'Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyerβ€”an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court.Justice Breyer, thank you for your service. \\\\n\\\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\', metadata={\\'doc_id\\': \\'10e9cbc0-4ba5-4d79-a09b-c033d1ba7b01\\', \\'source\\': \\'../../state_of_the_union.txt\\'}) ``` ``` # Retriever returns larger chunkslen(retriever.get_relevant_documents(\"justice breyer\")[0].page_content) ``` ``` 9874 ``` ## Summary[\\u200b](#summary) Oftentimes a summary may be able to distill more accurately what a chunk is about, leading to better retrieval. Here we show how to create summaries, and then embed those.``` from langchain.chat_models import ChatOpenAIfrom langchain.prompts import ChatPromptTemplatefrom langchain_core.output_parsers import StrOutputParserimport uuidfrom langchain_core.documents import Document ``` ``` chain = ( {\"doc\": lambda x: x.page_content} | ChatPromptTemplate.from_template(\"Summarize the following document:\\\\n\\\\n{doc}\") | ChatOpenAI(max_retries=0) | StrOutputParser()) ``` ``` summaries = chain.batch(docs, {\"max_concurrency\": 5}) ``` ``` # The vectorstore to use to index the child chunksvectorstore = Chroma( collection_name=\"summaries\", embedding_function=OpenAIEmbeddings())# The storage layer for the parent documentsstore = InMemoryStore()id_key = \"doc_id\"# The retriever (empty to start)retriever = MultiVectorRetriever( vectorstore=vectorstore, docstore=store, id_key=id_key,)doc_ids = [str(uuid.uuid4()) for _ in docs] ``` ``` summary_docs = [Document(page_content=s,metadata={id_key: doc_ids[i]}) for i, s in enumerate(summaries)] ``` ``` retriever.vectorstore.add_documents(summary_docs)retriever.docstore.mset(list(zip(doc_ids, docs))) ``` ``` # # We can also add the original chunks to the vectorstore if we so want# for i, doc in enumerate(docs):# doc.metadata[id_key] = doc_ids[i]# retriever.vectorstore.add_documents(docs) ``` ``` sub_docs = vectorstore.similarity_search(\"justice breyer\") ``` ``` sub_docs[0] ``` ``` Document(page_content=\"The document is a transcript of a speech given by the President of the United States.The President discusses several important issues and initiatives, including the nomination of a Supreme Court Justice, border security and immigration reform, protecting women\\'s rights, advancing LGBTQ+ equality, bipartisan legislation, addressing the opioid epidemic and mental health, supporting veterans, investigating the health effects of burn pits on military personnel, ending cancer, and the strength and resilience of the American people. \", metadata={\\'doc_id\\': \\'79fa2e9f-28d9-4372-8af3-2caf4f1de312\\'}) ``` ``` retrieved_docs = retriever.get_relevant_documents(\"justice breyer\") ``` ``` len(retrieved_docs[0].page_content) ``` ``` 9194 ``` ## Hypothetical Queries[\\u200b](#hypothetical-queries) An LLM can also be used to generate a list of hypothetical questions that could be asked of a particular document.These questions can then be embedded ``` functions = [ { \"name\": \"hypothetical_questions\", \"description\": \"Generate hypothetical questions\", \"parameters\": { \"type\": \"object\", \"properties\": { \"questions\": { \"type\": \"array\", \"items\": { \"type\": \"string\" }, }, }, \"required\": [\"questions\"] } } ] ``` ``` from langchain.output_parsers.openai_functions import JsonKeyOutputFunctionsParserchain = ( {\"doc\": lambda x: x.page_content} # Only asking for 3 hypothetical questions, but this could be adjusted | ChatPromptTemplate.from_template(\"Generate a list of 3 hypothetical questions that the below document could be used to answer:\\\\n\\\\n{doc}\") | ChatOpenAI(max_retries=0, model=\"gpt-4\").bind(functions=functions, function_call={\"name\": \"hypothetical_questions\"}) | JsonKeyOutputFunctionsParser(key_name=\"questions\")) ``` ``` chain.invoke(docs[0]) ``` ``` [\"What was the author\\'s initial impression of philosophy as a field of study, and how did it change when they got to college?\", \\'Why did the author decide to switch their focus to Artificial Intelligence (AI)? \\', \"What led to the author\\'s disillusionment with the field of AI as it was practiced at the time?\"]``` ``` hypothetical_questions = chain.batch(docs, {\"max_concurrency\": 5}) ``` ``` # The vectorstore to use to index the child chunksvectorstore = Chroma( collection_name=\"hypo-questions\", embedding_function=OpenAIEmbeddings())# The storage layer for the parent documentsstore = InMemoryStore()id_key = \"doc_id\"# The retriever (empty to start)retriever = MultiVectorRetriever( vectorstore=vectorstore, docstore=store, id_key=id_key,)doc_ids = [str(uuid.uuid4()) for _ in docs] ``` ``` question_docs = []for i, question_list in enumerate(hypothetical_questions): question_docs.extend([Document(page_content=s,metadata={id_key: doc_ids[i]}) for s in question_list]) ``` ``` retriever.vectorstore.add_documents(question_docs)retriever.docstore.mset(list(zip(doc_ids, docs))) ``` ``` sub_docs = vectorstore.similarity_search(\"justice breyer\") ``` ``` sub_docs ``` ``` [Document(page_content=\"What is the President\\'s stance on immigration reform?\", metadata={\\'doc_id\\': \\'505d73e3-8350-46ec-a58e-3af032f04ab3\\'}), Document(page_content=\"What is the President\\'s stance on immigration reform? \", metadata={\\'doc_id\\': \\'1c9618f0-7660-4b4f-a37c-509cbbbf6dba\\'}), Document(page_content=\"What is the President\\'s stance on immigration reform? \", metadata={\\'doc_id\\': \\'82c08209-b904-46a8-9532-edd2380950b7\\'}), Document(page_content=\\'What measures is the President proposing to protect the rights of LGBTQ+ Americans? \\', metadata={\\'doc_id\\': \\'82c08209-b904-46a8-9532-edd2380950b7\\'})] ``` ``` retrieved_docs = retriever.get_relevant_documents(\"justice breyer\") ``` ``` len(retrieved_docs[0].page_content) ``` ``` 9194 ```', metadata={'title': 'MultiVector Retriever | πŸ¦œοΈπŸ”— Langchain', 'type': None, 'url': 'https://python.langchain.com/docs/modules/data_connection/retrievers/multi_vector', 'id': 'beec5531-16a7-453c-80ab-c5628e0236ce'}),\n", " Document(page_content='MultiQueryRetriever | πŸ¦œοΈπŸ”— Langchain\\n# MultiQueryRetriever Distance-based vector database retrieval embeds (represents) queries in high-dimensional space and finds similar embedded documents based on \"distance\". But, retrieval may produce different results with subtle changes in query wording or if the embeddings do not capture the semantics of the data well. Prompt engineering / tuning is sometimes done to manually address these problems, but can be tedious. The `MultiQueryRetriever` automates the process of prompt tuning by using an LLM to generate multiple queries from different perspectives for a given user input query. For each query, it retrieves a set of relevant documents and takes the unique union across all queries to get a larger set of potentially relevant documents. By generating multiple perspectives on the same question, the `MultiQueryRetriever` might be able to overcome some of the limitations of the distance-based retrieval and get a richer set of results.By generating multiple perspectives on the same question, the `MultiQueryRetriever` might be able to overcome some of the limitations of the distance-based retrieval and get a richer set of results. ``` # Build a sample vectorDBfrom langchain.vectorstores import Chromafrom langchain.document_loaders import WebBaseLoaderfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.text_splitter import RecursiveCharacterTextSplitter# Load blog postloader = WebBaseLoader(\"https://lilianweng.github.io/posts/2023-06-23-agent/\")data = loader.load()# Splittext_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=0)splits = text_splitter.split_documents(data)# VectorDBembedding = OpenAIEmbeddings()vectordb = Chroma.from_documents(documents=splits, embedding=embedding) ``` #### Simple usage[\\u200b](#simple-usage) Specify the LLM to use for query generation, and the retriever will do the rest.``` from langchain.chat_models import ChatOpenAIfrom langchain.retrievers.multi_query import MultiQueryRetrieverquestion = \"What are the approaches to Task Decomposition? \"llm = ChatOpenAI(temperature=0)retriever_from_llm = MultiQueryRetriever.from_llm( retriever=vectordb.as_retriever(), llm=llm) ``` ``` # Set logging for the queriesimport logginglogging.basicConfig()logging.getLogger(\"langchain.retrievers.multi_query\").setLevel(logging.INFO) ``` ``` unique_docs = retriever_from_llm.get_relevant_documents(query=question)len(unique_docs) ``` ``` INFO:langchain.retrievers.multi_query:Generated queries: [\\'1. How can Task Decomposition be approached? \\', \\'2. What are the different methods for Task Decomposition? \\', \\'3. What are the various approaches to decomposing tasks?\\'] 5 ``` #### Supplying your own prompt[\\u200b](#supplying-your-own-prompt) You can also supply a prompt along with an output parser to split the results into a list of queries.5 ``` #### Supplying your own prompt[\\u200b](#supplying-your-own-prompt) You can also supply a prompt along with an output parser to split the results into a list of queries. ``` from typing import Listfrom langchain.chains import LLMChainfrom pydantic import BaseModel, Fieldfrom langchain.prompts import PromptTemplatefrom langchain.output_parsers import PydanticOutputParser# Output parser will split the LLM result into a list of queriesclass LineList(BaseModel): # \"lines\" is the key (attribute name) of the parsed output lines: List[str] = Field(description=\"Lines of text\")class LineListOutputParser(PydanticOutputParser): def __init__(self) -> None: super().__init__(pydantic_object=LineList) def parse(self, text: str) -> LineList: lines = text.strip().split(\"\\\\n\") return LineList(lines=lines)output_parser = LineListOutputParser()QUERY_PROMPT = PromptTemplate( input_variables=[\"question\"], template=\"\"\"You are an AI language model assistant.Your task is to generate five different versions of the given user question to retrieve relevant documents from a vector database. By generating multiple perspectives on the user question, your goal is to help the user overcome some of the limitations of the distance-based similarity search. Provide these alternative questions separated by newlines. Original question: {question}\"\"\",)llm = ChatOpenAI(temperature=0)# Chainllm_chain = LLMChain(llm=llm, prompt=QUERY_PROMPT, output_parser=output_parser)# Other inputsquestion = \"What are the approaches to Task Decomposition?\" ``` ``` # Runretriever = MultiQueryRetriever( retriever=vectordb.as_retriever(), llm_chain=llm_chain, parser_key=\"lines\") # \"lines\" is the key (attribute name) of the parsed output# Resultsunique_docs = retriever.get_relevant_documents( query=\"What does the course say about regression? \")len(unique_docs) ``` ``` INFO:langchain.retrievers.multi_query:Generated queries: [\"1.\")len(unique_docs) ``` ``` INFO:langchain.retrievers.multi_query:Generated queries: [\"1. What is the course\\'s perspective on regression? \", \\'2. Can you provide information on regression as discussed in the course? \\', \\'3. How does the course cover the topic of regression? \\', \"4. What are the course\\'s teachings on regression? \", \\'5. In relation to the course, what is mentioned about regression?\\'] 11 ```', metadata={'title': 'MultiQueryRetriever | πŸ¦œοΈπŸ”— Langchain', 'type': None, 'url': 'https://python.langchain.com/docs/modules/data_connection/retrievers/MultiQueryRetriever', 'id': 'f7c20633-6a60-4ca3-96b1-13fee66e321d'}),\n", " Document(page_content='langchain.retrievers.multi_vector.MultiVectorRetriever β€” πŸ¦œπŸ”— LangChain 0.0.322\\n# `langchain.retrievers.multi_vector`.MultiVectorRetriever[ΒΆ](#langchain-retrievers-multi-vector-multivectorretriever) *class *langchain.retrievers.multi_vector.MultiVectorRetriever[[source]](../_modules/langchain/retrievers/multi_vector.html#MultiVectorRetriever)[ΒΆ](#langchain.retrievers.multi_vector.MultiVectorRetriever) # Examples using MultiVectorRetriever[ΒΆ](#langchain-retrievers-multi-vector-multivectorretriever) - [MultiVector Retriever](https://python.langchain.com/docs/modules/data_connection/retrievers/multi_vector)', metadata={'title': 'langchain.retrievers.multi_vector.MultiVectorRetriever β€” πŸ¦œπŸ”— LangChain 0.0.322', 'type': None, 'url': 'https://api.python.langchain.com/en/latest/retrievers/langchain.retrievers.multi_vector.MultiVectorRetriever.html#langchain-retrievers-multi-vector-multivectorretriever', 'id': '1820c44d-7783-4846-a11c-106b18da015d'})]" ] @@ -226,7 +226,7 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", "from langchain.schema import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "prompt = ChatPromptTemplate.from_messages(\n", " [\n", diff --git a/docs/docs/integrations/vectorstores/astradb.ipynb b/docs/docs/integrations/vectorstores/astradb.ipynb index 4518265a9fc9e..06a99ffd3e72f 100644 --- a/docs/docs/integrations/vectorstores/astradb.ipynb +++ b/docs/docs/integrations/vectorstores/astradb.ipynb @@ -65,9 +65,9 @@ "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.prompts import ChatPromptTemplate\n", "from langchain.schema import Document\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", - "from langchain.text_splitter import RecursiveCharacterTextSplitter" + "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough" ] }, { diff --git a/docs/docs/integrations/vectorstores/weaviate.ipynb b/docs/docs/integrations/vectorstores/weaviate.ipynb index 6f1a7b3fad0cd..27cc2942e29ad 100644 --- a/docs/docs/integrations/vectorstores/weaviate.ipynb +++ b/docs/docs/integrations/vectorstores/weaviate.ipynb @@ -563,8 +563,8 @@ } ], "source": [ - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "rag_chain = (\n", " {\"context\": retriever, \"question\": RunnablePassthrough()}\n", diff --git a/docs/docs/modules/agents/agent_types/openai_assistants.ipynb b/docs/docs/modules/agents/agent_types/openai_assistants.ipynb index 0fb83ff6b02cd..763623b1618bc 100644 --- a/docs/docs/modules/agents/agent_types/openai_assistants.ipynb +++ b/docs/docs/modules/agents/agent_types/openai_assistants.ipynb @@ -193,7 +193,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.agent import AgentFinish\n", + "from langchain_core.agents import AgentFinish\n", "\n", "\n", "def execute_agent(agent, tools, input):\n", diff --git a/docs/docs/modules/agents/how_to/agent_iter.ipynb b/docs/docs/modules/agents/how_to/agent_iter.ipynb index 29f6337946357..5ed70f1c65a3d 100644 --- a/docs/docs/modules/agents/how_to/agent_iter.ipynb +++ b/docs/docs/modules/agents/how_to/agent_iter.ipynb @@ -23,9 +23,9 @@ "outputs": [], "source": [ "from langchain.agents import AgentType, initialize_agent\n", - "from langchain.agents.tools import Tool\n", "from langchain.chains import LLMMathChain\n", "from langchain.chat_models import ChatOpenAI\n", + "from langchain_core.tools import Tool\n", "from pydantic.v1 import BaseModel, Field" ] }, diff --git a/docs/docs/modules/agents/how_to/agent_structured.ipynb b/docs/docs/modules/agents/how_to/agent_structured.ipynb index 9f1f5262dea5c..2f1c8e38ae40d 100644 --- a/docs/docs/modules/agents/how_to/agent_structured.ipynb +++ b/docs/docs/modules/agents/how_to/agent_structured.ipynb @@ -166,7 +166,7 @@ "source": [ "import json\n", "\n", - "from langchain.schema.agent import AgentActionMessageLog, AgentFinish" + "from langchain_core.agents import AgentActionMessageLog, AgentFinish" ] }, { diff --git a/docs/docs/modules/agents/index.ipynb b/docs/docs/modules/agents/index.ipynb index 78a12b07ba8e4..480d93baeab3b 100644 --- a/docs/docs/modules/agents/index.ipynb +++ b/docs/docs/modules/agents/index.ipynb @@ -357,7 +357,7 @@ } ], "source": [ - "from langchain.schema.agent import AgentFinish\n", + "from langchain_core.agents import AgentFinish\n", "\n", "user_input = \"how many letters in the word educa?\"\n", "intermediate_steps = []\n", @@ -519,7 +519,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.messages import AIMessage, HumanMessage\n", + "from langchain_core.messages import AIMessage, HumanMessage\n", "\n", "chat_history = []" ] diff --git a/docs/docs/modules/agents/tools/custom_tools.ipynb b/docs/docs/modules/agents/tools/custom_tools.ipynb index 96c00295f3e4d..c2338ec0af680 100644 --- a/docs/docs/modules/agents/tools/custom_tools.ipynb +++ b/docs/docs/modules/agents/tools/custom_tools.ipynb @@ -938,8 +938,8 @@ "from langchain.agents import AgentType, initialize_agent\n", "from langchain.chat_models import ChatOpenAI\n", "from langchain.tools import Tool\n", - "from langchain.tools.base import ToolException\n", "from langchain.utilities import SerpAPIWrapper\n", + "from langchain_core.tools import ToolException\n", "\n", "\n", "def _handle_error(error: ToolException) -> str:\n", diff --git a/docs/docs/modules/chains/document/map_reduce.ipynb b/docs/docs/modules/chains/document/map_reduce.ipynb index 126ce5c8fa847..eb909f14195b0 100644 --- a/docs/docs/modules/chains/document/map_reduce.ipynb +++ b/docs/docs/modules/chains/document/map_reduce.ipynb @@ -35,8 +35,8 @@ "from langchain.chat_models import ChatAnthropic\n", "from langchain.prompts import PromptTemplate\n", "from langchain.schema import StrOutputParser\n", - "from langchain.schema.prompt_template import format_document\n", - "from langchain.schema.runnable import RunnableParallel, RunnablePassthrough" + "from langchain_core.prompts import format_document\n", + "from langchain_core.runnables import RunnableParallel, RunnablePassthrough" ] }, { diff --git a/docs/docs/modules/chains/document/map_rerank.ipynb b/docs/docs/modules/chains/document/map_rerank.ipynb index ab2277913784d..8d3aac7003c5b 100644 --- a/docs/docs/modules/chains/document/map_rerank.ipynb +++ b/docs/docs/modules/chains/document/map_rerank.ipynb @@ -32,9 +32,9 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.output_parsers.openai_functions import PydanticOutputFunctionsParser\n", "from langchain.prompts import PromptTemplate\n", - "from langchain.pydantic_v1 import BaseModel, Field\n", - "from langchain.schema.prompt_template import format_document\n", - "from langchain.utils.openai_functions import convert_pydantic_to_openai_function" + "from langchain.utils.openai_functions import convert_pydantic_to_openai_function\n", + "from langchain_core.prompts import format_document\n", + "from langchain_core.pydantic_v1 import BaseModel, Field" ] }, { diff --git a/docs/docs/modules/chains/document/refine.ipynb b/docs/docs/modules/chains/document/refine.ipynb index d84724def4df3..b011cdf6d2a31 100644 --- a/docs/docs/modules/chains/document/refine.ipynb +++ b/docs/docs/modules/chains/document/refine.ipynb @@ -51,7 +51,7 @@ "from langchain.chat_models import ChatAnthropic\n", "from langchain.prompts import PromptTemplate\n", "from langchain.schema import StrOutputParser\n", - "from langchain.schema.prompt_template import format_document" + "from langchain_core.prompts import format_document" ] }, { diff --git a/docs/docs/modules/chains/document/stuff.ipynb b/docs/docs/modules/chains/document/stuff.ipynb index 92798440fcbc8..8ea0a8e3ceb70 100644 --- a/docs/docs/modules/chains/document/stuff.ipynb +++ b/docs/docs/modules/chains/document/stuff.ipynb @@ -43,7 +43,7 @@ "from langchain.chat_models import ChatAnthropic\n", "from langchain.prompts import PromptTemplate\n", "from langchain.schema import StrOutputParser\n", - "from langchain.schema.prompt_template import format_document" + "from langchain_core.prompts import format_document" ] }, { diff --git a/docs/docs/modules/chains/foundational/router.ipynb b/docs/docs/modules/chains/foundational/router.ipynb index 3b6028c312717..a082d2964a276 100644 --- a/docs/docs/modules/chains/foundational/router.ipynb +++ b/docs/docs/modules/chains/foundational/router.ipynb @@ -58,8 +58,8 @@ "outputs": [], "source": [ "from langchain.chat_models import ChatOpenAI\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnableBranch" + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnableBranch" ] }, { @@ -89,8 +89,8 @@ "from typing import Literal\n", "\n", "from langchain.output_parsers.openai_functions import PydanticAttrOutputFunctionsParser\n", - "from langchain.pydantic_v1 import BaseModel\n", "from langchain.utils.openai_functions import convert_pydantic_to_openai_function\n", + "from langchain_core.pydantic_v1 import BaseModel\n", "\n", "\n", "class TopicClassifier(BaseModel):\n", @@ -119,8 +119,8 @@ "source": [ "from operator import itemgetter\n", "\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "final_chain = (\n", " RunnablePassthrough.assign(topic=itemgetter(\"input\") | classifier_chain)\n", diff --git a/docs/docs/modules/chains/foundational/sequential_chains.ipynb b/docs/docs/modules/chains/foundational/sequential_chains.ipynb index 09ff7956158c4..0bcb928a032df 100644 --- a/docs/docs/modules/chains/foundational/sequential_chains.ipynb +++ b/docs/docs/modules/chains/foundational/sequential_chains.ipynb @@ -107,7 +107,7 @@ } ], "source": [ - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "synopsis_chain = synopsis_prompt | llm | StrOutputParser()\n", "review_chain = review_prompt | llm | StrOutputParser()\n", diff --git a/docs/docs/modules/chains/how_to/custom_chain.ipynb b/docs/docs/modules/chains/how_to/custom_chain.ipynb index ddf268ef77130..692b4749d9d17 100644 --- a/docs/docs/modules/chains/how_to/custom_chain.ipynb +++ b/docs/docs/modules/chains/how_to/custom_chain.ipynb @@ -29,7 +29,7 @@ ")\n", "from langchain.chains.base import Chain\n", "from langchain.prompts.base import BasePromptTemplate\n", - "from langchain.schema.language_model import BaseLanguageModel\n", + "from langchain_core.language_models import BaseLanguageModel\n", "from pydantic import Extra\n", "\n", "\n", diff --git a/docs/docs/modules/chains/how_to/openai_functions.ipynb b/docs/docs/modules/chains/how_to/openai_functions.ipynb index 223668cc167a2..f5d4a5cd9d2cd 100644 --- a/docs/docs/modules/chains/how_to/openai_functions.ipynb +++ b/docs/docs/modules/chains/how_to/openai_functions.ipynb @@ -56,7 +56,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.pydantic_v1 import BaseModel, Field\n", + "from langchain_core.pydantic_v1 import BaseModel, Field\n", "\n", "\n", "class Person(BaseModel):\n", diff --git a/docs/docs/modules/data_connection/retrievers/index.ipynb b/docs/docs/modules/data_connection/retrievers/index.ipynb index 1f407fa9cecf2..f45764778889f 100644 --- a/docs/docs/modules/data_connection/retrievers/index.ipynb +++ b/docs/docs/modules/data_connection/retrievers/index.ipynb @@ -118,7 +118,7 @@ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", "from langchain.schema import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "template = \"\"\"Answer the question based only on the following context:\n", "\n", diff --git a/docs/docs/modules/data_connection/retrievers/multi_vector.ipynb b/docs/docs/modules/data_connection/retrievers/multi_vector.ipynb index 3ddbeb2f534f8..80877c2ca8b62 100644 --- a/docs/docs/modules/data_connection/retrievers/multi_vector.ipynb +++ b/docs/docs/modules/data_connection/retrievers/multi_vector.ipynb @@ -232,8 +232,8 @@ "\n", "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.document import Document\n", - "from langchain.schema.output_parser import StrOutputParser" + "from langchain_core.documents import Document\n", + "from langchain_core.output_parsers import StrOutputParser" ] }, { diff --git a/docs/docs/modules/model_io/chat/index.ipynb b/docs/docs/modules/model_io/chat/index.ipynb index 2d0f1b617e6dc..3c0b9d9344a53 100644 --- a/docs/docs/modules/model_io/chat/index.ipynb +++ b/docs/docs/modules/model_io/chat/index.ipynb @@ -104,7 +104,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.messages import HumanMessage, SystemMessage\n", + "from langchain_core.messages import HumanMessage, SystemMessage\n", "\n", "messages = [\n", " SystemMessage(content=\"You're a helpful assistant\"),\n", diff --git a/docs/docs/modules/model_io/llms/custom_llm.ipynb b/docs/docs/modules/model_io/llms/custom_llm.ipynb index 3fa76326fb8a2..04fa4e6a89275 100644 --- a/docs/docs/modules/model_io/llms/custom_llm.ipynb +++ b/docs/docs/modules/model_io/llms/custom_llm.ipynb @@ -30,7 +30,7 @@ "from typing import Any, List, Mapping, Optional\n", "\n", "from langchain.callbacks.manager import CallbackManagerForLLMRun\n", - "from langchain.llms.base import LLM" + "from langchain_core.language_models.llms import LLM" ] }, { diff --git a/docs/docs/modules/model_io/output_parsers/index.ipynb b/docs/docs/modules/model_io/output_parsers/index.ipynb index 917ee5e758c2b..b2913c22cbbe9 100644 --- a/docs/docs/modules/model_io/output_parsers/index.ipynb +++ b/docs/docs/modules/model_io/output_parsers/index.ipynb @@ -53,7 +53,7 @@ "from langchain.llms import OpenAI\n", "from langchain.output_parsers import PydanticOutputParser\n", "from langchain.prompts import PromptTemplate\n", - "from langchain.pydantic_v1 import BaseModel, Field, validator\n", + "from langchain_core.pydantic_v1 import BaseModel, Field, validator\n", "\n", "model = OpenAI(model_name=\"text-davinci-003\", temperature=0.0)\n", "\n", diff --git a/docs/docs/modules/model_io/output_parsers/output_fixing_parser.mdx b/docs/docs/modules/model_io/output_parsers/output_fixing_parser.mdx index 83151da7dd801..dd201049817b8 100644 --- a/docs/docs/modules/model_io/output_parsers/output_fixing_parser.mdx +++ b/docs/docs/modules/model_io/output_parsers/output_fixing_parser.mdx @@ -9,7 +9,7 @@ For this example, we'll use the above Pydantic output parser. Here's what happen ```python from langchain.chat_models import ChatOpenAI from langchain.output_parsers import PydanticOutputParser -from langchain.pydantic_v1 import BaseModel, Field +from langchain_core.pydantic_v1 import BaseModel, Field from typing import List ``` diff --git a/docs/docs/modules/model_io/output_parsers/pydantic.ipynb b/docs/docs/modules/model_io/output_parsers/pydantic.ipynb index d72ed8cf23df1..7b0290f1cd0cd 100644 --- a/docs/docs/modules/model_io/output_parsers/pydantic.ipynb +++ b/docs/docs/modules/model_io/output_parsers/pydantic.ipynb @@ -25,7 +25,7 @@ "from langchain.llms import OpenAI\n", "from langchain.output_parsers import PydanticOutputParser\n", "from langchain.prompts import PromptTemplate\n", - "from langchain.pydantic_v1 import BaseModel, Field, validator" + "from langchain_core.pydantic_v1 import BaseModel, Field, validator" ] }, { diff --git a/docs/docs/modules/model_io/prompts/prompt_templates/index.ipynb b/docs/docs/modules/model_io/prompts/prompt_templates/index.ipynb index 0cb5997b7b0bb..a8b3db19a92ba 100644 --- a/docs/docs/modules/model_io/prompts/prompt_templates/index.ipynb +++ b/docs/docs/modules/model_io/prompts/prompt_templates/index.ipynb @@ -203,7 +203,7 @@ "source": [ "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import HumanMessagePromptTemplate\n", - "from langchain.schema.messages import SystemMessage\n", + "from langchain_core.messages import SystemMessage\n", "\n", "chat_template = ChatPromptTemplate.from_messages(\n", " [\n", diff --git a/docs/docs/modules/model_io/prompts/prompt_templates/msg_prompt_templates.mdx b/docs/docs/modules/model_io/prompts/prompt_templates/msg_prompt_templates.mdx index 22c73a88f8013..af5d5b0724a7c 100644 --- a/docs/docs/modules/model_io/prompts/prompt_templates/msg_prompt_templates.mdx +++ b/docs/docs/modules/model_io/prompts/prompt_templates/msg_prompt_templates.mdx @@ -38,7 +38,7 @@ chat_prompt = ChatPromptTemplate.from_messages([MessagesPlaceholder(variable_nam ```python -from langchain.schema.messages import HumanMessage, AIMessage +from langchain_core.messages import HumanMessage, AIMessage human_message = HumanMessage(content="What is the best way to learn programming?") ai_message = AIMessage(content="""\ diff --git a/docs/docs/use_cases/data_generation.ipynb b/docs/docs/use_cases/data_generation.ipynb index e6fa11442fe38..3e9cd776c165e 100644 --- a/docs/docs/use_cases/data_generation.ipynb +++ b/docs/docs/use_cases/data_generation.ipynb @@ -66,7 +66,7 @@ "\n", "from langchain.chat_models import ChatOpenAI\n", "from langchain.prompts import FewShotPromptTemplate, PromptTemplate\n", - "from langchain.pydantic_v1 import BaseModel\n", + "from langchain_core.pydantic_v1 import BaseModel\n", "from langchain_experimental.tabular_synthetic_data.openai import (\n", " OPENAI_TEMPLATE,\n", " create_openai_data_generator,\n", diff --git a/docs/docs/use_cases/extraction.ipynb b/docs/docs/use_cases/extraction.ipynb index 7fdf12694defd..165670f9b330b 100644 --- a/docs/docs/use_cases/extraction.ipynb +++ b/docs/docs/use_cases/extraction.ipynb @@ -382,7 +382,7 @@ "from typing import Optional\n", "\n", "from langchain.chains import create_extraction_chain_pydantic\n", - "from langchain.pydantic_v1 import BaseModel\n", + "from langchain_core.pydantic_v1 import BaseModel\n", "\n", "\n", "# Pydantic data class\n", diff --git a/docs/docs/use_cases/question_answering/code_understanding.ipynb b/docs/docs/use_cases/question_answering/code_understanding.ipynb index d848db2c9d57c..34a272421d197 100644 --- a/docs/docs/use_cases/question_answering/code_understanding.ipynb +++ b/docs/docs/use_cases/question_answering/code_understanding.ipynb @@ -250,7 +250,7 @@ { "data": { "text/plain": [ - "'To initialize a ReAct agent, you need to follow these steps:\\n\\n1. Initialize a language model `llm` of type `BaseLanguageModel`.\\n\\n2. Initialize a document store `docstore` of type `Docstore`.\\n\\n3. Create a `DocstoreExplorer` with the initialized `docstore`. The `DocstoreExplorer` is used to search for and look up terms in the document store.\\n\\n4. Create an array of `Tool` objects. The `Tool` objects represent the actions that the agent can perform. In the case of `ReActDocstoreAgent`, the tools must be \"Search\" and \"Lookup\" with their corresponding functions from the `DocstoreExplorer`.\\n\\n5. Initialize the `ReActDocstoreAgent` using the `from_llm_and_tools` method with the `llm` (language model) and `tools` as parameters.\\n\\n6. Initialize the `ReActChain` (which is the `AgentExecutor`) using the `ReActDocstoreAgent` and `tools` as parameters.\\n\\nHere is an example of how to do this:\\n\\n```python\\nfrom langchain.chains import ReActChain, OpenAI\\nfrom langchain.docstore.base import Docstore\\nfrom langchain.docstore.document import Document\\nfrom langchain.tools.base import BaseTool\\n\\n# Initialize the LLM and a docstore\\nllm = OpenAI()\\ndocstore = Docstore()\\n\\ndocstore_explorer = DocstoreExplorer(docstore)\\ntools = [\\n Tool(\\n name=\"Search\",\\n func=docstore_explorer.search,\\n description=\"Search for a term in the docstore.\",\\n ),\\n Tool(\\n name=\"Lookup\",\\n func=docstore_explorer.lookup,\\n description=\"Lookup a term in the docstore.\",\\n ),\\n]\\nagent = ReActDocstoreAgent.from_llm_and_tools(llm, tools)\\nreact = ReActChain(agent=agent, tools=tools)\\n```\\n\\nKeep in mind that this is a simplified example and you might need to adapt it to your specific needs.'" + "'To initialize a ReAct agent, you need to follow these steps:\\n\\n1. Initialize a language model `llm` of type `BaseLanguageModel`.\\n\\n2. Initialize a document store `docstore` of type `Docstore`.\\n\\n3. Create a `DocstoreExplorer` with the initialized `docstore`. The `DocstoreExplorer` is used to search for and look up terms in the document store.\\n\\n4. Create an array of `Tool` objects. The `Tool` objects represent the actions that the agent can perform. In the case of `ReActDocstoreAgent`, the tools must be \"Search\" and \"Lookup\" with their corresponding functions from the `DocstoreExplorer`.\\n\\n5. Initialize the `ReActDocstoreAgent` using the `from_llm_and_tools` method with the `llm` (language model) and `tools` as parameters.\\n\\n6. Initialize the `ReActChain` (which is the `AgentExecutor`) using the `ReActDocstoreAgent` and `tools` as parameters.\\n\\nHere is an example of how to do this:\\n\\n```python\\nfrom langchain.chains import ReActChain, OpenAI\\nfrom langchain.docstore.base import Docstore\\nfrom langchain.docstore.document import Document\\nfrom langchain_core.tools import BaseTool\\n\\n# Initialize the LLM and a docstore\\nllm = OpenAI()\\ndocstore = Docstore()\\n\\ndocstore_explorer = DocstoreExplorer(docstore)\\ntools = [\\n Tool(\\n name=\"Search\",\\n func=docstore_explorer.search,\\n description=\"Search for a term in the docstore.\",\\n ),\\n Tool(\\n name=\"Lookup\",\\n func=docstore_explorer.lookup,\\n description=\"Lookup a term in the docstore.\",\\n ),\\n]\\nagent = ReActDocstoreAgent.from_llm_and_tools(llm, tools)\\nreact = ReActChain(agent=agent, tools=tools)\\n```\\n\\nKeep in mind that this is a simplified example and you might need to adapt it to your specific needs.'" ] }, "execution_count": 43, diff --git a/docs/docs/use_cases/question_answering/conversational_retrieval_agents.ipynb b/docs/docs/use_cases/question_answering/conversational_retrieval_agents.ipynb index 502ea5053f608..46b0fa002f9ed 100644 --- a/docs/docs/use_cases/question_answering/conversational_retrieval_agents.ipynb +++ b/docs/docs/use_cases/question_answering/conversational_retrieval_agents.ipynb @@ -429,7 +429,7 @@ "source": [ "from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent\n", "from langchain.prompts import MessagesPlaceholder\n", - "from langchain.schema.messages import SystemMessage" + "from langchain_core.messages import SystemMessage" ] }, { diff --git a/docs/docs/use_cases/question_answering/index.ipynb b/docs/docs/use_cases/question_answering/index.ipynb index 4bfc6b91c3a29..b5c982f847276 100644 --- a/docs/docs/use_cases/question_answering/index.ipynb +++ b/docs/docs/use_cases/question_answering/index.ipynb @@ -162,9 +162,9 @@ "from langchain.document_loaders import WebBaseLoader\n", "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.schema import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", - "from langchain.vectorstores import Chroma" + "from langchain.vectorstores import Chroma\n", + "from langchain_core.runnables import RunnablePassthrough" ] }, { @@ -687,7 +687,7 @@ "outputs": [], "source": [ "from langchain.schema import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "\n", "def format_docs(docs):\n", @@ -855,7 +855,7 @@ "source": [ "from operator import itemgetter\n", "\n", - "from langchain.schema.runnable import RunnableParallel\n", + "from langchain_core.runnables import RunnableParallel\n", "\n", "rag_chain_from_docs = (\n", " {\n", @@ -943,7 +943,7 @@ } ], "source": [ - "from langchain.schema.messages import AIMessage, HumanMessage\n", + "from langchain_core.messages import AIMessage, HumanMessage\n", "\n", "condense_q_chain.invoke(\n", " {\n", diff --git a/docs/docs/use_cases/tagging.ipynb b/docs/docs/use_cases/tagging.ipynb index 248b33b9f0b62..0e9b1b91aadf9 100644 --- a/docs/docs/use_cases/tagging.ipynb +++ b/docs/docs/use_cases/tagging.ipynb @@ -323,7 +323,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.pydantic_v1 import BaseModel, Field" + "from langchain_core.pydantic_v1 import BaseModel, Field" ] }, { diff --git a/docs/scripts/model_feat_table.py b/docs/scripts/model_feat_table.py index f81ebb66a02d2..7f4fa0ca1d1eb 100644 --- a/docs/scripts/model_feat_table.py +++ b/docs/scripts/model_feat_table.py @@ -2,8 +2,8 @@ from pathlib import Path from langchain import chat_models, llms -from langchain.chat_models.base import BaseChatModel, SimpleChatModel -from langchain.llms.base import LLM, BaseLLM +from langchain_core.language_models.chat_models import BaseChatModel, SimpleChatModel +from langchain_core.language_models.llms import LLM, BaseLLM INTEGRATIONS_DIR = Path(os.path.abspath(__file__)).parents[1] / "docs" / "integrations" LLM_IGNORE = ("FakeListLLM", "OpenAIChat", "PromptLayerOpenAIChat") diff --git a/templates/anthropic-iterative-search/anthropic_iterative_search/chain.py b/templates/anthropic-iterative-search/anthropic_iterative_search/chain.py index 8ffd2ad7000b6..289abc1f8829b 100644 --- a/templates/anthropic-iterative-search/anthropic_iterative_search/chain.py +++ b/templates/anthropic-iterative-search/anthropic_iterative_search/chain.py @@ -1,8 +1,8 @@ from langchain.chat_models import ChatAnthropic from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import ConfigurableField +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import ConfigurableField from .prompts import answer_prompt from .retriever_agent import executor diff --git a/templates/anthropic-iterative-search/anthropic_iterative_search/output_parser.py b/templates/anthropic-iterative-search/anthropic_iterative_search/output_parser.py index f1e981d761060..23697894cade2 100644 --- a/templates/anthropic-iterative-search/anthropic_iterative_search/output_parser.py +++ b/templates/anthropic-iterative-search/anthropic_iterative_search/output_parser.py @@ -1,6 +1,6 @@ import re -from langchain.schema.agent import AgentAction, AgentFinish +from langchain_core.agents import AgentAction, AgentFinish from .agent_scratchpad import _format_docs diff --git a/templates/anthropic-iterative-search/anthropic_iterative_search/retriever_agent.py b/templates/anthropic-iterative-search/anthropic_iterative_search/retriever_agent.py index 0c373bfc950ec..1a84a2024bd6f 100644 --- a/templates/anthropic-iterative-search/anthropic_iterative_search/retriever_agent.py +++ b/templates/anthropic-iterative-search/anthropic_iterative_search/retriever_agent.py @@ -1,8 +1,8 @@ from langchain.agents import AgentExecutor from langchain.chat_models import ChatAnthropic from langchain.prompts import ChatPromptTemplate -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import RunnableParallel, RunnablePassthrough from .agent_scratchpad import format_agent_scratchpad from .output_parser import parse_output diff --git a/templates/basic-critique-revise/basic_critique_revise/chain.py b/templates/basic-critique-revise/basic_critique_revise/chain.py index 0be6e60abdf99..ac70c89f9193b 100644 --- a/templates/basic-critique-revise/basic_critique_revise/chain.py +++ b/templates/basic-critique-revise/basic_critique_revise/chain.py @@ -7,8 +7,8 @@ from langchain.chains.openai_functions import convert_to_openai_function from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel, Field, ValidationError, conint -from langchain.schema.runnable import ( +from langchain_core.pydantic_v1 import BaseModel, Field, ValidationError, conint +from langchain_core.runnables import ( Runnable, RunnableBranch, RunnableLambda, diff --git a/templates/cassandra-entomology-rag/cassandra_entomology_rag/__init__.py b/templates/cassandra-entomology-rag/cassandra_entomology_rag/__init__.py index 73377401d4171..9e831ee91731d 100644 --- a/templates/cassandra-entomology-rag/cassandra_entomology_rag/__init__.py +++ b/templates/cassandra-entomology-rag/cassandra_entomology_rag/__init__.py @@ -4,9 +4,9 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough from langchain.vectorstores import Cassandra +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import RunnablePassthrough from .populate_vector_store import populate diff --git a/templates/cassandra-synonym-caching/cassandra_synonym_caching/__init__.py b/templates/cassandra-synonym-caching/cassandra_synonym_caching/__init__.py index cbb666ae4f232..f38d81d765142 100644 --- a/templates/cassandra-synonym-caching/cassandra_synonym_caching/__init__.py +++ b/templates/cassandra-synonym-caching/cassandra_synonym_caching/__init__.py @@ -6,7 +6,7 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate from langchain.schema import BaseMessage -from langchain.schema.runnable import RunnableLambda +from langchain_core.runnables import RunnableLambda use_cassandra = int(os.environ.get("USE_CASSANDRA_CLUSTER", "0")) if use_cassandra: diff --git a/templates/chain-of-note-wiki/chain_of_note_wiki/chain.py b/templates/chain-of-note-wiki/chain_of_note_wiki/chain.py index 63c1654802c21..cd5b247788709 100644 --- a/templates/chain-of-note-wiki/chain_of_note_wiki/chain.py +++ b/templates/chain-of-note-wiki/chain_of_note_wiki/chain.py @@ -1,9 +1,9 @@ from langchain import hub from langchain.chat_models import ChatAnthropic -from langchain.pydantic_v1 import BaseModel from langchain.schema import StrOutputParser -from langchain.schema.runnable import RunnableLambda, RunnablePassthrough from langchain.utilities import WikipediaAPIWrapper +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableLambda, RunnablePassthrough class Question(BaseModel): diff --git a/templates/chat-bot-feedback/chat_bot_feedback/chain.py b/templates/chat-bot-feedback/chat_bot_feedback/chain.py index 004f93ba683c8..5c4055d66f1b2 100644 --- a/templates/chat-bot-feedback/chat_bot_feedback/chain.py +++ b/templates/chat-bot-feedback/chat_bot_feedback/chain.py @@ -15,7 +15,7 @@ StrOutputParser, get_buffer_string, ) -from langchain.schema.runnable import Runnable +from langchain_core.runnables import Runnable from langsmith.evaluation import EvaluationResult, RunEvaluator from langsmith.schemas import Example from pydantic import BaseModel, Field diff --git a/templates/csv-agent/csv_agent/agent.py b/templates/csv-agent/csv_agent/agent.py index 4aa4694b89795..4d50c14870332 100644 --- a/templates/csv-agent/csv_agent/agent.py +++ b/templates/csv-agent/csv_agent/agent.py @@ -5,9 +5,9 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder -from langchain.pydantic_v1 import BaseModel, Field from langchain.tools.retriever import create_retriever_tool from langchain.vectorstores import FAISS +from langchain_core.pydantic_v1 import BaseModel, Field from langchain_experimental.tools import PythonAstREPLTool MAIN_DIR = Path(__file__).parents[1] diff --git a/templates/elastic-query-generator/elastic_query_generator/chain.py b/templates/elastic-query-generator/elastic_query_generator/chain.py index f72a6c3007e8b..911c053e93c89 100644 --- a/templates/elastic-query-generator/elastic_query_generator/chain.py +++ b/templates/elastic-query-generator/elastic_query_generator/chain.py @@ -1,7 +1,7 @@ from elasticsearch import Elasticsearch from langchain.chat_models import ChatOpenAI from langchain.output_parsers.json import SimpleJsonOutputParser -from langchain.pydantic_v1 import BaseModel +from langchain_core.pydantic_v1 import BaseModel from .elastic_index_info import get_indices_infos from .prompts import DSL_PROMPT diff --git a/templates/extraction-anthropic-functions/extraction_anthropic_functions/chain.py b/templates/extraction-anthropic-functions/extraction_anthropic_functions/chain.py index 4aab09665173e..ac87eb508fb4a 100644 --- a/templates/extraction-anthropic-functions/extraction_anthropic_functions/chain.py +++ b/templates/extraction-anthropic-functions/extraction_anthropic_functions/chain.py @@ -2,8 +2,8 @@ from langchain.output_parsers.openai_functions import JsonKeyOutputFunctionsParser from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel from langchain.utils.openai_functions import convert_pydantic_to_openai_function +from langchain_core.pydantic_v1 import BaseModel from langchain_experimental.llms.anthropic_functions import AnthropicFunctions template = """A article will be passed to you. Extract from it all papers that are mentioned by this article. diff --git a/templates/extraction-openai-functions/extraction_openai_functions/chain.py b/templates/extraction-openai-functions/extraction_openai_functions/chain.py index ccf3c876848c5..9c54d7ef295f3 100644 --- a/templates/extraction-openai-functions/extraction_openai_functions/chain.py +++ b/templates/extraction-openai-functions/extraction_openai_functions/chain.py @@ -3,8 +3,8 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel from langchain.utils.openai_functions import convert_pydantic_to_openai_function +from langchain_core.pydantic_v1 import BaseModel template = """A article will be passed to you. Extract from it all papers that are mentioned by this article. diff --git a/templates/hybrid-search-weaviate/hybrid_search_weaviate/chain.py b/templates/hybrid-search-weaviate/hybrid_search_weaviate/chain.py index bd54a866039e9..9c6480d37dec2 100644 --- a/templates/hybrid-search-weaviate/hybrid_search_weaviate/chain.py +++ b/templates/hybrid-search-weaviate/hybrid_search_weaviate/chain.py @@ -4,8 +4,8 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate from langchain.retrievers.weaviate_hybrid_search import WeaviateHybridSearchRetriever -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import RunnableParallel, RunnablePassthrough # Check env vars if os.environ.get("WEAVIATE_API_KEY", None) is None: diff --git a/templates/hyde/hyde/chain.py b/templates/hyde/hyde/chain.py index a6503c9447f4e..24e7d37e38de7 100644 --- a/templates/hyde/hyde/chain.py +++ b/templates/hyde/hyde/chain.py @@ -1,10 +1,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel from langchain.vectorstores import Chroma +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel from hyde.prompts import hyde_prompt diff --git a/templates/mongo-parent-document-retrieval/mongo_parent_document_retrieval/chain.py b/templates/mongo-parent-document-retrieval/mongo_parent_document_retrieval/chain.py index 7307e60b66b1d..5e182144f4483 100644 --- a/templates/mongo-parent-document-retrieval/mongo_parent_document_retrieval/chain.py +++ b/templates/mongo-parent-document-retrieval/mongo_parent_document_retrieval/chain.py @@ -3,11 +3,11 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.document import Document -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import MongoDBAtlasVectorSearch +from langchain_core.documents import Document +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough from pymongo import MongoClient MONGO_URI = os.environ["MONGO_URI"] diff --git a/templates/neo4j-advanced-rag/ingest.py b/templates/neo4j-advanced-rag/ingest.py index ee268cd2e2c59..d19767acc2403 100644 --- a/templates/neo4j-advanced-rag/ingest.py +++ b/templates/neo4j-advanced-rag/ingest.py @@ -7,8 +7,8 @@ from langchain.embeddings.openai import OpenAIEmbeddings from langchain.graphs import Neo4jGraph from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel, Field from langchain.text_splitter import TokenTextSplitter +from langchain_core.pydantic_v1 import BaseModel, Field from neo4j.exceptions import ClientError txt_path = Path(__file__).parent / "dune.txt" diff --git a/templates/neo4j-advanced-rag/neo4j_advanced_rag/chain.py b/templates/neo4j-advanced-rag/neo4j_advanced_rag/chain.py index e8fe3cebc07f2..5293920f916d6 100644 --- a/templates/neo4j-advanced-rag/neo4j_advanced_rag/chain.py +++ b/templates/neo4j-advanced-rag/neo4j_advanced_rag/chain.py @@ -2,9 +2,9 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import ConfigurableField, RunnableParallel +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import ConfigurableField, RunnableParallel from neo4j_advanced_rag.retrievers import ( hypothetic_question_vectorstore, diff --git a/templates/neo4j-cypher-ft/neo4j_cypher_ft/chain.py b/templates/neo4j-cypher-ft/neo4j_cypher_ft/chain.py index 7d065315bc193..79c64b4ffd5d9 100644 --- a/templates/neo4j-cypher-ft/neo4j_cypher_ft/chain.py +++ b/templates/neo4j-cypher-ft/neo4j_cypher_ft/chain.py @@ -5,9 +5,9 @@ from langchain.chat_models import ChatOpenAI from langchain.graphs import Neo4jGraph from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel, Field -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel, Field +from langchain_core.runnables import RunnablePassthrough # Connection to Neo4j graph = Neo4jGraph() diff --git a/templates/neo4j-cypher-memory/neo4j_cypher_memory/chain.py b/templates/neo4j-cypher-memory/neo4j_cypher_memory/chain.py index 594b901fc3564..a8f3fff0adc4c 100644 --- a/templates/neo4j-cypher-memory/neo4j_cypher_memory/chain.py +++ b/templates/neo4j-cypher-memory/neo4j_cypher_memory/chain.py @@ -5,9 +5,9 @@ from langchain.graphs import Neo4jGraph from langchain.memory import ChatMessageHistory from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnablePassthrough # Connection to Neo4j graph = Neo4jGraph() diff --git a/templates/neo4j-cypher/neo4j_cypher/chain.py b/templates/neo4j-cypher/neo4j_cypher/chain.py index 16ca63f6d585e..f8e4d8d90471f 100644 --- a/templates/neo4j-cypher/neo4j_cypher/chain.py +++ b/templates/neo4j-cypher/neo4j_cypher/chain.py @@ -2,9 +2,9 @@ from langchain.chat_models import ChatOpenAI from langchain.graphs import Neo4jGraph from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnablePassthrough # Connection to Neo4j graph = Neo4jGraph() diff --git a/templates/neo4j-generation/neo4j_generation/utils.py b/templates/neo4j-generation/neo4j_generation/utils.py index 0509a574b9d8d..d888db37dbe9d 100644 --- a/templates/neo4j-generation/neo4j_generation/utils.py +++ b/templates/neo4j-generation/neo4j_generation/utils.py @@ -2,7 +2,7 @@ from langchain.graphs.graph_document import Node as BaseNode from langchain.graphs.graph_document import Relationship as BaseRelationship -from langchain.pydantic_v1 import BaseModel, Field +from langchain_core.pydantic_v1 import BaseModel, Field class Property(BaseModel): diff --git a/templates/neo4j-parent/neo4j_parent/chain.py b/templates/neo4j-parent/neo4j_parent/chain.py index e47c89e495742..01950baba99b0 100644 --- a/templates/neo4j-parent/neo4j_parent/chain.py +++ b/templates/neo4j-parent/neo4j_parent/chain.py @@ -1,10 +1,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import Neo4jVector +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough retrieval_query = """ MATCH (node)-[:HAS_PARENT]->(parent) diff --git a/templates/neo4j-vector-memory/neo4j_vector_memory/chain.py b/templates/neo4j-vector-memory/neo4j_vector_memory/chain.py index eae03f122817a..63b9f4fef012a 100644 --- a/templates/neo4j-vector-memory/neo4j_vector_memory/chain.py +++ b/templates/neo4j-vector-memory/neo4j_vector_memory/chain.py @@ -3,10 +3,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder, PromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough from langchain.vectorstores import Neo4jVector +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnablePassthrough from neo4j_vector_memory.history import get_history, save_history diff --git a/templates/openai-functions-agent/openai_functions_agent/agent.py b/templates/openai-functions-agent/openai_functions_agent/agent.py index 276b40438bebf..80986fd4d0afc 100644 --- a/templates/openai-functions-agent/openai_functions_agent/agent.py +++ b/templates/openai-functions-agent/openai_functions_agent/agent.py @@ -5,11 +5,11 @@ from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder -from langchain.pydantic_v1 import BaseModel, Field -from langchain.schema.messages import AIMessage, HumanMessage from langchain.tools.render import format_tool_to_openai_function from langchain.tools.tavily_search import TavilySearchResults from langchain.utilities.tavily_search import TavilySearchAPIWrapper +from langchain_core.messages import AIMessage, HumanMessage +from langchain_core.pydantic_v1 import BaseModel, Field # Create the tool search = TavilySearchAPIWrapper() diff --git a/templates/openai-functions-tool-retrieval-agent/openai_functions_tool_retrieval_agent/agent.py b/templates/openai-functions-tool-retrieval-agent/openai_functions_tool_retrieval_agent/agent.py index fd61d91928a28..983208026e967 100644 --- a/templates/openai-functions-tool-retrieval-agent/openai_functions_tool_retrieval_agent/agent.py +++ b/templates/openai-functions-tool-retrieval-agent/openai_functions_tool_retrieval_agent/agent.py @@ -12,15 +12,15 @@ ChatPromptTemplate, MessagesPlaceholder, ) -from langchain.pydantic_v1 import BaseModel, Field from langchain.schema import Document -from langchain.schema.messages import AIMessage, HumanMessage -from langchain.schema.runnable import Runnable, RunnableLambda, RunnableParallel -from langchain.tools.base import BaseTool from langchain.tools.render import format_tool_to_openai_function from langchain.tools.tavily_search import TavilySearchResults from langchain.utilities.tavily_search import TavilySearchAPIWrapper from langchain.vectorstores import FAISS +from langchain_core.messages import AIMessage, HumanMessage +from langchain_core.pydantic_v1 import BaseModel, Field +from langchain_core.runnables import Runnable, RunnableLambda, RunnableParallel +from langchain_core.tools import BaseTool # Create the tools search = TavilySearchAPIWrapper() diff --git a/templates/pii-protected-chatbot/pii_protected_chatbot/chain.py b/templates/pii-protected-chatbot/pii_protected_chatbot/chain.py index d7d502ae8d4db..d36c8719f9b11 100644 --- a/templates/pii-protected-chatbot/pii_protected_chatbot/chain.py +++ b/templates/pii-protected-chatbot/pii_protected_chatbot/chain.py @@ -2,10 +2,10 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder -from langchain.pydantic_v1 import BaseModel -from langchain.schema.messages import AIMessage, HumanMessage -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough +from langchain_core.messages import AIMessage, HumanMessage +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnablePassthrough from presidio_analyzer import AnalyzerEngine diff --git a/templates/pirate-speak-configurable/pirate_speak_configurable/chain.py b/templates/pirate-speak-configurable/pirate_speak_configurable/chain.py index a385f22036712..241397ed7258e 100644 --- a/templates/pirate-speak-configurable/pirate_speak_configurable/chain.py +++ b/templates/pirate-speak-configurable/pirate_speak_configurable/chain.py @@ -1,6 +1,6 @@ from langchain.chat_models import ChatAnthropic, ChatCohere, ChatOpenAI from langchain.prompts import ChatPromptTemplate -from langchain.schema.runnable import ConfigurableField +from langchain_core.runnables import ConfigurableField _prompt = ChatPromptTemplate.from_messages( [ diff --git a/templates/plate-chain/plate_chain/chain.py b/templates/plate-chain/plate_chain/chain.py index 7a0aa0edccdcc..a369d23be2a11 100644 --- a/templates/plate-chain/plate_chain/chain.py +++ b/templates/plate-chain/plate_chain/chain.py @@ -3,8 +3,8 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate -from langchain.pydantic_v1 import Field -from langchain.schema.output_parser import StrOutputParser +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import Field from langserve import CustomUserType from .prompts import ( diff --git a/templates/rag-astradb/astradb_entomology_rag/__init__.py b/templates/rag-astradb/astradb_entomology_rag/__init__.py index 4f85982f4476e..2f1c325a0e1c0 100644 --- a/templates/rag-astradb/astradb_entomology_rag/__init__.py +++ b/templates/rag-astradb/astradb_entomology_rag/__init__.py @@ -3,9 +3,9 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough from langchain.vectorstores import AstraDB +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import RunnablePassthrough from .populate_vector_store import populate diff --git a/templates/rag-aws-bedrock/rag_aws_bedrock/chain.py b/templates/rag-aws-bedrock/rag_aws_bedrock/chain.py index 6ff1c185028f6..744b96545a67a 100644 --- a/templates/rag-aws-bedrock/rag_aws_bedrock/chain.py +++ b/templates/rag-aws-bedrock/rag_aws_bedrock/chain.py @@ -3,10 +3,10 @@ from langchain.embeddings import BedrockEmbeddings from langchain.llms.bedrock import Bedrock from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import FAISS +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough # Get region and profile from env region = os.environ.get("AWS_DEFAULT_REGION", "us-east-1") diff --git a/templates/rag-aws-kendra/rag_aws_kendra/chain.py b/templates/rag-aws-kendra/rag_aws_kendra/chain.py index d07a2a4539546..df2e56355733d 100644 --- a/templates/rag-aws-kendra/rag_aws_kendra/chain.py +++ b/templates/rag-aws-kendra/rag_aws_kendra/chain.py @@ -2,10 +2,10 @@ from langchain.llms.bedrock import Bedrock from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel from langchain.retrievers import AmazonKendraRetriever -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough # Get region and profile from env region = os.environ.get("AWS_DEFAULT_REGION", "us-east-1") diff --git a/templates/rag-chroma-multi-modal/rag_chroma_multi_modal/chain.py b/templates/rag-chroma-multi-modal/rag_chroma_multi_modal/chain.py index 2cd83b743fff4..c8c674365d546 100644 --- a/templates/rag-chroma-multi-modal/rag_chroma_multi_modal/chain.py +++ b/templates/rag-chroma-multi-modal/rag_chroma_multi_modal/chain.py @@ -3,12 +3,12 @@ from pathlib import Path from langchain.chat_models import ChatOpenAI -from langchain.pydantic_v1 import BaseModel -from langchain.schema.document import Document -from langchain.schema.messages import HumanMessage -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableLambda, RunnablePassthrough from langchain.vectorstores import Chroma +from langchain_core.documents import Document +from langchain_core.messages import HumanMessage +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableLambda, RunnablePassthrough from langchain_experimental.open_clip import OpenCLIPEmbeddings from PIL import Image diff --git a/templates/rag-chroma-private/rag_chroma_private/chain.py b/templates/rag-chroma-private/rag_chroma_private/chain.py index b3942d909eb45..05e5bca894e98 100644 --- a/templates/rag-chroma-private/rag_chroma_private/chain.py +++ b/templates/rag-chroma-private/rag_chroma_private/chain.py @@ -3,11 +3,11 @@ from langchain.document_loaders import WebBaseLoader from langchain.embeddings import GPT4AllEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.vectorstores import Chroma +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough loader = WebBaseLoader("https://lilianweng.github.io/posts/2023-06-23-agent/") data = loader.load() diff --git a/templates/rag-chroma/rag_chroma/chain.py b/templates/rag-chroma/rag_chroma/chain.py index dd6f319ef874f..ea929e974cbbc 100644 --- a/templates/rag-chroma/rag_chroma/chain.py +++ b/templates/rag-chroma/rag_chroma/chain.py @@ -1,10 +1,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import Chroma +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough # Example for document loading (from url), splitting, and creating vectostore diff --git a/templates/rag-codellama-fireworks/rag_codellama_fireworks/chain.py b/templates/rag-codellama-fireworks/rag_codellama_fireworks/chain.py index 405aad4fc1859..c1f4cefebb4c7 100644 --- a/templates/rag-codellama-fireworks/rag_codellama_fireworks/chain.py +++ b/templates/rag-codellama-fireworks/rag_codellama_fireworks/chain.py @@ -6,11 +6,11 @@ from langchain.embeddings import GPT4AllEmbeddings from langchain.llms.fireworks import Fireworks from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.text_splitter import Language, RecursiveCharacterTextSplitter from langchain.vectorstores import Chroma +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough # Check API key if os.environ.get("FIREWORKS_API_KEY", None) is None: diff --git a/templates/rag-conversation-zep/rag_conversation_zep/chain.py b/templates/rag-conversation-zep/rag_conversation_zep/chain.py index 7da815f2ad9c8..f46e66a4bd02b 100644 --- a/templates/rag-conversation-zep/rag_conversation_zep/chain.py +++ b/templates/rag-conversation-zep/rag_conversation_zep/chain.py @@ -5,20 +5,20 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder from langchain.prompts.prompt import PromptTemplate -from langchain.pydantic_v1 import BaseModel, Field from langchain.schema import AIMessage, HumanMessage, format_document -from langchain.schema.document import Document -from langchain.schema.messages import BaseMessage -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import ( +from langchain.vectorstores.zep import CollectionConfig, ZepVectorStore +from langchain_core.documents import Document +from langchain_core.messages import BaseMessage +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel, Field +from langchain_core.runnables import ( ConfigurableField, RunnableBranch, RunnableLambda, RunnableParallel, RunnablePassthrough, ) -from langchain.schema.runnable.utils import ConfigurableFieldSingleOption -from langchain.vectorstores.zep import CollectionConfig, ZepVectorStore +from langchain_core.runnables.utils import ConfigurableFieldSingleOption ZEP_API_URL = os.environ.get("ZEP_API_URL", "http://localhost:8000") ZEP_API_KEY = os.environ.get("ZEP_API_KEY", None) diff --git a/templates/rag-conversation/rag_conversation/chain.py b/templates/rag-conversation/rag_conversation/chain.py index 3c12583caf2e6..2ae5d3500167b 100644 --- a/templates/rag-conversation/rag_conversation/chain.py +++ b/templates/rag-conversation/rag_conversation/chain.py @@ -7,14 +7,14 @@ from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder from langchain.prompts.prompt import PromptTemplate from langchain.schema import AIMessage, HumanMessage, format_document -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import ( +from langchain.vectorstores import Pinecone +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import ( RunnableBranch, RunnableLambda, RunnableParallel, RunnablePassthrough, ) -from langchain.vectorstores import Pinecone from pydantic import BaseModel, Field if os.environ.get("PINECONE_API_KEY", None) is None: diff --git a/templates/rag-elasticsearch/rag_elasticsearch/chain.py b/templates/rag-elasticsearch/rag_elasticsearch/chain.py index 07f37300b086d..963e7854f03b5 100644 --- a/templates/rag-elasticsearch/rag_elasticsearch/chain.py +++ b/templates/rag-elasticsearch/rag_elasticsearch/chain.py @@ -4,9 +4,9 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import HuggingFaceEmbeddings from langchain.schema import BaseMessage, format_document -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores.elasticsearch import ElasticsearchStore +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import RunnableParallel, RunnablePassthrough from pydantic import BaseModel, Field from .connection import es_connection_details diff --git a/templates/rag-fusion/rag_fusion/chain.py b/templates/rag-fusion/rag_fusion/chain.py index 8d1830c74ff17..60d11bd49b983 100644 --- a/templates/rag-fusion/rag_fusion/chain.py +++ b/templates/rag-fusion/rag_fusion/chain.py @@ -2,9 +2,9 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.load import dumps, loads -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser from langchain.vectorstores import Pinecone +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel def reciprocal_rank_fusion(results: list[list], k=60): diff --git a/templates/rag-google-cloud-sensitive-data-protection/rag_google_cloud_sensitive_data_protection/chain.py b/templates/rag-google-cloud-sensitive-data-protection/rag_google_cloud_sensitive_data_protection/chain.py index aeb6033e51c62..0a33e7c58ae49 100644 --- a/templates/rag-google-cloud-sensitive-data-protection/rag_google_cloud_sensitive_data_protection/chain.py +++ b/templates/rag-google-cloud-sensitive-data-protection/rag_google_cloud_sensitive_data_protection/chain.py @@ -4,10 +4,10 @@ from google.cloud import dlp_v2 from langchain.chat_models import ChatVertexAI from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder -from langchain.pydantic_v1 import BaseModel, Field -from langchain.schema.messages import AIMessage, HumanMessage -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableLambda, RunnableParallel +from langchain_core.messages import AIMessage, HumanMessage +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel, Field +from langchain_core.runnables import RunnableLambda, RunnableParallel # Formatting for chat history diff --git a/templates/rag-google-cloud-vertexai-search/rag_google_cloud_vertexai_search/chain.py b/templates/rag-google-cloud-vertexai-search/rag_google_cloud_vertexai_search/chain.py index 57076d5f86a94..46eafc5ccc93d 100644 --- a/templates/rag-google-cloud-vertexai-search/rag_google_cloud_vertexai_search/chain.py +++ b/templates/rag-google-cloud-vertexai-search/rag_google_cloud_vertexai_search/chain.py @@ -2,10 +2,10 @@ from langchain.chat_models import ChatVertexAI from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel from langchain.retrievers import GoogleVertexAISearchRetriever -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough # Get project, data store, and model type from env variables project_id = os.environ.get("GOOGLE_CLOUD_PROJECT_ID") diff --git a/templates/rag-gpt-crawler/rag_gpt_crawler/chain.py b/templates/rag-gpt-crawler/rag_gpt_crawler/chain.py index 1fcfff0d5d76f..a217de65ca1b7 100644 --- a/templates/rag-gpt-crawler/rag_gpt_crawler/chain.py +++ b/templates/rag-gpt-crawler/rag_gpt_crawler/chain.py @@ -4,12 +4,12 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel from langchain.schema import Document -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.vectorstores import Chroma +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough # Load output from gpt crawler path_to_gptcrawler = Path(__file__).parent.parent / "output.json" diff --git a/templates/rag-matching-engine/rag_matching_engine/chain.py b/templates/rag-matching-engine/rag_matching_engine/chain.py index b2d215c09291b..943eec823ef06 100644 --- a/templates/rag-matching-engine/rag_matching_engine/chain.py +++ b/templates/rag-matching-engine/rag_matching_engine/chain.py @@ -3,10 +3,10 @@ from langchain.embeddings import VertexAIEmbeddings from langchain.llms import VertexAI from langchain.prompts import PromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import MatchingEngine +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough # you need to preate the index first, for example, as described here: # https://github.com/GoogleCloudPlatform/generative-ai/blob/main/language/use-cases/document-qa/question_answering_documents_langchain_matching_engine.ipynb diff --git a/templates/rag-momento-vector-index/rag_momento_vector_index/chain.py b/templates/rag-momento-vector-index/rag_momento_vector_index/chain.py index 2c1604f2cded3..78291f68e7527 100644 --- a/templates/rag-momento-vector-index/rag_momento_vector_index/chain.py +++ b/templates/rag-momento-vector-index/rag_momento_vector_index/chain.py @@ -3,10 +3,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough from langchain.vectorstores import MomentoVectorIndex +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnablePassthrough from momento import ( CredentialProvider, PreviewVectorIndexClient, diff --git a/templates/rag-mongo/rag_mongo/chain.py b/templates/rag-mongo/rag_mongo/chain.py index c75159881ba79..62613f2e076be 100644 --- a/templates/rag-mongo/rag_mongo/chain.py +++ b/templates/rag-mongo/rag_mongo/chain.py @@ -4,15 +4,15 @@ from langchain.document_loaders import PyPDFLoader from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import ( +from langchain.text_splitter import RecursiveCharacterTextSplitter +from langchain.vectorstores import MongoDBAtlasVectorSearch +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import ( RunnableLambda, RunnableParallel, RunnablePassthrough, ) -from langchain.text_splitter import RecursiveCharacterTextSplitter -from langchain.vectorstores import MongoDBAtlasVectorSearch from pymongo import MongoClient # Set DB diff --git a/templates/rag-multi-index-fusion/rag_multi_index_fusion/chain.py b/templates/rag-multi-index-fusion/rag_multi_index_fusion/chain.py index a6b10dc6f24c5..03799162355ce 100644 --- a/templates/rag-multi-index-fusion/rag_multi_index_fusion/chain.py +++ b/templates/rag-multi-index-fusion/rag_multi_index_fusion/chain.py @@ -4,7 +4,6 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel from langchain.retrievers import ( ArxivRetriever, KayAiRetriever, @@ -12,11 +11,12 @@ WikipediaRetriever, ) from langchain.schema import StrOutputParser -from langchain.schema.runnable import ( +from langchain.utils.math import cosine_similarity +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import ( RunnableParallel, RunnablePassthrough, ) -from langchain.utils.math import cosine_similarity pubmed = PubMedRetriever(top_k_results=5).with_config(run_name="pubmed") arxiv = ArxivRetriever(top_k_results=5).with_config(run_name="arxiv") diff --git a/templates/rag-multi-index-router/rag_multi_index_router/chain.py b/templates/rag-multi-index-router/rag_multi_index_router/chain.py index cbdb6a3e2d13d..625f2b4e80ea2 100644 --- a/templates/rag-multi-index-router/rag_multi_index_router/chain.py +++ b/templates/rag-multi-index-router/rag_multi_index_router/chain.py @@ -4,7 +4,6 @@ from langchain.chat_models import ChatOpenAI from langchain.output_parsers.openai_functions import PydanticAttrOutputFunctionsParser from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel, Field from langchain.retrievers import ( ArxivRetriever, KayAiRetriever, @@ -12,12 +11,13 @@ WikipediaRetriever, ) from langchain.schema import StrOutputParser -from langchain.schema.runnable import ( +from langchain.utils.openai_functions import convert_pydantic_to_openai_function +from langchain_core.pydantic_v1 import BaseModel, Field +from langchain_core.runnables import ( RouterRunnable, RunnableParallel, RunnablePassthrough, ) -from langchain.utils.openai_functions import convert_pydantic_to_openai_function pubmed = PubMedRetriever(top_k_results=5).with_config(run_name="pubmed") arxiv = ArxivRetriever(top_k_results=5).with_config(run_name="arxiv") diff --git a/templates/rag-ollama-multi-query/rag_ollama_multi_query/chain.py b/templates/rag-ollama-multi-query/rag_ollama_multi_query/chain.py index 1fa031ae2e0e9..c65675e0be181 100644 --- a/templates/rag-ollama-multi-query/rag_ollama_multi_query/chain.py +++ b/templates/rag-ollama-multi-query/rag_ollama_multi_query/chain.py @@ -6,12 +6,12 @@ from langchain.embeddings import OpenAIEmbeddings from langchain.output_parsers import PydanticOutputParser from langchain.prompts import ChatPromptTemplate, PromptTemplate -from langchain.pydantic_v1 import BaseModel, Field from langchain.retrievers.multi_query import MultiQueryRetriever -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.vectorstores import Chroma +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel, Field +from langchain_core.runnables import RunnableParallel, RunnablePassthrough # Load loader = WebBaseLoader("https://lilianweng.github.io/posts/2023-06-23-agent/") diff --git a/templates/rag-opensearch/rag_opensearch/chain.py b/templates/rag-opensearch/rag_opensearch/chain.py index 067dfca240558..75f9b0fb841f7 100644 --- a/templates/rag-opensearch/rag_opensearch/chain.py +++ b/templates/rag-opensearch/rag_opensearch/chain.py @@ -3,10 +3,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores.opensearch_vector_search import OpenSearchVectorSearch +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") OPENSEARCH_URL = os.getenv("OPENSEARCH_URL", "https://localhost:9200") diff --git a/templates/rag-pinecone-multi-query/rag_pinecone_multi_query/chain.py b/templates/rag-pinecone-multi-query/rag_pinecone_multi_query/chain.py index 5db9b5026edd8..ace96bda06874 100644 --- a/templates/rag-pinecone-multi-query/rag_pinecone_multi_query/chain.py +++ b/templates/rag-pinecone-multi-query/rag_pinecone_multi_query/chain.py @@ -3,11 +3,11 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel from langchain.retrievers.multi_query import MultiQueryRetriever -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import Pinecone +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough if os.environ.get("PINECONE_API_KEY", None) is None: raise Exception("Missing `PINECONE_API_KEY` environment variable.") diff --git a/templates/rag-pinecone-rerank/rag_pinecone_rerank/chain.py b/templates/rag-pinecone-rerank/rag_pinecone_rerank/chain.py index ba1d37ea2c7cd..f5d3439c7b056 100644 --- a/templates/rag-pinecone-rerank/rag_pinecone_rerank/chain.py +++ b/templates/rag-pinecone-rerank/rag_pinecone_rerank/chain.py @@ -3,12 +3,12 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel from langchain.retrievers import ContextualCompressionRetriever from langchain.retrievers.document_compressors import CohereRerank -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import Pinecone +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough if os.environ.get("PINECONE_API_KEY", None) is None: raise Exception("Missing `PINECONE_API_KEY` environment variable.") diff --git a/templates/rag-pinecone/rag_pinecone/chain.py b/templates/rag-pinecone/rag_pinecone/chain.py index 7e9dfb796660b..8f1d03d2abef3 100644 --- a/templates/rag-pinecone/rag_pinecone/chain.py +++ b/templates/rag-pinecone/rag_pinecone/chain.py @@ -3,10 +3,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import Pinecone +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough if os.environ.get("PINECONE_API_KEY", None) is None: raise Exception("Missing `PINECONE_API_KEY` environment variable.") diff --git a/templates/rag-redis/rag_redis/chain.py b/templates/rag-redis/rag_redis/chain.py index df78737a2eae5..0e451f363620f 100644 --- a/templates/rag-redis/rag_redis/chain.py +++ b/templates/rag-redis/rag_redis/chain.py @@ -1,10 +1,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import HuggingFaceEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import Redis +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough from rag_redis.config import ( EMBED_MODEL, diff --git a/templates/rag-self-query/rag_self_query/chain.py b/templates/rag-self-query/rag_self_query/chain.py index bcb22c67f8bf1..8e5e7cbe5ffda 100644 --- a/templates/rag-self-query/rag_self_query/chain.py +++ b/templates/rag-self-query/rag_self_query/chain.py @@ -6,9 +6,9 @@ from langchain.embeddings import OpenAIEmbeddings from langchain.retrievers import SelfQueryRetriever from langchain.schema import format_document -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores.elasticsearch import ElasticsearchStore +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import RunnableParallel, RunnablePassthrough from pydantic.v1 import BaseModel, Field from .prompts import CONDENSE_QUESTION_PROMPT, DOCUMENT_PROMPT, LLM_CONTEXT_PROMPT diff --git a/templates/rag-semi-structured/rag_semi_structured/chain.py b/templates/rag-semi-structured/rag_semi_structured/chain.py index d0775ae318a5d..488a753c88a18 100644 --- a/templates/rag-semi-structured/rag_semi_structured/chain.py +++ b/templates/rag-semi-structured/rag_semi_structured/chain.py @@ -4,13 +4,13 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel from langchain.retrievers.multi_vector import MultiVectorRetriever -from langchain.schema.document import Document -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough from langchain.storage import InMemoryStore from langchain.vectorstores import Chroma +from langchain_core.documents import Document +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnablePassthrough from unstructured.partition.pdf import partition_pdf # Path to docs diff --git a/templates/rag-singlestoredb/rag_singlestoredb/chain.py b/templates/rag-singlestoredb/rag_singlestoredb/chain.py index a4324843150d2..f609266566a2f 100644 --- a/templates/rag-singlestoredb/rag_singlestoredb/chain.py +++ b/templates/rag-singlestoredb/rag_singlestoredb/chain.py @@ -3,10 +3,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import SingleStoreDB +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough if os.environ.get("SINGLESTOREDB_URL", None) is None: raise Exception("Missing `SINGLESTOREDB_URL` environment variable.") diff --git a/templates/rag-supabase/rag_supabase/chain.py b/templates/rag-supabase/rag_supabase/chain.py index 1fead91b4112b..6a24aa7fb7eeb 100644 --- a/templates/rag-supabase/rag_supabase/chain.py +++ b/templates/rag-supabase/rag_supabase/chain.py @@ -3,10 +3,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores.supabase import SupabaseVectorStore +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough from supabase.client import create_client supabase_url = os.environ.get("SUPABASE_URL") diff --git a/templates/rag-timescale-conversation/rag_timescale_conversation/chain.py b/templates/rag-timescale-conversation/rag_timescale_conversation/chain.py index ba9551db80a3c..06363e401a099 100644 --- a/templates/rag-timescale-conversation/rag_timescale_conversation/chain.py +++ b/templates/rag-timescale-conversation/rag_timescale_conversation/chain.py @@ -9,14 +9,14 @@ from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder from langchain.prompts.prompt import PromptTemplate from langchain.schema import AIMessage, HumanMessage, format_document -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import ( +from langchain.vectorstores.timescalevector import TimescaleVector +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import ( RunnableBranch, RunnableLambda, RunnableParallel, RunnablePassthrough, ) -from langchain.vectorstores.timescalevector import TimescaleVector from pydantic import BaseModel, Field from .load_sample_dataset import load_ts_git_dataset diff --git a/templates/rag-timescale-hybrid-search-time/rag_timescale_hybrid_search_time/chain.py b/templates/rag-timescale-hybrid-search-time/rag_timescale_hybrid_search_time/chain.py index a5ad549b8bc84..0e0cc868a3622 100644 --- a/templates/rag-timescale-hybrid-search-time/rag_timescale_hybrid_search_time/chain.py +++ b/templates/rag-timescale-hybrid-search-time/rag_timescale_hybrid_search_time/chain.py @@ -9,9 +9,9 @@ from langchain.llms import OpenAI from langchain.prompts import ChatPromptTemplate from langchain.retrievers.self_query.base import SelfQueryRetriever -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores.timescalevector import TimescaleVector +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import RunnableParallel, RunnablePassthrough from pydantic import BaseModel from .load_sample_dataset import load_ts_git_dataset diff --git a/templates/rag-vectara-multiquery/rag_vectara_multiquery/chain.py b/templates/rag-vectara-multiquery/rag_vectara_multiquery/chain.py index 3085d33c3ae60..2a3640f1787a1 100644 --- a/templates/rag-vectara-multiquery/rag_vectara_multiquery/chain.py +++ b/templates/rag-vectara-multiquery/rag_vectara_multiquery/chain.py @@ -2,11 +2,11 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel from langchain.retrievers.multi_query import MultiQueryRetriever -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import Vectara +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough if os.environ.get("VECTARA_CUSTOMER_ID", None) is None: raise Exception("Missing `VECTARA_CUSTOMER_ID` environment variable.") diff --git a/templates/rag-vectara/rag_vectara/chain.py b/templates/rag-vectara/rag_vectara/chain.py index 2b760d2a98da4..f64cd8abd471e 100644 --- a/templates/rag-vectara/rag_vectara/chain.py +++ b/templates/rag-vectara/rag_vectara/chain.py @@ -2,10 +2,10 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores import Vectara +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough if os.environ.get("VECTARA_CUSTOMER_ID", None) is None: raise Exception("Missing `VECTARA_CUSTOMER_ID` environment variable.") diff --git a/templates/rag-weaviate/rag_weaviate/chain.py b/templates/rag-weaviate/rag_weaviate/chain.py index 8f128fbf8aaa5..0bb5044d57e85 100644 --- a/templates/rag-weaviate/rag_weaviate/chain.py +++ b/templates/rag-weaviate/rag_weaviate/chain.py @@ -4,11 +4,11 @@ from langchain.document_loaders import WebBaseLoader from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.vectorstores import Weaviate +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough if os.environ.get("WEAVIATE_API_KEY", None) is None: raise Exception("Missing `WEAVIATE_API_KEY` environment variable.") diff --git a/templates/research-assistant/research_assistant/chain.py b/templates/research-assistant/research_assistant/chain.py index 45a2c58b17961..c0414b00bcf89 100644 --- a/templates/research-assistant/research_assistant/chain.py +++ b/templates/research-assistant/research_assistant/chain.py @@ -1,5 +1,5 @@ -from langchain.pydantic_v1 import BaseModel -from langchain.schema.runnable import RunnablePassthrough +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnablePassthrough from research_assistant.search.web import chain as search_chain from research_assistant.writer import chain as writer_chain diff --git a/templates/research-assistant/research_assistant/search/web.py b/templates/research-assistant/research_assistant/search/web.py index be6e01fbbbee1..16db649104bc5 100644 --- a/templates/research-assistant/research_assistant/search/web.py +++ b/templates/research-assistant/research_assistant/search/web.py @@ -6,16 +6,16 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate from langchain.retrievers.tavily_search_api import TavilySearchAPIRetriever -from langchain.schema.messages import SystemMessage -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import ( +from langchain.utilities import DuckDuckGoSearchAPIWrapper +from langchain_core.messages import SystemMessage +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import ( ConfigurableField, Runnable, RunnableLambda, RunnableParallel, RunnablePassthrough, ) -from langchain.utilities import DuckDuckGoSearchAPIWrapper RESULTS_PER_QUESTION = 3 diff --git a/templates/research-assistant/research_assistant/writer.py b/templates/research-assistant/research_assistant/writer.py index 9af15f4b0d100..34a167a70b694 100644 --- a/templates/research-assistant/research_assistant/writer.py +++ b/templates/research-assistant/research_assistant/writer.py @@ -1,7 +1,7 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import ConfigurableField +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import ConfigurableField WRITER_SYSTEM_PROMPT = "You are an AI critical thinker research assistant. Your sole purpose is to write well written, critically acclaimed, objective and structured reports on given text." # noqa: E501 diff --git a/templates/retrieval-agent/retrieval_agent/chain.py b/templates/retrieval-agent/retrieval_agent/chain.py index 4c548fb064e88..c0fb6f798f8a7 100644 --- a/templates/retrieval-agent/retrieval_agent/chain.py +++ b/templates/retrieval-agent/retrieval_agent/chain.py @@ -7,12 +7,12 @@ from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.chat_models import AzureChatOpenAI from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder -from langchain.pydantic_v1 import BaseModel, Field from langchain.schema import BaseRetriever, Document -from langchain.schema.messages import AIMessage, HumanMessage from langchain.tools.render import format_tool_to_openai_function from langchain.tools.retriever import create_retriever_tool from langchain.utilities.arxiv import ArxivAPIWrapper +from langchain_core.messages import AIMessage, HumanMessage +from langchain_core.pydantic_v1 import BaseModel, Field class ArxivRetriever(BaseRetriever, ArxivAPIWrapper): diff --git a/templates/rewrite-retrieve-read/rewrite_retrieve_read/chain.py b/templates/rewrite-retrieve-read/rewrite_retrieve_read/chain.py index 1ead011f0d890..996b9b1347c43 100644 --- a/templates/rewrite-retrieve-read/rewrite_retrieve_read/chain.py +++ b/templates/rewrite-retrieve-read/rewrite_retrieve_read/chain.py @@ -1,9 +1,9 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough from langchain.utilities import DuckDuckGoSearchAPIWrapper +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnablePassthrough template = """Answer the users question based only on the following context: diff --git a/templates/self-query-qdrant/self_query_qdrant/chain.py b/templates/self-query-qdrant/self_query_qdrant/chain.py index 3b673d2d3241d..73e46b525aa73 100644 --- a/templates/self-query-qdrant/self_query_qdrant/chain.py +++ b/templates/self-query-qdrant/self_query_qdrant/chain.py @@ -5,12 +5,12 @@ from langchain.embeddings import OpenAIEmbeddings from langchain.llms import BaseLLM from langchain.llms.openai import OpenAI -from langchain.pydantic_v1 import BaseModel from langchain.retrievers import SelfQueryRetriever from langchain.schema import Document, StrOutputParser -from langchain.schema.embeddings import Embeddings -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores.qdrant import Qdrant +from langchain_core.embeddings import Embeddings +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableParallel, RunnablePassthrough from qdrant_client import QdrantClient from self_query_qdrant import defaults, helper, prompts diff --git a/templates/self-query-supabase/self_query_supabase/chain.py b/templates/self-query-supabase/self_query_supabase/chain.py index eca0c0e82c4b8..1bd87d8da65ca 100644 --- a/templates/self-query-supabase/self_query_supabase/chain.py +++ b/templates/self-query-supabase/self_query_supabase/chain.py @@ -4,8 +4,8 @@ from langchain.embeddings import OpenAIEmbeddings from langchain.llms.openai import OpenAI from langchain.retrievers.self_query.base import SelfQueryRetriever -from langchain.schema.runnable import RunnableParallel, RunnablePassthrough from langchain.vectorstores.supabase import SupabaseVectorStore +from langchain_core.runnables import RunnableParallel, RunnablePassthrough from supabase.client import create_client supabase_url = os.environ.get("SUPABASE_URL") diff --git a/templates/skeleton-of-thought/skeleton_of_thought/chain.py b/templates/skeleton-of-thought/skeleton_of_thought/chain.py index 67a950307b55a..d0184e215d24d 100644 --- a/templates/skeleton-of-thought/skeleton_of_thought/chain.py +++ b/templates/skeleton-of-thought/skeleton_of_thought/chain.py @@ -1,8 +1,8 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnablePassthrough skeleton_generator_template = """[User:] You’re an organizer responsible for only \ giving the skeleton (not the full content) for answering the question. diff --git a/templates/solo-performance-prompting-agent/solo_performance_prompting_agent/agent.py b/templates/solo-performance-prompting-agent/solo_performance_prompting_agent/agent.py index c7817f3e9ef0a..ac59eb3f1f1e0 100644 --- a/templates/solo-performance-prompting-agent/solo_performance_prompting_agent/agent.py +++ b/templates/solo-performance-prompting-agent/solo_performance_prompting_agent/agent.py @@ -1,9 +1,9 @@ from langchain.agents import AgentExecutor from langchain.agents.format_scratchpad import format_xml from langchain.llms import OpenAI -from langchain.pydantic_v1 import BaseModel from langchain.tools import DuckDuckGoSearchRun from langchain.tools.render import render_text_description +from langchain_core.pydantic_v1 import BaseModel from solo_performance_prompting_agent.parser import parse_output from solo_performance_prompting_agent.prompts import conversational_prompt diff --git a/templates/sql-llama2/sql_llama2/chain.py b/templates/sql-llama2/sql_llama2/chain.py index d81bed0dc40bd..bfec939734431 100644 --- a/templates/sql-llama2/sql_llama2/chain.py +++ b/templates/sql-llama2/sql_llama2/chain.py @@ -2,10 +2,10 @@ from langchain.llms import Replicate from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnablePassthrough from langchain.utilities import SQLDatabase +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnablePassthrough # make sure to set REPLICATE_API_TOKEN in your environment # use llama-2-13b model in replicate diff --git a/templates/sql-llamacpp/sql_llamacpp/chain.py b/templates/sql-llamacpp/sql_llamacpp/chain.py index 9a62faf396667..6ca92567e0726 100644 --- a/templates/sql-llamacpp/sql_llamacpp/chain.py +++ b/templates/sql-llamacpp/sql_llamacpp/chain.py @@ -6,10 +6,10 @@ from langchain.llms import LlamaCpp from langchain.memory import ConversationBufferMemory from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableLambda, RunnablePassthrough from langchain.utilities import SQLDatabase +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableLambda, RunnablePassthrough # File name and URL file_name = "mistral-7b-instruct-v0.1.Q4_K_M.gguf" diff --git a/templates/sql-ollama/sql_ollama/chain.py b/templates/sql-ollama/sql_ollama/chain.py index aea56b50f74da..2a32d954f0629 100644 --- a/templates/sql-ollama/sql_ollama/chain.py +++ b/templates/sql-ollama/sql_ollama/chain.py @@ -3,10 +3,10 @@ from langchain.chat_models import ChatOllama from langchain.memory import ConversationBufferMemory from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableLambda, RunnablePassthrough from langchain.utilities import SQLDatabase +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableLambda, RunnablePassthrough # Add the LLM downloaded from Ollama ollama_llm = "zephyr" diff --git a/templates/sql-pgvector/sql_pgvector/chain.py b/templates/sql-pgvector/sql_pgvector/chain.py index 0b4c1fc825346..542a65781240e 100644 --- a/templates/sql-pgvector/sql_pgvector/chain.py +++ b/templates/sql-pgvector/sql_pgvector/chain.py @@ -4,10 +4,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import ChatPromptTemplate -from langchain.pydantic_v1 import BaseModel -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableLambda, RunnablePassthrough from langchain.sql_database import SQLDatabase +from langchain_core.output_parsers import StrOutputParser +from langchain_core.pydantic_v1 import BaseModel +from langchain_core.runnables import RunnableLambda, RunnablePassthrough from sql_pgvector.prompt_templates import final_template, postgresql_template diff --git a/templates/stepback-qa-prompting/stepback_qa_prompting/chain.py b/templates/stepback-qa-prompting/stepback_qa_prompting/chain.py index f25802ef264fe..eb3c6c87b5bb3 100644 --- a/templates/stepback-qa-prompting/stepback_qa_prompting/chain.py +++ b/templates/stepback-qa-prompting/stepback_qa_prompting/chain.py @@ -1,8 +1,8 @@ from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate, FewShotChatMessagePromptTemplate -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableLambda from langchain.utilities import DuckDuckGoSearchAPIWrapper +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import RunnableLambda search = DuckDuckGoSearchAPIWrapper(max_results=4) diff --git a/templates/summarize-anthropic/summarize_anthropic/chain.py b/templates/summarize-anthropic/summarize_anthropic/chain.py index 80a809c6375df..36c8a3e2b054c 100644 --- a/templates/summarize-anthropic/summarize_anthropic/chain.py +++ b/templates/summarize-anthropic/summarize_anthropic/chain.py @@ -1,6 +1,6 @@ from langchain import hub from langchain.chat_models import ChatAnthropic -from langchain.schema.output_parser import StrOutputParser +from langchain_core.output_parsers import StrOutputParser # Create chain prompt = hub.pull("hwchase17/anthropic-paper-qa") diff --git a/templates/xml-agent/xml_agent/agent.py b/templates/xml-agent/xml_agent/agent.py index a7eb97d3fd40b..dad89a1cf59fe 100644 --- a/templates/xml-agent/xml_agent/agent.py +++ b/templates/xml-agent/xml_agent/agent.py @@ -3,10 +3,10 @@ from langchain.agents import AgentExecutor from langchain.agents.format_scratchpad import format_xml from langchain.chat_models import ChatAnthropic -from langchain.pydantic_v1 import BaseModel, Field from langchain.schema import AIMessage, HumanMessage from langchain.tools import DuckDuckGoSearchRun from langchain.tools.render import render_text_description +from langchain_core.pydantic_v1 import BaseModel, Field from xml_agent.prompts import conversational_prompt, parse_output