From 08d4bdd61aff6005070ce858fe85d0e40bf89d6c Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Mon, 29 Apr 2024 11:14:52 -0400 Subject: [PATCH] Migrate to locations of imports (#625) Migrate to new locations of imports --- examples/agent/server.py | 12 ++++++------ examples/agent_custom_streaming/server.py | 8 ++++---- examples/agent_with_history/server.py | 8 ++++---- examples/auth/api_handler/server.py | 2 +- examples/auth/per_req_config_modifier/server.py | 2 +- examples/chat_playground/legacy_input/server.py | 2 +- examples/chat_with_persistence/server.py | 4 ++-- examples/chat_with_persistence_and_user/server.py | 6 +++--- examples/configurable_agent_executor/server.py | 12 ++++++------ examples/configurable_chain/server.py | 8 ++++---- examples/configurable_retrieval/server.py | 15 ++++++++------- examples/conversational_retrieval_chain/server.py | 13 +++++-------- examples/file_processing/server.py | 6 +++--- examples/llm/server.py | 3 ++- examples/passthrough_dict/server.py | 8 ++++---- examples/retrieval/server.py | 4 ++-- examples/router/server.py | 3 ++- examples/widgets/chat/message_list/server.py | 2 +- examples/widgets/chat/tuples/server.py | 11 +++++------ 19 files changed, 64 insertions(+), 65 deletions(-) diff --git a/examples/agent/server.py b/examples/agent/server.py index 8a477884..2eb32fc1 100755 --- a/examples/agent/server.py +++ b/examples/agent/server.py @@ -20,15 +20,15 @@ from typing import Any from fastapi import FastAPI -from langchain.agents import AgentExecutor, tool +from langchain.agents import AgentExecutor from langchain.agents.format_scratchpad import format_to_openai_functions from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser -from langchain.chat_models import ChatOpenAI -from langchain.embeddings import OpenAIEmbeddings -from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder from langchain.pydantic_v1 import BaseModel -from langchain.tools.render import format_tool_to_openai_function -from langchain.vectorstores import FAISS +from langchain_community.vectorstores import FAISS +from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder +from langchain_core.tools import tool +from langchain_core.utils.function_calling import format_tool_to_openai_function +from langchain_openai import ChatOpenAI, OpenAIEmbeddings from langserve import add_routes diff --git a/examples/agent_custom_streaming/server.py b/examples/agent_custom_streaming/server.py index 90987983..736a0858 100755 --- a/examples/agent_custom_streaming/server.py +++ b/examples/agent_custom_streaming/server.py @@ -47,15 +47,15 @@ from typing import Any, AsyncIterator, List, Literal from fastapi import FastAPI -from langchain.agents import AgentExecutor, tool +from langchain.agents import AgentExecutor from langchain.agents.format_scratchpad.openai_tools import ( format_to_openai_tool_messages, ) from langchain.agents.output_parsers.openai_tools import OpenAIToolsAgentOutputParser -from langchain.prompts import MessagesPlaceholder -from langchain_community.tools.convert_to_openai import format_tool_to_openai_tool -from langchain_core.prompts import ChatPromptTemplate +from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder from langchain_core.runnables import RunnableLambda +from langchain_core.tools import tool +from langchain_core.utils.function_calling import format_tool_to_openai_tool from langchain_openai import ChatOpenAI from langserve import add_routes diff --git a/examples/agent_with_history/server.py b/examples/agent_with_history/server.py index d859d8f1..5435e1f3 100755 --- a/examples/agent_with_history/server.py +++ b/examples/agent_with_history/server.py @@ -26,15 +26,15 @@ from typing import Any, List, Union from fastapi import FastAPI -from langchain.agents import AgentExecutor, tool +from langchain.agents import AgentExecutor from langchain.agents.format_scratchpad.openai_tools import ( format_to_openai_tool_messages, ) from langchain.agents.output_parsers.openai_tools import OpenAIToolsAgentOutputParser -from langchain.prompts import MessagesPlaceholder -from langchain_community.tools.convert_to_openai import format_tool_to_openai_tool from langchain_core.messages import AIMessage, FunctionMessage, HumanMessage -from langchain_core.prompts import ChatPromptTemplate +from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder +from langchain_core.tools import tool +from langchain_core.utils.function_calling import format_tool_to_openai_tool from langchain_openai import ChatOpenAI from langserve import add_routes diff --git a/examples/auth/api_handler/server.py b/examples/auth/api_handler/server.py index 720115b7..862cbbe4 100755 --- a/examples/auth/api_handler/server.py +++ b/examples/auth/api_handler/server.py @@ -35,7 +35,6 @@ from fastapi import Depends, FastAPI, HTTPException, Request, Response, status from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm -from langchain_community.embeddings.openai import OpenAIEmbeddings from langchain_community.vectorstores.chroma import Chroma from langchain_core.documents import Document from langchain_core.runnables import ( @@ -44,6 +43,7 @@ RunnableSerializable, ) from langchain_core.vectorstores import VectorStore +from langchain_openai import OpenAIEmbeddings from typing_extensions import Annotated from langserve import APIHandler diff --git a/examples/auth/per_req_config_modifier/server.py b/examples/auth/per_req_config_modifier/server.py index 14e2c1c8..26f90e01 100755 --- a/examples/auth/per_req_config_modifier/server.py +++ b/examples/auth/per_req_config_modifier/server.py @@ -36,7 +36,6 @@ from fastapi import Depends, FastAPI, HTTPException, Request, status from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm -from langchain_community.embeddings.openai import OpenAIEmbeddings from langchain_community.vectorstores.chroma import Chroma from langchain_core.documents import Document from langchain_core.runnables import ( @@ -45,6 +44,7 @@ RunnableSerializable, ) from langchain_core.vectorstores import VectorStore +from langchain_openai import OpenAIEmbeddings from typing_extensions import Annotated from langserve import add_routes diff --git a/examples/chat_playground/legacy_input/server.py b/examples/chat_playground/legacy_input/server.py index 2d01dc26..415259b8 100644 --- a/examples/chat_playground/legacy_input/server.py +++ b/examples/chat_playground/legacy_input/server.py @@ -5,7 +5,7 @@ from typing import List, Union from fastapi import FastAPI -from langchain.chat_models import ChatAnthropic +from langchain_anthropic import ChatAnthropic from langchain_core.messages import AIMessage, HumanMessage, SystemMessage from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder diff --git a/examples/chat_with_persistence/server.py b/examples/chat_with_persistence/server.py index 82170ff7..b2c87e75 100755 --- a/examples/chat_with_persistence/server.py +++ b/examples/chat_with_persistence/server.py @@ -13,8 +13,8 @@ from typing import Callable, Union from fastapi import FastAPI, HTTPException -from langchain.chat_models import ChatAnthropic -from langchain.memory import FileChatMessageHistory +from langchain_anthropic import ChatAnthropic +from langchain_community.chat_message_histories import FileChatMessageHistory from langchain_core.chat_history import BaseChatMessageHistory from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder from langchain_core.runnables.history import RunnableWithMessageHistory diff --git a/examples/chat_with_persistence_and_user/server.py b/examples/chat_with_persistence_and_user/server.py index 97ea8673..ccb1eea6 100755 --- a/examples/chat_with_persistence_and_user/server.py +++ b/examples/chat_with_persistence_and_user/server.py @@ -13,13 +13,13 @@ from typing import Any, Callable, Dict, Union from fastapi import FastAPI, HTTPException, Request -from langchain.chat_models import ChatOpenAI -from langchain.memory import FileChatMessageHistory -from langchain.schema.runnable.utils import ConfigurableFieldSpec +from langchain_community.chat_message_histories import FileChatMessageHistory from langchain_core import __version__ from langchain_core.chat_history import BaseChatMessageHistory from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder +from langchain_core.runnables import ConfigurableFieldSpec from langchain_core.runnables.history import RunnableWithMessageHistory +from langchain_openai import ChatOpenAI from typing_extensions import TypedDict from langserve import add_routes diff --git a/examples/configurable_agent_executor/server.py b/examples/configurable_agent_executor/server.py index 3d425956..7ce73651 100755 --- a/examples/configurable_agent_executor/server.py +++ b/examples/configurable_agent_executor/server.py @@ -17,15 +17,12 @@ from typing import Any, AsyncIterator, Dict, List, Optional, cast from fastapi import FastAPI -from langchain.agents import AgentExecutor, tool +from langchain.agents import AgentExecutor from langchain.agents.format_scratchpad import format_to_openai_functions from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser -from langchain.chat_models import ChatOpenAI -from langchain.embeddings import OpenAIEmbeddings -from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder from langchain.pydantic_v1 import BaseModel -from langchain.tools.render import format_tool_to_openai_function -from langchain.vectorstores import FAISS +from langchain_community.vectorstores import FAISS +from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder from langchain_core.runnables import ( ConfigurableField, ConfigurableFieldSpec, @@ -33,6 +30,9 @@ RunnableConfig, ) from langchain_core.runnables.utils import Input, Output +from langchain_core.tools import tool +from langchain_core.utils.function_calling import format_tool_to_openai_function +from langchain_openai import ChatOpenAI, OpenAIEmbeddings from langserve import add_routes diff --git a/examples/configurable_chain/server.py b/examples/configurable_chain/server.py index a2fe2af8..4f7cc30f 100755 --- a/examples/configurable_chain/server.py +++ b/examples/configurable_chain/server.py @@ -10,10 +10,10 @@ from fastapi import FastAPI, HTTPException, Request from fastapi.middleware.cors import CORSMiddleware -from langchain.chat_models import ChatOpenAI -from langchain.prompts import PromptTemplate -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import ConfigurableField +from langchain_core.output_parsers import StrOutputParser +from langchain_core.prompts import PromptTemplate +from langchain_core.runnables import ConfigurableField +from langchain_openai import ChatOpenAI from langserve import add_routes diff --git a/examples/configurable_retrieval/server.py b/examples/configurable_retrieval/server.py index 0382e79e..c6e227cc 100755 --- a/examples/configurable_retrieval/server.py +++ b/examples/configurable_retrieval/server.py @@ -3,17 +3,18 @@ from typing import Any, Iterable, List, Optional, Type from fastapi import FastAPI -from langchain.embeddings import OpenAIEmbeddings -from langchain.schema import Document -from langchain.schema.embeddings import Embeddings -from langchain.schema.retriever import BaseRetriever -from langchain.schema.runnable import ( +from langchain.schema.vectorstore import VST +from langchain_community.vectorstores import FAISS +from langchain_core.documents import Document +from langchain_core.embeddings import Embeddings +from langchain_core.retrievers import BaseRetriever +from langchain_core.runnables import ( ConfigurableFieldSingleOption, RunnableConfig, RunnableSerializable, ) -from langchain.schema.vectorstore import VST -from langchain.vectorstores import FAISS, VectorStore +from langchain_core.vectorstores import VectorStore +from langchain_openai import OpenAIEmbeddings from langserve import add_routes from langserve.pydantic_v1 import BaseModel, Field diff --git a/examples/conversational_retrieval_chain/server.py b/examples/conversational_retrieval_chain/server.py index 47f4117f..e3cc1d95 100755 --- a/examples/conversational_retrieval_chain/server.py +++ b/examples/conversational_retrieval_chain/server.py @@ -13,14 +13,11 @@ from typing import List, Tuple from fastapi import FastAPI -from langchain.chat_models import ChatOpenAI -from langchain.embeddings import OpenAIEmbeddings -from langchain.prompts import ChatPromptTemplate -from langchain.prompts.prompt import PromptTemplate -from langchain.schema import format_document -from langchain.schema.output_parser import StrOutputParser -from langchain.schema.runnable import RunnableMap, RunnablePassthrough -from langchain.vectorstores import FAISS +from langchain_community.vectorstores import FAISS +from langchain_core.output_parsers import StrOutputParser +from langchain_core.prompts import ChatPromptTemplate, PromptTemplate, format_document +from langchain_core.runnables import RunnableMap, RunnablePassthrough +from langchain_openai import ChatOpenAI, OpenAIEmbeddings from langserve import add_routes from langserve.pydantic_v1 import BaseModel, Field diff --git a/examples/file_processing/server.py b/examples/file_processing/server.py index 07b19144..c3ee4a30 100755 --- a/examples/file_processing/server.py +++ b/examples/file_processing/server.py @@ -15,10 +15,10 @@ import base64 from fastapi import FastAPI -from langchain.document_loaders.blob_loaders import Blob -from langchain.document_loaders.parsers.pdf import PDFMinerParser from langchain.pydantic_v1 import Field -from langchain.schema.runnable import RunnableLambda +from langchain_community.document_loaders.parsers.pdf import PDFMinerParser +from langchain_core.document_loaders import Blob +from langchain_core.runnables import RunnableLambda from langserve import CustomUserType, add_routes diff --git a/examples/llm/server.py b/examples/llm/server.py index 0652db95..81999f30 100755 --- a/examples/llm/server.py +++ b/examples/llm/server.py @@ -2,7 +2,8 @@ """Example LangChain server exposes multiple runnables (LLMs in this case).""" from fastapi import FastAPI -from langchain.chat_models import ChatAnthropic, ChatOpenAI +from langchain_anthropic import ChatAnthropic +from langchain_openai import ChatOpenAI from langserve import add_routes diff --git a/examples/passthrough_dict/server.py b/examples/passthrough_dict/server.py index dfcca4e8..ec764862 100755 --- a/examples/passthrough_dict/server.py +++ b/examples/passthrough_dict/server.py @@ -4,9 +4,9 @@ from typing import Any, Callable, Dict, List, Optional, TypedDict from fastapi import FastAPI -from langchain.chat_models import ChatOpenAI -from langchain.prompts import ChatPromptTemplate -from langchain.schema.runnable import RunnableMap, RunnablePassthrough +from langchain_core.prompts import ChatPromptTemplate +from langchain_core.runnables import RunnableParallel, RunnablePassthrough +from langchain_openai import ChatOpenAI from langserve import add_routes @@ -43,7 +43,7 @@ def _project_dict( underlying_chain = prompt | model -wrapped_chain = RunnableMap( +wrapped_chain = RunnableParallel( { "output": _create_projection(exclude_keys=["info"]) | underlying_chain, "info": _create_projection(include_keys=["info"]), diff --git a/examples/retrieval/server.py b/examples/retrieval/server.py index 12663ed8..a13243f4 100755 --- a/examples/retrieval/server.py +++ b/examples/retrieval/server.py @@ -1,8 +1,8 @@ #!/usr/bin/env python """Example LangChain server exposes a retriever.""" from fastapi import FastAPI -from langchain.embeddings import OpenAIEmbeddings -from langchain.vectorstores import FAISS +from langchain_community.vectorstores import FAISS +from langchain_openai import OpenAIEmbeddings from langserve import add_routes diff --git a/examples/router/server.py b/examples/router/server.py index 7f51974b..985bea10 100755 --- a/examples/router/server.py +++ b/examples/router/server.py @@ -9,7 +9,8 @@ https://fastapi.tiangolo.com/tutorial/bigger-applications/ """ from fastapi import APIRouter, FastAPI -from langchain.chat_models import ChatAnthropic, ChatOpenAI +from langchain_anthropic import ChatAnthropic +from langchain_openai import ChatOpenAI from langserve import add_routes diff --git a/examples/widgets/chat/message_list/server.py b/examples/widgets/chat/message_list/server.py index b2c31465..bc23463b 100755 --- a/examples/widgets/chat/message_list/server.py +++ b/examples/widgets/chat/message_list/server.py @@ -6,7 +6,7 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware -from langchain.chat_models import ChatAnthropic +from langchain_anthropic import ChatAnthropic from langchain_core.messages import AIMessage, HumanMessage, SystemMessage from langchain_core.output_parsers import StrOutputParser from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder diff --git a/examples/widgets/chat/tuples/server.py b/examples/widgets/chat/tuples/server.py index 7aefc2a2..8f80b264 100755 --- a/examples/widgets/chat/tuples/server.py +++ b/examples/widgets/chat/tuples/server.py @@ -6,18 +6,17 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware -from langchain.chat_models.openai import ChatOpenAI -from langchain.document_loaders.blob_loaders import Blob -from langchain.document_loaders.parsers.pdf import PDFMinerParser from langchain.pydantic_v1 import BaseModel, Field -from langchain.schema.messages import ( +from langchain_community.document_loaders.parsers.pdf import PDFMinerParser +from langchain_core.document_loaders import Blob +from langchain_core.messages import ( AIMessage, BaseMessage, FunctionMessage, HumanMessage, ) -from langchain.schema.runnable import RunnableLambda -from langchain_core.runnables import RunnableParallel +from langchain_core.runnables import RunnableLambda, RunnableParallel +from langchain_openai import ChatOpenAI from langserve import CustomUserType from langserve.server import add_routes