From 8e0d5813c25c19bb26bd4e0da6a60d052a86da47 Mon Sep 17 00:00:00 2001 From: Bagatur <22008038+baskaryan@users.noreply.github.com> Date: Tue, 2 Jan 2024 15:09:45 -0500 Subject: [PATCH] langchain[patch], experimental[patch]: replace langchain.schema imports (#15410) Import from core instead. Ran: ```bash git grep -l 'from langchain.schema\.output_parser' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.output_parser/from\ langchain_core.output_parsers/g" git grep -l 'from langchain.schema\.messages' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.messages/from\ langchain_core.messages/g" git grep -l 'from langchain.schema\.document' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.document/from\ langchain_core.documents/g" git grep -l 'from langchain.schema\.runnable' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.runnable/from\ langchain_core.runnables/g" git grep -l 'from langchain.schema\.vectorstore' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.vectorstore/from\ langchain_core.vectorstores/g" git grep -l 'from langchain.schema\.language_model' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.language_model/from\ langchain_core.language_models/g" git grep -l 'from langchain.schema\.embeddings' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.embeddings/from\ langchain_core.embeddings/g" git grep -l 'from langchain.schema\.storage' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.storage/from\ langchain_core.stores/g" git checkout master libs/langchain/tests/unit_tests/schema/ make format cd libs/experimental make format cd ../langchain make format ``` --- cookbook/Multi_modal_RAG_google.ipynb | 8 ++++---- docs/docs/integrations/chat/google_generative_ai.ipynb | 2 +- docs/docs/integrations/llms/google_vertex_ai_palm.ipynb | 2 +- docs/docs/integrations/providers/cohere.mdx | 4 ++-- .../integrations/providers/vectara/vectara_summary.ipynb | 6 +++--- docs/docs/integrations/retrievers/fleet_context.ipynb | 4 ++-- docs/docs/integrations/vectorstores/jaguar.ipynb | 4 ++-- libs/core/langchain_core/runnables/base.py | 2 +- .../agents/agent_toolkits/csv/base.py | 2 +- .../agents/agent_toolkits/pandas/base.py | 4 ++-- .../agents/agent_toolkits/python/base.py | 4 ++-- .../autonomous_agents/autogpt/agent.py | 4 ++-- .../autonomous_agents/autogpt/memory.py | 2 +- .../autonomous_agents/autogpt/prompt.py | 4 ++-- .../autonomous_agents/baby_agi/baby_agi.py | 4 ++-- .../autonomous_agents/baby_agi/task_creation.py | 2 +- .../autonomous_agents/baby_agi/task_execution.py | 2 +- .../autonomous_agents/baby_agi/task_prioritization.py | 2 +- .../langchain_experimental/fallacy_removal/base.py | 2 +- .../generative_agents/generative_agent.py | 2 +- .../langchain_experimental/generative_agents/memory.py | 2 +- libs/experimental/langchain_experimental/llm_bash/base.py | 2 +- .../langchain_experimental/llms/anthropic_functions.py | 2 +- libs/experimental/langchain_experimental/llms/llamaapi.py | 2 +- .../langchain_experimental/open_clip/open_clip.py | 2 +- .../experimental/langchain_experimental/pal_chain/base.py | 2 +- .../plan_and_execute/executors/agent_executor.py | 2 +- .../plan_and_execute/planners/chat_planner.py | 4 ++-- libs/experimental/langchain_experimental/sql/base.py | 2 +- .../experimental/langchain_experimental/sql/vector_sql.py | 4 ++-- .../langchain_experimental/synthetic_data/__init__.py | 2 +- .../langchain_experimental/tabular_synthetic_data/base.py | 2 +- libs/langchain/langchain/chains/ernie_functions/base.py | 5 +++-- .../langchain/langchain/output_parsers/ernie_functions.py | 8 ++++---- libs/langchain/tests/unit_tests/agents/test_agent.py | 2 +- .../langchain/tests/unit_tests/agents/test_agent_async.py | 2 +- templates/bedrock-jcvd/bedrock_jcvd/chain.py | 2 +- templates/cohere-librarian/cohere_librarian/router.py | 4 ++-- templates/python-lint/python_lint/agent_executor.py | 2 +- templates/rag-chroma-multi-modal-multi-vector/ingest.py | 4 ++-- .../rag_chroma_multi_modal_multi_vector/chain.py | 8 ++++---- templates/rag-multi-modal-mv-local/ingest.py | 4 ++-- .../rag_multi_modal_mv_local/chain.py | 8 ++++---- .../sql_research_assistant/chain.py | 2 +- .../sql_research_assistant/search/sql.py | 4 ++-- .../sql_research_assistant/search/web.py | 8 ++++---- .../sql_research_assistant/writer.py | 4 ++-- 47 files changed, 81 insertions(+), 80 deletions(-) diff --git a/cookbook/Multi_modal_RAG_google.ipynb b/cookbook/Multi_modal_RAG_google.ipynb index 741ddefea2e62..568c14998bede 100644 --- a/cookbook/Multi_modal_RAG_google.ipynb +++ b/cookbook/Multi_modal_RAG_google.ipynb @@ -161,8 +161,8 @@ "from langchain.chat_models import ChatVertexAI\n", "from langchain.llms import VertexAI\n", "from langchain.prompts import PromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", "from langchain_core.messages import AIMessage\n", + "from langchain_core.output_parsers import StrOutputParser\n", "from langchain_core.runnables import RunnableLambda\n", "\n", "\n", @@ -243,7 +243,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", @@ -344,9 +344,9 @@ "\n", "from langchain.embeddings import VertexAIEmbeddings\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", @@ -440,7 +440,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/docs/docs/integrations/chat/google_generative_ai.ipynb b/docs/docs/integrations/chat/google_generative_ai.ipynb index c3f3f2f56a279..94a4671ae91a1 100644 --- a/docs/docs/integrations/chat/google_generative_ai.ipynb +++ b/docs/docs/integrations/chat/google_generative_ai.ipynb @@ -151,7 +151,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.messages import HumanMessage, SystemMessage\n", + "from langchain_core.messages import HumanMessage, SystemMessage\n", "\n", "model = ChatGoogleGenerativeAI(model=\"gemini-pro\", convert_system_message_to_human=True)\n", "model(\n", diff --git a/docs/docs/integrations/llms/google_vertex_ai_palm.ipynb b/docs/docs/integrations/llms/google_vertex_ai_palm.ipynb index f93a254475e34..c61a6ed04f2df 100644 --- a/docs/docs/integrations/llms/google_vertex_ai_palm.ipynb +++ b/docs/docs/integrations/llms/google_vertex_ai_palm.ipynb @@ -415,7 +415,7 @@ ], "source": [ "from langchain.chat_models import ChatVertexAI\n", - "from langchain.schema.messages import HumanMessage\n", + "from langchain_core.messages import HumanMessage\n", "\n", "llm = ChatVertexAI(model_name=\"gemini-ultra-vision\")\n", "\n", diff --git a/docs/docs/integrations/providers/cohere.mdx b/docs/docs/integrations/providers/cohere.mdx index 4fe6a4364210b..de409d08f80b9 100644 --- a/docs/docs/integrations/providers/cohere.mdx +++ b/docs/docs/integrations/providers/cohere.mdx @@ -49,7 +49,7 @@ print(llm.invoke("Come up with a pet name")) ```python from langchain.chat_models import ChatCohere from langchain.retrievers import CohereRagRetriever -from langchain.schema.document import Document +from langchain_core.documents import Document rag = CohereRagRetriever(llm=ChatCohere()) print(rag.get_relevant_documents("What is cohere ai?")) @@ -60,7 +60,7 @@ print(rag.get_relevant_documents("What is cohere ai?")) ```python from langchain.chat_models import ChatCohere from langchain.retrievers import CohereRagRetriever -from langchain.schema.document import Document +from langchain_core.documents import Document rag = CohereRagRetriever(llm=ChatCohere()) print(rag.get_relevant_documents("What is cohere ai?")) diff --git a/docs/docs/integrations/providers/vectara/vectara_summary.ipynb b/docs/docs/integrations/providers/vectara/vectara_summary.ipynb index b41e7e5280ea2..837341b43c07b 100644 --- a/docs/docs/integrations/providers/vectara/vectara_summary.ipynb +++ b/docs/docs/integrations/providers/vectara/vectara_summary.ipynb @@ -76,9 +76,9 @@ "source": [ "from langchain.embeddings import FakeEmbeddings\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 Vectara" + "from langchain.vectorstores import Vectara\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnableLambda, RunnablePassthrough" ] }, { diff --git a/docs/docs/integrations/retrievers/fleet_context.ipynb b/docs/docs/integrations/retrievers/fleet_context.ipynb index d5e97c04e71fe..f15645fdbb63d 100644 --- a/docs/docs/integrations/retrievers/fleet_context.ipynb +++ b/docs/docs/integrations/retrievers/fleet_context.ipynb @@ -36,9 +36,9 @@ "from langchain.embeddings import OpenAIEmbeddings\n", "from langchain.retrievers import MultiVectorRetriever\n", "from langchain.schema import Document\n", - "from langchain.schema.storage import BaseStore\n", - "from langchain.schema.vectorstore import VectorStore\n", "from langchain.vectorstores import FAISS\n", + "from langchain_core.stores import BaseStore\n", + "from langchain_core.vectorstores import VectorStore\n", "\n", "\n", "def load_fleet_retriever(\n", diff --git a/docs/docs/integrations/vectorstores/jaguar.ipynb b/docs/docs/integrations/vectorstores/jaguar.ipynb index 9d817ed768285..03797457e7310 100644 --- a/docs/docs/integrations/vectorstores/jaguar.ipynb +++ b/docs/docs/integrations/vectorstores/jaguar.ipynb @@ -58,10 +58,10 @@ "from langchain.embeddings.openai import OpenAIEmbeddings\n", "from langchain.llms import OpenAI\n", "from langchain.prompts import ChatPromptTemplate\n", - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain_community.vectorstores.jaguar import Jaguar\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "\"\"\" \n", "Load a text file into a set of documents \n", diff --git a/libs/core/langchain_core/runnables/base.py b/libs/core/langchain_core/runnables/base.py index 27ee8409a7166..5bf6e8d98cd22 100644 --- a/libs/core/langchain_core/runnables/base.py +++ b/libs/core/langchain_core/runnables/base.py @@ -3556,7 +3556,7 @@ class RunnableBinding(RunnableBindingBase[Input, Output]): .. code-block:: python - from langchain.schema.runnable import RunnableBinding + from langchain_core.runnables import RunnableBinding runnable_binding = RunnableBinding( bound=model, kwargs={'stop': ['-']} # <-- Note the additional kwargs diff --git a/libs/experimental/langchain_experimental/agents/agent_toolkits/csv/base.py b/libs/experimental/langchain_experimental/agents/agent_toolkits/csv/base.py index 36cf453c38b81..8691aed0fea02 100644 --- a/libs/experimental/langchain_experimental/agents/agent_toolkits/csv/base.py +++ b/libs/experimental/langchain_experimental/agents/agent_toolkits/csv/base.py @@ -2,7 +2,7 @@ from typing import Any, List, Optional, Union from langchain.agents.agent import AgentExecutor -from langchain.schema.language_model import BaseLanguageModel +from langchain_core.language_models import BaseLanguageModel from langchain_experimental.agents.agent_toolkits.pandas.base import ( create_pandas_dataframe_agent, diff --git a/libs/experimental/langchain_experimental/agents/agent_toolkits/pandas/base.py b/libs/experimental/langchain_experimental/agents/agent_toolkits/pandas/base.py index cc5205a3dcc83..1ab58c20c0dd1 100644 --- a/libs/experimental/langchain_experimental/agents/agent_toolkits/pandas/base.py +++ b/libs/experimental/langchain_experimental/agents/agent_toolkits/pandas/base.py @@ -8,9 +8,9 @@ from langchain.callbacks.base import BaseCallbackManager from langchain.chains.llm import LLMChain from langchain.schema import BasePromptTemplate -from langchain.schema.language_model import BaseLanguageModel -from langchain.schema.messages import SystemMessage from langchain.tools import BaseTool +from langchain_core.language_models import BaseLanguageModel +from langchain_core.messages import SystemMessage from langchain_experimental.agents.agent_toolkits.pandas.prompt import ( FUNCTIONS_WITH_DF, diff --git a/libs/experimental/langchain_experimental/agents/agent_toolkits/python/base.py b/libs/experimental/langchain_experimental/agents/agent_toolkits/python/base.py index 10d9632357d84..6a7e65125a3fc 100644 --- a/libs/experimental/langchain_experimental/agents/agent_toolkits/python/base.py +++ b/libs/experimental/langchain_experimental/agents/agent_toolkits/python/base.py @@ -8,8 +8,8 @@ from langchain.agents.types import AgentType from langchain.callbacks.base import BaseCallbackManager from langchain.chains.llm import LLMChain -from langchain.schema.language_model import BaseLanguageModel -from langchain.schema.messages import SystemMessage +from langchain_core.language_models import BaseLanguageModel +from langchain_core.messages import SystemMessage from langchain_experimental.agents.agent_toolkits.python.prompt import PREFIX from langchain_experimental.tools.python.tool import PythonREPLTool diff --git a/libs/experimental/langchain_experimental/autonomous_agents/autogpt/agent.py b/libs/experimental/langchain_experimental/autonomous_agents/autogpt/agent.py index bffd6b2c21c62..35cbc6c44c620 100644 --- a/libs/experimental/langchain_experimental/autonomous_agents/autogpt/agent.py +++ b/libs/experimental/langchain_experimental/autonomous_agents/autogpt/agent.py @@ -9,10 +9,10 @@ BaseChatMessageHistory, Document, ) -from langchain.schema.messages import AIMessage, HumanMessage, SystemMessage -from langchain.schema.vectorstore import VectorStoreRetriever from langchain.tools.base import BaseTool from langchain.tools.human.tool import HumanInputRun +from langchain_core.messages import AIMessage, HumanMessage, SystemMessage +from langchain_core.vectorstores import VectorStoreRetriever from langchain_experimental.autonomous_agents.autogpt.output_parser import ( AutoGPTOutputParser, diff --git a/libs/experimental/langchain_experimental/autonomous_agents/autogpt/memory.py b/libs/experimental/langchain_experimental/autonomous_agents/autogpt/memory.py index 41f8339b1e69f..c59e326a5cecf 100644 --- a/libs/experimental/langchain_experimental/autonomous_agents/autogpt/memory.py +++ b/libs/experimental/langchain_experimental/autonomous_agents/autogpt/memory.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List from langchain.memory.chat_memory import BaseChatMemory, get_prompt_input_key -from langchain.schema.vectorstore import VectorStoreRetriever +from langchain_core.vectorstores import VectorStoreRetriever from langchain_experimental.pydantic_v1 import Field diff --git a/libs/experimental/langchain_experimental/autonomous_agents/autogpt/prompt.py b/libs/experimental/langchain_experimental/autonomous_agents/autogpt/prompt.py index 83fd495ff8da5..7a5b4c831b8c3 100644 --- a/libs/experimental/langchain_experimental/autonomous_agents/autogpt/prompt.py +++ b/libs/experimental/langchain_experimental/autonomous_agents/autogpt/prompt.py @@ -4,9 +4,9 @@ from langchain.prompts.chat import ( BaseChatPromptTemplate, ) -from langchain.schema.messages import BaseMessage, HumanMessage, SystemMessage -from langchain.schema.vectorstore import VectorStoreRetriever from langchain.tools.base import BaseTool +from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage +from langchain_core.vectorstores import VectorStoreRetriever from langchain_experimental.autonomous_agents.autogpt.prompt_generator import get_prompt from langchain_experimental.pydantic_v1 import BaseModel diff --git a/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/baby_agi.py b/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/baby_agi.py index a8247417ff009..13caa93705757 100644 --- a/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/baby_agi.py +++ b/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/baby_agi.py @@ -4,8 +4,8 @@ from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain -from langchain.schema.language_model import BaseLanguageModel -from langchain.schema.vectorstore import VectorStore +from langchain_core.language_models import BaseLanguageModel +from langchain_core.vectorstores import VectorStore from langchain_experimental.autonomous_agents.baby_agi.task_creation import ( TaskCreationChain, diff --git a/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_creation.py b/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_creation.py index ad9cbc35c2f5b..a22041fd56c8f 100644 --- a/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_creation.py +++ b/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_creation.py @@ -1,6 +1,6 @@ from langchain.chains import LLMChain from langchain.prompts import PromptTemplate -from langchain.schema.language_model import BaseLanguageModel +from langchain_core.language_models import BaseLanguageModel class TaskCreationChain(LLMChain): diff --git a/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_execution.py b/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_execution.py index 62f7406295bec..044a2b7eb6b71 100644 --- a/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_execution.py +++ b/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_execution.py @@ -1,6 +1,6 @@ from langchain.chains import LLMChain from langchain.prompts import PromptTemplate -from langchain.schema.language_model import BaseLanguageModel +from langchain_core.language_models import BaseLanguageModel class TaskExecutionChain(LLMChain): diff --git a/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_prioritization.py b/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_prioritization.py index b8c669475e945..670576ae14674 100644 --- a/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_prioritization.py +++ b/libs/experimental/langchain_experimental/autonomous_agents/baby_agi/task_prioritization.py @@ -1,6 +1,6 @@ from langchain.chains import LLMChain from langchain.prompts import PromptTemplate -from langchain.schema.language_model import BaseLanguageModel +from langchain_core.language_models import BaseLanguageModel class TaskPrioritizationChain(LLMChain): diff --git a/libs/experimental/langchain_experimental/fallacy_removal/base.py b/libs/experimental/langchain_experimental/fallacy_removal/base.py index df897bcf4255e..8979d00135edf 100644 --- a/libs/experimental/langchain_experimental/fallacy_removal/base.py +++ b/libs/experimental/langchain_experimental/fallacy_removal/base.py @@ -7,7 +7,7 @@ from langchain.chains.base import Chain from langchain.chains.llm import LLMChain from langchain.schema import BasePromptTemplate -from langchain.schema.language_model import BaseLanguageModel +from langchain_core.language_models import BaseLanguageModel from langchain_experimental.fallacy_removal.fallacies import FALLACIES from langchain_experimental.fallacy_removal.models import LogicalFallacy diff --git a/libs/experimental/langchain_experimental/generative_agents/generative_agent.py b/libs/experimental/langchain_experimental/generative_agents/generative_agent.py index 8fcc4b8413c8c..2aca90162302b 100644 --- a/libs/experimental/langchain_experimental/generative_agents/generative_agent.py +++ b/libs/experimental/langchain_experimental/generative_agents/generative_agent.py @@ -4,7 +4,7 @@ from langchain.chains import LLMChain from langchain.prompts import PromptTemplate -from langchain.schema.language_model import BaseLanguageModel +from langchain_core.language_models import BaseLanguageModel from langchain_experimental.generative_agents.memory import GenerativeAgentMemory from langchain_experimental.pydantic_v1 import BaseModel, Field diff --git a/libs/experimental/langchain_experimental/generative_agents/memory.py b/libs/experimental/langchain_experimental/generative_agents/memory.py index adee72bfa0737..f95576675e03f 100644 --- a/libs/experimental/langchain_experimental/generative_agents/memory.py +++ b/libs/experimental/langchain_experimental/generative_agents/memory.py @@ -7,8 +7,8 @@ from langchain.prompts import PromptTemplate from langchain.retrievers import TimeWeightedVectorStoreRetriever from langchain.schema import BaseMemory, Document -from langchain.schema.language_model import BaseLanguageModel from langchain.utils import mock_now +from langchain_core.language_models import BaseLanguageModel logger = logging.getLogger(__name__) diff --git a/libs/experimental/langchain_experimental/llm_bash/base.py b/libs/experimental/langchain_experimental/llm_bash/base.py index 13cace9779ef0..f1fa97cbbcaa9 100644 --- a/libs/experimental/langchain_experimental/llm_bash/base.py +++ b/libs/experimental/langchain_experimental/llm_bash/base.py @@ -9,7 +9,7 @@ from langchain.chains.base import Chain from langchain.chains.llm import LLMChain from langchain.schema import BasePromptTemplate, OutputParserException -from langchain.schema.language_model import BaseLanguageModel +from langchain_core.language_models import BaseLanguageModel from langchain_experimental.llm_bash.bash import BashProcess from langchain_experimental.llm_bash.prompt import PROMPT diff --git a/libs/experimental/langchain_experimental/llms/anthropic_functions.py b/libs/experimental/langchain_experimental/llms/anthropic_functions.py index 3f5f8f51864db..3a18d734601ee 100644 --- a/libs/experimental/langchain_experimental/llms/anthropic_functions.py +++ b/libs/experimental/langchain_experimental/llms/anthropic_functions.py @@ -12,7 +12,7 @@ ChatGeneration, ChatResult, ) -from langchain.schema.messages import ( +from langchain_core.messages import ( AIMessage, BaseMessage, SystemMessage, diff --git a/libs/experimental/langchain_experimental/llms/llamaapi.py b/libs/experimental/langchain_experimental/llms/llamaapi.py index 9d2e79d2fe00d..2981c9e489bbf 100644 --- a/libs/experimental/langchain_experimental/llms/llamaapi.py +++ b/libs/experimental/langchain_experimental/llms/llamaapi.py @@ -15,7 +15,7 @@ ChatGeneration, ChatResult, ) -from langchain.schema.messages import ( +from langchain_core.messages import ( AIMessage, BaseMessage, ChatMessage, diff --git a/libs/experimental/langchain_experimental/open_clip/open_clip.py b/libs/experimental/langchain_experimental/open_clip/open_clip.py index f6c1cc5f64c65..6459522314d24 100644 --- a/libs/experimental/langchain_experimental/open_clip/open_clip.py +++ b/libs/experimental/langchain_experimental/open_clip/open_clip.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List from langchain.pydantic_v1 import BaseModel, root_validator -from langchain.schema.embeddings import Embeddings +from langchain_core.embeddings import Embeddings class OpenCLIPEmbeddings(BaseModel, Embeddings): diff --git a/libs/experimental/langchain_experimental/pal_chain/base.py b/libs/experimental/langchain_experimental/pal_chain/base.py index abadd85360e1f..71c7a7446d691 100644 --- a/libs/experimental/langchain_experimental/pal_chain/base.py +++ b/libs/experimental/langchain_experimental/pal_chain/base.py @@ -13,8 +13,8 @@ from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.chains.llm import LLMChain -from langchain.schema.language_model import BaseLanguageModel from langchain.utilities import PythonREPL +from langchain_core.language_models import BaseLanguageModel from langchain_experimental.pal_chain.colored_object_prompt import COLORED_OBJECT_PROMPT from langchain_experimental.pal_chain.math_prompt import MATH_PROMPT diff --git a/libs/experimental/langchain_experimental/plan_and_execute/executors/agent_executor.py b/libs/experimental/langchain_experimental/plan_and_execute/executors/agent_executor.py index 7ae770e199369..0f971deeb6f08 100644 --- a/libs/experimental/langchain_experimental/plan_and_execute/executors/agent_executor.py +++ b/libs/experimental/langchain_experimental/plan_and_execute/executors/agent_executor.py @@ -2,8 +2,8 @@ from langchain.agents.agent import AgentExecutor from langchain.agents.structured_chat.base import StructuredChatAgent -from langchain.schema.language_model import BaseLanguageModel from langchain.tools import BaseTool +from langchain_core.language_models import BaseLanguageModel from langchain_experimental.plan_and_execute.executors.base import ChainExecutor diff --git a/libs/experimental/langchain_experimental/plan_and_execute/planners/chat_planner.py b/libs/experimental/langchain_experimental/plan_and_execute/planners/chat_planner.py index 091b17561df13..4aad342ea6563 100644 --- a/libs/experimental/langchain_experimental/plan_and_execute/planners/chat_planner.py +++ b/libs/experimental/langchain_experimental/plan_and_execute/planners/chat_planner.py @@ -2,8 +2,8 @@ from langchain.chains import LLMChain from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate -from langchain.schema.language_model import BaseLanguageModel -from langchain.schema.messages import SystemMessage +from langchain_core.language_models import BaseLanguageModel +from langchain_core.messages import SystemMessage from langchain_experimental.plan_and_execute.planners.base import LLMPlanner from langchain_experimental.plan_and_execute.schema import ( diff --git a/libs/experimental/langchain_experimental/sql/base.py b/libs/experimental/langchain_experimental/sql/base.py index ce46e8e04a452..f7b0ac5152265 100644 --- a/libs/experimental/langchain_experimental/sql/base.py +++ b/libs/experimental/langchain_experimental/sql/base.py @@ -10,9 +10,9 @@ from langchain.chains.sql_database.prompt import DECIDER_PROMPT, PROMPT, SQL_PROMPTS from langchain.prompts.prompt import PromptTemplate from langchain.schema import BasePromptTemplate -from langchain.schema.language_model import BaseLanguageModel from langchain.tools.sql_database.prompt import QUERY_CHECKER from langchain.utilities.sql_database import SQLDatabase +from langchain_core.language_models import BaseLanguageModel from langchain_experimental.pydantic_v1 import Extra, Field, root_validator diff --git a/libs/experimental/langchain_experimental/sql/vector_sql.py b/libs/experimental/langchain_experimental/sql/vector_sql.py index 3ab08cbef53f4..396b48bba999f 100644 --- a/libs/experimental/langchain_experimental/sql/vector_sql.py +++ b/libs/experimental/langchain_experimental/sql/vector_sql.py @@ -8,10 +8,10 @@ from langchain.chains.sql_database.prompt import PROMPT, SQL_PROMPTS from langchain.prompts.prompt import PromptTemplate from langchain.schema import BaseOutputParser, BasePromptTemplate -from langchain.schema.embeddings import Embeddings -from langchain.schema.language_model import BaseLanguageModel from langchain.tools.sql_database.prompt import QUERY_CHECKER from langchain.utilities.sql_database import SQLDatabase +from langchain_core.embeddings import Embeddings +from langchain_core.language_models import BaseLanguageModel from langchain_experimental.sql.base import INTERMEDIATE_STEPS_KEY, SQLDatabaseChain diff --git a/libs/experimental/langchain_experimental/synthetic_data/__init__.py b/libs/experimental/langchain_experimental/synthetic_data/__init__.py index de07dfc0a7be3..e3325efb0dc2f 100644 --- a/libs/experimental/langchain_experimental/synthetic_data/__init__.py +++ b/libs/experimental/langchain_experimental/synthetic_data/__init__.py @@ -3,7 +3,7 @@ from langchain.chains.base import Chain from langchain.chains.llm import LLMChain from langchain.prompts import PromptTemplate -from langchain.schema.language_model import BaseLanguageModel +from langchain_core.language_models import BaseLanguageModel from langchain_experimental.synthetic_data.prompts import SENTENCE_PROMPT diff --git a/libs/experimental/langchain_experimental/tabular_synthetic_data/base.py b/libs/experimental/langchain_experimental/tabular_synthetic_data/base.py index 45932945c5132..9d67060609fa8 100644 --- a/libs/experimental/langchain_experimental/tabular_synthetic_data/base.py +++ b/libs/experimental/langchain_experimental/tabular_synthetic_data/base.py @@ -5,7 +5,7 @@ from langchain.chains.llm import LLMChain from langchain.prompts.few_shot import FewShotPromptTemplate from langchain.pydantic_v1 import BaseModel, root_validator -from langchain.schema.language_model import BaseLanguageModel +from langchain_core.language_models import BaseLanguageModel class SyntheticDataGenerator(BaseModel): diff --git a/libs/langchain/langchain/chains/ernie_functions/base.py b/libs/langchain/langchain/chains/ernie_functions/base.py index b8005665c7ffc..2f0924e3b3a92 100644 --- a/libs/langchain/langchain/chains/ernie_functions/base.py +++ b/libs/langchain/langchain/chains/ernie_functions/base.py @@ -13,6 +13,9 @@ cast, ) +from langchain_core.output_parsers import BaseGenerationOutputParser, BaseOutputParser +from langchain_core.runnables import Runnable + from langchain.base_language import BaseLanguageModel from langchain.chains import LLMChain from langchain.output_parsers.ernie_functions import ( @@ -23,8 +26,6 @@ from langchain.prompts import BasePromptTemplate from langchain.pydantic_v1 import BaseModel from langchain.schema import BaseLLMOutputParser -from langchain.schema.output_parser import BaseGenerationOutputParser, BaseOutputParser -from langchain.schema.runnable import Runnable from langchain.utils.ernie_functions import convert_pydantic_to_ernie_function PYTHON_TO_JSON_TYPES = { diff --git a/libs/langchain/langchain/output_parsers/ernie_functions.py b/libs/langchain/langchain/output_parsers/ernie_functions.py index dd5e45853454a..0bd481fa8c592 100644 --- a/libs/langchain/langchain/output_parsers/ernie_functions.py +++ b/libs/langchain/langchain/output_parsers/ernie_functions.py @@ -3,6 +3,10 @@ from typing import Any, Dict, List, Optional, Type, Union import jsonpatch +from langchain_core.output_parsers import ( + BaseCumulativeTransformOutputParser, + BaseGenerationOutputParser, +) from langchain.output_parsers.json import parse_partial_json from langchain.pydantic_v1 import BaseModel, root_validator @@ -11,10 +15,6 @@ Generation, OutputParserException, ) -from langchain.schema.output_parser import ( - BaseCumulativeTransformOutputParser, - BaseGenerationOutputParser, -) class OutputFunctionsParser(BaseGenerationOutputParser[Any]): diff --git a/libs/langchain/tests/unit_tests/agents/test_agent.py b/libs/langchain/tests/unit_tests/agents/test_agent.py index de0f772aac5a3..ca7fa9b1b559d 100644 --- a/libs/langchain/tests/unit_tests/agents/test_agent.py +++ b/libs/langchain/tests/unit_tests/agents/test_agent.py @@ -5,11 +5,11 @@ from langchain_core.agents import AgentAction, AgentStep from langchain_core.language_models.llms import LLM from langchain_core.messages import AIMessage, HumanMessage +from langchain_core.runnables.utils import add from langchain_core.tools import Tool from langchain.agents import AgentExecutor, AgentType, initialize_agent from langchain.callbacks.manager import CallbackManagerForLLMRun -from langchain.schema.runnable.utils import add from tests.unit_tests.callbacks.fake_callback_handler import FakeCallbackHandler diff --git a/libs/langchain/tests/unit_tests/agents/test_agent_async.py b/libs/langchain/tests/unit_tests/agents/test_agent_async.py index ce0372e3ffaaa..aeee034df7abe 100644 --- a/libs/langchain/tests/unit_tests/agents/test_agent_async.py +++ b/libs/langchain/tests/unit_tests/agents/test_agent_async.py @@ -5,11 +5,11 @@ from langchain_core.agents import AgentAction, AgentStep from langchain_core.language_models.llms import LLM from langchain_core.messages import AIMessage, HumanMessage +from langchain_core.runnables.utils import add from langchain_core.tools import Tool from langchain.agents import AgentExecutor, AgentType, initialize_agent from langchain.callbacks.manager import CallbackManagerForLLMRun -from langchain.schema.runnable.utils import add from tests.unit_tests.callbacks.fake_callback_handler import FakeCallbackHandler diff --git a/templates/bedrock-jcvd/bedrock_jcvd/chain.py b/templates/bedrock-jcvd/bedrock_jcvd/chain.py index a5e8265f468a8..def23e5541875 100644 --- a/templates/bedrock-jcvd/bedrock_jcvd/chain.py +++ b/templates/bedrock-jcvd/bedrock_jcvd/chain.py @@ -2,7 +2,7 @@ from langchain.chat_models import BedrockChat from langchain.prompts import ChatPromptTemplate -from langchain.schema.runnable import ConfigurableField +from langchain_core.runnables import ConfigurableField # For a description of each inference parameter, see # https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html diff --git a/templates/cohere-librarian/cohere_librarian/router.py b/templates/cohere-librarian/cohere_librarian/router.py index 7ab675e0391ae..6c094e4a3874b 100644 --- a/templates/cohere-librarian/cohere_librarian/router.py +++ b/templates/cohere-librarian/cohere_librarian/router.py @@ -1,6 +1,6 @@ from langchain.prompts import ChatPromptTemplate -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableBranch +from langchain_core.output_parsers import StrOutputParser +from langchain_core.runnables import RunnableBranch from .blurb_matcher import book_rec_chain from .chat import chat diff --git a/templates/python-lint/python_lint/agent_executor.py b/templates/python-lint/python_lint/agent_executor.py index 04b8304b6e42f..6a27385727c6c 100644 --- a/templates/python-lint/python_lint/agent_executor.py +++ b/templates/python-lint/python_lint/agent_executor.py @@ -9,7 +9,7 @@ from langchain.llms.base import BaseLLM from langchain.prompts import ChatPromptTemplate from langchain.pydantic_v1 import BaseModel, Field, ValidationError, validator -from langchain.schema.runnable import ConfigurableField, Runnable +from langchain_core.runnables import ConfigurableField, Runnable def strip_python_markdown_tags(text: str) -> str: diff --git a/templates/rag-chroma-multi-modal-multi-vector/ingest.py b/templates/rag-chroma-multi-modal-multi-vector/ingest.py index d9918a75545a4..ef8d9819721dc 100644 --- a/templates/rag-chroma-multi-modal-multi-vector/ingest.py +++ b/templates/rag-chroma-multi-modal-multi-vector/ingest.py @@ -9,10 +9,10 @@ from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.retrievers.multi_vector import MultiVectorRetriever -from langchain.schema.document import Document -from langchain.schema.messages import HumanMessage from langchain.storage import LocalFileStore, UpstashRedisByteStore from langchain.vectorstores import Chroma +from langchain_core.documents import Document +from langchain_core.messages import HumanMessage from PIL import Image diff --git a/templates/rag-chroma-multi-modal-multi-vector/rag_chroma_multi_modal_multi_vector/chain.py b/templates/rag-chroma-multi-modal-multi-vector/rag_chroma_multi_modal_multi_vector/chain.py index 39f448b297a55..f3cb84c1996e4 100644 --- a/templates/rag-chroma-multi-modal-multi-vector/rag_chroma_multi_modal_multi_vector/chain.py +++ b/templates/rag-chroma-multi-modal-multi-vector/rag_chroma_multi_modal_multi_vector/chain.py @@ -7,12 +7,12 @@ from langchain.embeddings import OpenAIEmbeddings from langchain.pydantic_v1 import BaseModel from langchain.retrievers.multi_vector import MultiVectorRetriever -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.storage import LocalFileStore, UpstashRedisByteStore 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.runnables import RunnableLambda, RunnablePassthrough from PIL import Image diff --git a/templates/rag-multi-modal-mv-local/ingest.py b/templates/rag-multi-modal-mv-local/ingest.py index 72c22b9b1bbf7..6b186c7b3b901 100644 --- a/templates/rag-multi-modal-mv-local/ingest.py +++ b/templates/rag-multi-modal-mv-local/ingest.py @@ -8,10 +8,10 @@ from langchain.chat_models import ChatOllama from langchain.embeddings import OllamaEmbeddings from langchain.retrievers.multi_vector import MultiVectorRetriever -from langchain.schema.document import Document -from langchain.schema.messages import HumanMessage from langchain.storage import LocalFileStore from langchain.vectorstores import Chroma +from langchain_core.documents import Document +from langchain_core.messages import HumanMessage from PIL import Image diff --git a/templates/rag-multi-modal-mv-local/rag_multi_modal_mv_local/chain.py b/templates/rag-multi-modal-mv-local/rag_multi_modal_mv_local/chain.py index 4808aacf0f740..e66064b2782f4 100644 --- a/templates/rag-multi-modal-mv-local/rag_multi_modal_mv_local/chain.py +++ b/templates/rag-multi-modal-mv-local/rag_multi_modal_mv_local/chain.py @@ -6,12 +6,12 @@ from langchain.embeddings import OllamaEmbeddings from langchain.pydantic_v1 import BaseModel from langchain.retrievers.multi_vector import MultiVectorRetriever -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.storage import LocalFileStore 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.runnables import RunnableLambda, RunnablePassthrough from PIL import Image diff --git a/templates/sql-research-assistant/sql_research_assistant/chain.py b/templates/sql-research-assistant/sql_research_assistant/chain.py index 43984719a3d89..d04e14efd8bc9 100644 --- a/templates/sql-research-assistant/sql_research_assistant/chain.py +++ b/templates/sql-research-assistant/sql_research_assistant/chain.py @@ -1,5 +1,5 @@ from langchain.pydantic_v1 import BaseModel -from langchain.schema.runnable import RunnablePassthrough +from langchain_core.runnables import RunnablePassthrough from sql_research_assistant.search.web import chain as search_chain from sql_research_assistant.writer import chain as writer_chain diff --git a/templates/sql-research-assistant/sql_research_assistant/search/sql.py b/templates/sql-research-assistant/sql_research_assistant/search/sql.py index cb976e2d2114e..25a68da050dd2 100644 --- a/templates/sql-research-assistant/sql_research_assistant/search/sql.py +++ b/templates/sql-research-assistant/sql_research_assistant/search/sql.py @@ -4,9 +4,9 @@ from langchain.memory import ConversationBufferMemory 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.runnables import RunnablePassthrough # Add the LLM downloaded from Ollama ollama_llm = "llama2" diff --git a/templates/sql-research-assistant/sql_research_assistant/search/web.py b/templates/sql-research-assistant/sql_research_assistant/search/web.py index eb84202febd38..929d4362d7aad 100644 --- a/templates/sql-research-assistant/sql_research_assistant/search/web.py +++ b/templates/sql-research-assistant/sql_research_assistant/search/web.py @@ -5,15 +5,15 @@ from bs4 import BeautifulSoup from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate -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 ( Runnable, RunnableLambda, RunnableParallel, RunnablePassthrough, ) -from langchain.utilities import DuckDuckGoSearchAPIWrapper from sql_research_assistant.search.sql import sql_answer_chain diff --git a/templates/sql-research-assistant/sql_research_assistant/writer.py b/templates/sql-research-assistant/sql_research_assistant/writer.py index 9af15f4b0d100..34a167a70b694 100644 --- a/templates/sql-research-assistant/sql_research_assistant/writer.py +++ b/templates/sql-research-assistant/sql_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