Skip to content

Commit

Permalink
langchain[patch], experimental[patch]: replace langchain.schema impor…
Browse files Browse the repository at this point in the history
…ts (langchain-ai#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
```
  • Loading branch information
baskaryan authored Jan 2, 2024
1 parent a3d47b4 commit 8e0d581
Show file tree
Hide file tree
Showing 47 changed files with 81 additions and 80 deletions.
8 changes: 4 additions & 4 deletions cookbook/Multi_modal_RAG_google.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/chat/google_generative_ai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrations/llms/google_vertex_ai_palm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/providers/cohere.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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?"))
Expand All @@ -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?"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/retrievers/fleet_context.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/integrations/vectorstores/jaguar.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion libs/core/langchain_core/runnables/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
2 changes: 1 addition & 1 deletion libs/experimental/langchain_experimental/llm_bash/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ChatGeneration,
ChatResult,
)
from langchain.schema.messages import (
from langchain_core.messages import (
AIMessage,
BaseMessage,
SystemMessage,
Expand Down
2 changes: 1 addition & 1 deletion libs/experimental/langchain_experimental/llms/llamaapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ChatGeneration,
ChatResult,
)
from langchain.schema.messages import (
from langchain_core.messages import (
AIMessage,
BaseMessage,
ChatMessage,
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion libs/experimental/langchain_experimental/pal_chain/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion libs/experimental/langchain_experimental/sql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions libs/experimental/langchain_experimental/sql/vector_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions libs/langchain/langchain/chains/ernie_functions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 = {
Expand Down
Loading

0 comments on commit 8e0d581

Please sign in to comment.