From e512d3c6a64a305443d1cf9e5b0b0839691adfa4 Mon Sep 17 00:00:00 2001 From: Leonid Ganeline Date: Fri, 12 Apr 2024 13:13:14 -0700 Subject: [PATCH] langchain: `callbacks` imports fix (#20348) Replaced all `from langchain.callbacks` into `from langchain_core.callbacks` . Changes in the `langchain` and `langchain_experimental` --------- Co-authored-by: Erick Friis --- .../agents/agent_toolkits/python/base.py | 2 +- .../agents/agent_toolkits/spark/base.py | 2 +- .../agents/agent_toolkits/xorbits/base.py | 2 +- .../autonomous_agents/baby_agi/baby_agi.py | 2 +- .../autonomous_agents/hugginggpt/repsonse_generator.py | 2 +- .../autonomous_agents/hugginggpt/task_planner.py | 2 +- .../langchain_experimental/chat_models/llm_wrapper.py | 8 ++++---- .../amazon_comprehend_moderation.py | 2 +- .../comprehend_moderation/base_moderation.py | 2 +- libs/experimental/langchain_experimental/cpal/base.py | 2 +- .../langchain_experimental/fallacy_removal/base.py | 2 +- .../langchain_experimental/llm_bash/base.py | 2 +- .../langchain_experimental/llm_symbolic_math/base.py | 8 ++++---- .../langchain_experimental/llms/anthropic_functions.py | 6 +++--- .../langchain_experimental/llms/jsonformer_decoder.py | 2 +- .../langchain_experimental/llms/llamaapi.py | 2 +- .../llms/lmformatenforcer_decoder.py | 2 +- .../langchain_experimental/llms/rellm_decoder.py | 2 +- .../langchain_experimental/pal_chain/base.py | 2 +- .../plan_and_execute/agent_executor.py | 4 ++-- .../plan_and_execute/executors/base.py | 2 +- .../plan_and_execute/planners/base.py | 2 +- .../recommenders/amazon_personalize_chain.py | 6 +++--- .../retrievers/vector_sql_database.py | 2 +- .../langchain_experimental/rl_chain/base.py | 2 +- .../langchain_experimental/rl_chain/pick_best_chain.py | 2 +- .../langchain_experimental/smart_llm/base.py | 2 +- libs/experimental/langchain_experimental/sql/base.py | 2 +- .../langchain_experimental/sql/vector_sql.py | 2 +- .../langchain_experimental/tools/python/tool.py | 6 +++--- libs/experimental/langchain_experimental/tot/base.py | 4 ++-- .../experimental/langchain_experimental/tot/checker.py | 2 +- .../video_captioning/services/audio_service.py | 2 +- .../video_captioning/services/caption_service.py | 2 +- .../video_captioning/services/combine_service.py | 2 +- .../chat_models/test_llm_wrapper_llama2chat.py | 2 +- libs/experimental/tests/unit_tests/fake_llm.py | 2 +- .../agents/agent_toolkits/vectorstore/base.py | 2 +- .../langchain/callbacks/streamlit/__init__.py | 3 ++- libs/langchain/langchain/chains/graph_qa/base.py | 2 +- .../langchain/chains/graph_qa/neptune_sparql.py | 2 +- .../langchain/chains/graph_qa/ontotext_graphdb.py | 3 +-- .../evaluation/agents/trajectory_eval_chain.py | 10 +++++----- .../langchain/evaluation/comparison/eval_chain.py | 2 +- .../langchain/evaluation/criteria/eval_chain.py | 2 +- .../langchain/evaluation/embedding_distance/base.py | 8 ++++---- libs/langchain/langchain/evaluation/qa/eval_chain.py | 2 +- .../langchain/evaluation/scoring/eval_chain.py | 2 +- .../langchain/evaluation/string_distance/base.py | 6 +++--- .../langchain/retrievers/document_compressors/base.py | 3 +-- .../retrievers/document_compressors/chain_extract.py | 2 +- .../retrievers/document_compressors/chain_filter.py | 2 +- .../retrievers/document_compressors/cohere_rerank.py | 2 +- .../document_compressors/embeddings_filter.py | 2 +- .../document_compressors/flashrank_rerank.py | 2 +- libs/langchain/langchain/retrievers/self_query/base.py | 8 ++++---- .../langchain/smith/evaluation/runner_utils.py | 2 +- .../langchain/smith/evaluation/string_run_evaluator.py | 8 ++++---- libs/langchain/tests/unit_tests/agents/test_agent.py | 2 +- .../tests/unit_tests/agents/test_agent_async.py | 2 +- .../unit_tests/callbacks/fake_callback_handler.py | 3 +-- libs/langchain/tests/unit_tests/callbacks/test_base.py | 8 ++++---- libs/langchain/tests/unit_tests/chains/test_base.py | 2 +- libs/langchain/tests/unit_tests/chains/test_hyde.py | 8 ++++---- libs/langchain/tests/unit_tests/chains/test_natbot.py | 2 +- .../tests/unit_tests/chains/test_sequential.py | 4 ++-- .../unit_tests/evaluation/agents/test_eval_chain.py | 2 +- .../langchain/tests/unit_tests/llms/fake_chat_model.py | 9 ++++----- libs/langchain/tests/unit_tests/llms/fake_llm.py | 3 +-- .../tests/unit_tests/llms/test_fake_chat_model.py | 2 +- .../unit_tests/retrievers/self_query/test_base.py | 6 +++--- .../unit_tests/runnables/test_openai_functions.py | 2 +- libs/langchain/tests/unit_tests/test_dependencies.py | 2 +- 73 files changed, 115 insertions(+), 119 deletions(-) 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 6a7e65125a..8186d978e0 100644 --- a/libs/experimental/langchain_experimental/agents/agent_toolkits/python/base.py +++ b/libs/experimental/langchain_experimental/agents/agent_toolkits/python/base.py @@ -6,8 +6,8 @@ from langchain.agents.agent import AgentExecutor, BaseSingleActionAgent from langchain.agents.mrkl.base import ZeroShotAgent from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent from langchain.agents.types import AgentType -from langchain.callbacks.base import BaseCallbackManager from langchain.chains.llm import LLMChain +from langchain_core.callbacks.base import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_core.messages import SystemMessage diff --git a/libs/experimental/langchain_experimental/agents/agent_toolkits/spark/base.py b/libs/experimental/langchain_experimental/agents/agent_toolkits/spark/base.py index 9639ac0db1..8c09079c56 100644 --- a/libs/experimental/langchain_experimental/agents/agent_toolkits/spark/base.py +++ b/libs/experimental/langchain_experimental/agents/agent_toolkits/spark/base.py @@ -3,8 +3,8 @@ from typing import Any, Dict, List, Optional from langchain.agents.agent import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent -from langchain.callbacks.base import BaseCallbackManager from langchain.chains.llm import LLMChain +from langchain_core.callbacks.base import BaseCallbackManager from langchain_core.language_models import BaseLLM from langchain_experimental.agents.agent_toolkits.spark.prompt import PREFIX, SUFFIX diff --git a/libs/experimental/langchain_experimental/agents/agent_toolkits/xorbits/base.py b/libs/experimental/langchain_experimental/agents/agent_toolkits/xorbits/base.py index 31bc94c702..09f936401a 100644 --- a/libs/experimental/langchain_experimental/agents/agent_toolkits/xorbits/base.py +++ b/libs/experimental/langchain_experimental/agents/agent_toolkits/xorbits/base.py @@ -3,8 +3,8 @@ from typing import Any, Dict, List, Optional from langchain.agents.agent import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent -from langchain.callbacks.base import BaseCallbackManager from langchain.chains.llm import LLMChain +from langchain_core.callbacks.base import BaseCallbackManager from langchain_core.language_models import BaseLLM from langchain_experimental.agents.agent_toolkits.xorbits.prompt import ( 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 6aa662892f..2c8b09be9e 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 @@ -3,8 +3,8 @@ from collections import deque from typing import Any, Dict, List, Optional -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_core.language_models import BaseLanguageModel from langchain_core.vectorstores import VectorStore diff --git a/libs/experimental/langchain_experimental/autonomous_agents/hugginggpt/repsonse_generator.py b/libs/experimental/langchain_experimental/autonomous_agents/hugginggpt/repsonse_generator.py index 110a5313b5..e12d7b3152 100644 --- a/libs/experimental/langchain_experimental/autonomous_agents/hugginggpt/repsonse_generator.py +++ b/libs/experimental/langchain_experimental/autonomous_agents/hugginggpt/repsonse_generator.py @@ -1,8 +1,8 @@ from typing import Any, List, Optional from langchain.base_language import BaseLanguageModel -from langchain.callbacks.manager import Callbacks from langchain.chains import LLMChain +from langchain_core.callbacks.manager import Callbacks from langchain_core.prompts import PromptTemplate diff --git a/libs/experimental/langchain_experimental/autonomous_agents/hugginggpt/task_planner.py b/libs/experimental/langchain_experimental/autonomous_agents/hugginggpt/task_planner.py index afda9ab035..43ec79b086 100644 --- a/libs/experimental/langchain_experimental/autonomous_agents/hugginggpt/task_planner.py +++ b/libs/experimental/langchain_experimental/autonomous_agents/hugginggpt/task_planner.py @@ -4,7 +4,6 @@ from abc import abstractmethod from typing import Any, Dict, List, Optional, Union from langchain.base_language import BaseLanguageModel -from langchain.callbacks.manager import Callbacks from langchain.chains import LLMChain from langchain.prompts.chat import ( AIMessagePromptTemplate, @@ -13,6 +12,7 @@ from langchain.prompts.chat import ( SystemMessagePromptTemplate, ) from langchain.tools.base import BaseTool +from langchain_core.callbacks.manager import Callbacks from langchain_experimental.pydantic_v1 import BaseModel diff --git a/libs/experimental/langchain_experimental/chat_models/llm_wrapper.py b/libs/experimental/langchain_experimental/chat_models/llm_wrapper.py index b9fcde9bed..e02855a761 100644 --- a/libs/experimental/langchain_experimental/chat_models/llm_wrapper.py +++ b/libs/experimental/langchain_experimental/chat_models/llm_wrapper.py @@ -3,10 +3,6 @@ for Llama-2-chat, Llama-2-instruct and Vicuna models. """ from typing import Any, List, Optional, cast -from langchain.callbacks.manager import ( - AsyncCallbackManagerForLLMRun, - CallbackManagerForLLMRun, -) from langchain.schema import ( AIMessage, BaseMessage, @@ -16,6 +12,10 @@ from langchain.schema import ( LLMResult, SystemMessage, ) +from langchain_core.callbacks.manager import ( + AsyncCallbackManagerForLLMRun, + CallbackManagerForLLMRun, +) from langchain_core.language_models import LLM, BaseChatModel DEFAULT_SYSTEM_PROMPT = """You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. diff --git a/libs/experimental/langchain_experimental/comprehend_moderation/amazon_comprehend_moderation.py b/libs/experimental/langchain_experimental/comprehend_moderation/amazon_comprehend_moderation.py index 197d789e32..4f76ba7db0 100644 --- a/libs/experimental/langchain_experimental/comprehend_moderation/amazon_comprehend_moderation.py +++ b/libs/experimental/langchain_experimental/comprehend_moderation/amazon_comprehend_moderation.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_experimental.comprehend_moderation.base_moderation import BaseModeration from langchain_experimental.comprehend_moderation.base_moderation_callbacks import ( diff --git a/libs/experimental/langchain_experimental/comprehend_moderation/base_moderation.py b/libs/experimental/langchain_experimental/comprehend_moderation/base_moderation.py index cbeb6d52f2..be236f5ece 100644 --- a/libs/experimental/langchain_experimental/comprehend_moderation/base_moderation.py +++ b/libs/experimental/langchain_experimental/comprehend_moderation/base_moderation.py @@ -1,7 +1,7 @@ import uuid from typing import Any, Callable, Optional, cast -from langchain.callbacks.manager import CallbackManagerForChainRun +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_core.messages import AIMessage, HumanMessage from langchain_core.prompt_values import ChatPromptValue, StringPromptValue diff --git a/libs/experimental/langchain_experimental/cpal/base.py b/libs/experimental/langchain_experimental/cpal/base.py index b72c9c5cd3..ebfcce7ac5 100644 --- a/libs/experimental/langchain_experimental/cpal/base.py +++ b/libs/experimental/langchain_experimental/cpal/base.py @@ -7,11 +7,11 @@ import json from typing import Any, ClassVar, Dict, List, Optional, Type from langchain.base_language import BaseLanguageModel -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.chains.llm import LLMChain from langchain.output_parsers import PydanticOutputParser from langchain.prompts.prompt import PromptTemplate +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_experimental import pydantic_v1 as pydantic from langchain_experimental.cpal.constants import Constant diff --git a/libs/experimental/langchain_experimental/fallacy_removal/base.py b/libs/experimental/langchain_experimental/fallacy_removal/base.py index a09114295e..97df55e798 100644 --- a/libs/experimental/langchain_experimental/fallacy_removal/base.py +++ b/libs/experimental/langchain_experimental/fallacy_removal/base.py @@ -3,10 +3,10 @@ from __future__ import annotations from typing import Any, Dict, List, Optional -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.chains.llm import LLMChain from langchain.schema import BasePromptTemplate +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_core.language_models import BaseLanguageModel from langchain_experimental.fallacy_removal.fallacies import FALLACIES diff --git a/libs/experimental/langchain_experimental/llm_bash/base.py b/libs/experimental/langchain_experimental/llm_bash/base.py index a016304ef9..22df953310 100644 --- a/libs/experimental/langchain_experimental/llm_bash/base.py +++ b/libs/experimental/langchain_experimental/llm_bash/base.py @@ -5,10 +5,10 @@ import logging import warnings from typing import Any, Dict, List, Optional -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.chains.llm import LLMChain from langchain.schema import BasePromptTemplate, OutputParserException +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_core.language_models import BaseLanguageModel from langchain_experimental.llm_bash.bash import BashProcess diff --git a/libs/experimental/langchain_experimental/llm_symbolic_math/base.py b/libs/experimental/langchain_experimental/llm_symbolic_math/base.py index fa5a29e5f8..8607511e4d 100644 --- a/libs/experimental/langchain_experimental/llm_symbolic_math/base.py +++ b/libs/experimental/langchain_experimental/llm_symbolic_math/base.py @@ -5,13 +5,13 @@ import re from typing import Any, Dict, List, Optional from langchain.base_language import BaseLanguageModel -from langchain.callbacks.manager import ( - AsyncCallbackManagerForChainRun, - CallbackManagerForChainRun, -) from langchain.chains.base import Chain from langchain.chains.llm import LLMChain from langchain.prompts.base import BasePromptTemplate +from langchain_core.callbacks.manager import ( + AsyncCallbackManagerForChainRun, + CallbackManagerForChainRun, +) from langchain_experimental.llm_symbolic_math.prompt import PROMPT from langchain_experimental.pydantic_v1 import Extra diff --git a/libs/experimental/langchain_experimental/llms/anthropic_functions.py b/libs/experimental/langchain_experimental/llms/anthropic_functions.py index 58399b7ca9..3d290f5f17 100644 --- a/libs/experimental/langchain_experimental/llms/anthropic_functions.py +++ b/libs/experimental/langchain_experimental/llms/anthropic_functions.py @@ -3,15 +3,15 @@ from collections import defaultdict from html.parser import HTMLParser from typing import Any, DefaultDict, Dict, List, Optional, cast -from langchain.callbacks.manager import ( - CallbackManagerForLLMRun, -) from langchain.schema import ( ChatGeneration, ChatResult, ) from langchain_community.chat_models.anthropic import ChatAnthropic from langchain_core._api.deprecation import deprecated +from langchain_core.callbacks.manager import ( + CallbackManagerForLLMRun, +) from langchain_core.language_models import BaseChatModel from langchain_core.messages import ( AIMessage, diff --git a/libs/experimental/langchain_experimental/llms/jsonformer_decoder.py b/libs/experimental/langchain_experimental/llms/jsonformer_decoder.py index 392cb602d6..dbcbb72f3a 100644 --- a/libs/experimental/langchain_experimental/llms/jsonformer_decoder.py +++ b/libs/experimental/langchain_experimental/llms/jsonformer_decoder.py @@ -4,8 +4,8 @@ from __future__ import annotations import json from typing import TYPE_CHECKING, Any, List, Optional, cast -from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline +from langchain_core.callbacks.manager import CallbackManagerForLLMRun from langchain_experimental.pydantic_v1 import Field, root_validator diff --git a/libs/experimental/langchain_experimental/llms/llamaapi.py b/libs/experimental/langchain_experimental/llms/llamaapi.py index 29e841a658..6f96ceebfa 100644 --- a/libs/experimental/langchain_experimental/llms/llamaapi.py +++ b/libs/experimental/langchain_experimental/llms/llamaapi.py @@ -9,11 +9,11 @@ from typing import ( Tuple, ) -from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.schema import ( ChatGeneration, ChatResult, ) +from langchain_core.callbacks.manager import CallbackManagerForLLMRun from langchain_core.language_models import BaseChatModel from langchain_core.messages import ( AIMessage, diff --git a/libs/experimental/langchain_experimental/llms/lmformatenforcer_decoder.py b/libs/experimental/langchain_experimental/llms/lmformatenforcer_decoder.py index ab899b5534..61d1a0ba56 100644 --- a/libs/experimental/langchain_experimental/llms/lmformatenforcer_decoder.py +++ b/libs/experimental/langchain_experimental/llms/lmformatenforcer_decoder.py @@ -3,9 +3,9 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any, List, Optional -from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.schema import LLMResult from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline +from langchain_core.callbacks.manager import CallbackManagerForLLMRun from langchain_experimental.pydantic_v1 import Field diff --git a/libs/experimental/langchain_experimental/llms/rellm_decoder.py b/libs/experimental/langchain_experimental/llms/rellm_decoder.py index a04c09c2d4..b349b9b8f1 100644 --- a/libs/experimental/langchain_experimental/llms/rellm_decoder.py +++ b/libs/experimental/langchain_experimental/llms/rellm_decoder.py @@ -3,9 +3,9 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any, List, Optional, cast -from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline from langchain_community.llms.utils import enforce_stop_tokens +from langchain_core.callbacks.manager import CallbackManagerForLLMRun from langchain_experimental.pydantic_v1 import Field, root_validator diff --git a/libs/experimental/langchain_experimental/pal_chain/base.py b/libs/experimental/langchain_experimental/pal_chain/base.py index d7b7136f65..ad1fbc1c5d 100644 --- a/libs/experimental/langchain_experimental/pal_chain/base.py +++ b/libs/experimental/langchain_experimental/pal_chain/base.py @@ -10,10 +10,10 @@ from __future__ import annotations import ast from typing import Any, Dict, List, Optional -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.chains.llm import LLMChain from langchain_community.utilities import PythonREPL +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_core.language_models import BaseLanguageModel from langchain_experimental.pal_chain.colored_object_prompt import COLORED_OBJECT_PROMPT diff --git a/libs/experimental/langchain_experimental/plan_and_execute/agent_executor.py b/libs/experimental/langchain_experimental/plan_and_execute/agent_executor.py index 9c50bad650..2ec7433938 100644 --- a/libs/experimental/langchain_experimental/plan_and_execute/agent_executor.py +++ b/libs/experimental/langchain_experimental/plan_and_execute/agent_executor.py @@ -1,10 +1,10 @@ from typing import Any, Dict, List, Optional -from langchain.callbacks.manager import ( +from langchain.chains.base import Chain +from langchain_core.callbacks.manager import ( AsyncCallbackManagerForChainRun, CallbackManagerForChainRun, ) -from langchain.chains.base import Chain from langchain_experimental.plan_and_execute.executors.base import BaseExecutor from langchain_experimental.plan_and_execute.planners.base import BasePlanner diff --git a/libs/experimental/langchain_experimental/plan_and_execute/executors/base.py b/libs/experimental/langchain_experimental/plan_and_execute/executors/base.py index a65716de29..f50c1b7fd9 100644 --- a/libs/experimental/langchain_experimental/plan_and_execute/executors/base.py +++ b/libs/experimental/langchain_experimental/plan_and_execute/executors/base.py @@ -1,8 +1,8 @@ from abc import abstractmethod from typing import Any -from langchain.callbacks.manager import Callbacks from langchain.chains.base import Chain +from langchain_core.callbacks.manager import Callbacks from langchain_experimental.plan_and_execute.schema import StepResponse from langchain_experimental.pydantic_v1 import BaseModel diff --git a/libs/experimental/langchain_experimental/plan_and_execute/planners/base.py b/libs/experimental/langchain_experimental/plan_and_execute/planners/base.py index e79c564f80..9ec4da7353 100644 --- a/libs/experimental/langchain_experimental/plan_and_execute/planners/base.py +++ b/libs/experimental/langchain_experimental/plan_and_execute/planners/base.py @@ -1,8 +1,8 @@ from abc import abstractmethod from typing import Any, List, Optional -from langchain.callbacks.manager import Callbacks from langchain.chains.llm import LLMChain +from langchain_core.callbacks.manager import Callbacks from langchain_experimental.plan_and_execute.schema import Plan, PlanOutputParser from langchain_experimental.pydantic_v1 import BaseModel diff --git a/libs/experimental/langchain_experimental/recommenders/amazon_personalize_chain.py b/libs/experimental/langchain_experimental/recommenders/amazon_personalize_chain.py index 751da51520..740b24ad58 100644 --- a/libs/experimental/langchain_experimental/recommenders/amazon_personalize_chain.py +++ b/libs/experimental/langchain_experimental/recommenders/amazon_personalize_chain.py @@ -2,13 +2,13 @@ from __future__ import annotations from typing import Any, Dict, List, Mapping, Optional, cast -from langchain.callbacks.manager import ( - CallbackManagerForChainRun, -) from langchain.chains import LLMChain from langchain.chains.base import Chain from langchain.prompts.prompt import PromptTemplate from langchain.schema.language_model import BaseLanguageModel +from langchain_core.callbacks.manager import ( + CallbackManagerForChainRun, +) from langchain_experimental.recommenders.amazon_personalize import AmazonPersonalize diff --git a/libs/experimental/langchain_experimental/retrievers/vector_sql_database.py b/libs/experimental/langchain_experimental/retrievers/vector_sql_database.py index 5c75c1eaf2..58b41e4c5c 100644 --- a/libs/experimental/langchain_experimental/retrievers/vector_sql_database.py +++ b/libs/experimental/langchain_experimental/retrievers/vector_sql_database.py @@ -2,7 +2,7 @@ from typing import Any, Dict, List -from langchain.callbacks.manager import ( +from langchain_core.callbacks.manager import ( AsyncCallbackManagerForRetrieverRun, CallbackManagerForRetrieverRun, ) diff --git a/libs/experimental/langchain_experimental/rl_chain/base.py b/libs/experimental/langchain_experimental/rl_chain/base.py index 329a9dbafc..c6cfc9d960 100644 --- a/libs/experimental/langchain_experimental/rl_chain/base.py +++ b/libs/experimental/langchain_experimental/rl_chain/base.py @@ -16,7 +16,6 @@ from typing import ( Union, ) -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.chains.llm import LLMChain from langchain.prompts import ( @@ -25,6 +24,7 @@ from langchain.prompts import ( HumanMessagePromptTemplate, SystemMessagePromptTemplate, ) +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_experimental.pydantic_v1 import BaseModel, Extra, root_validator from langchain_experimental.rl_chain.metrics import ( diff --git a/libs/experimental/langchain_experimental/rl_chain/pick_best_chain.py b/libs/experimental/langchain_experimental/rl_chain/pick_best_chain.py index c7fd5cc6b3..5b95c6cf19 100644 --- a/libs/experimental/langchain_experimental/rl_chain/pick_best_chain.py +++ b/libs/experimental/langchain_experimental/rl_chain/pick_best_chain.py @@ -4,9 +4,9 @@ import logging from typing import Any, Dict, List, Optional, Tuple, Type, Union from langchain.base_language import BaseLanguageModel -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.llm import LLMChain from langchain.prompts import BasePromptTemplate +from langchain_core.callbacks.manager import CallbackManagerForChainRun import langchain_experimental.rl_chain.base as base diff --git a/libs/experimental/langchain_experimental/smart_llm/base.py b/libs/experimental/langchain_experimental/smart_llm/base.py index 5cef9fc378..64689230fb 100644 --- a/libs/experimental/langchain_experimental/smart_llm/base.py +++ b/libs/experimental/langchain_experimental/smart_llm/base.py @@ -2,7 +2,6 @@ from typing import Any, Dict, List, Optional, Tuple, Type from langchain.base_language import BaseLanguageModel -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.input import get_colored_text from langchain.prompts.base import BasePromptTemplate @@ -13,6 +12,7 @@ from langchain.prompts.chat import ( HumanMessagePromptTemplate, ) from langchain.schema import LLMResult, PromptValue +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_experimental.pydantic_v1 import Extra, root_validator diff --git a/libs/experimental/langchain_experimental/sql/base.py b/libs/experimental/langchain_experimental/sql/base.py index 7376b08115..d075da98d6 100644 --- a/libs/experimental/langchain_experimental/sql/base.py +++ b/libs/experimental/langchain_experimental/sql/base.py @@ -4,7 +4,6 @@ from __future__ import annotations import warnings from typing import Any, Dict, List, Optional -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.chains.llm import LLMChain from langchain.chains.sql_database.prompt import DECIDER_PROMPT, PROMPT, SQL_PROMPTS @@ -12,6 +11,7 @@ from langchain.prompts.prompt import PromptTemplate from langchain.schema import BasePromptTemplate from langchain_community.tools.sql_database.prompt import QUERY_CHECKER from langchain_community.utilities.sql_database import SQLDatabase +from langchain_core.callbacks.manager import CallbackManagerForChainRun 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 7c28ec8861..5f3eed5d58 100644 --- a/libs/experimental/langchain_experimental/sql/vector_sql.py +++ b/libs/experimental/langchain_experimental/sql/vector_sql.py @@ -4,12 +4,12 @@ from __future__ import annotations from typing import Any, Dict, List, Optional, Sequence, Union -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.llm import LLMChain from langchain.chains.sql_database.prompt import PROMPT, SQL_PROMPTS from langchain.prompts.prompt import PromptTemplate from langchain_community.tools.sql_database.prompt import QUERY_CHECKER from langchain_community.utilities.sql_database import SQLDatabase +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_core.embeddings import Embeddings from langchain_core.language_models import BaseLanguageModel from langchain_core.output_parsers import BaseOutputParser diff --git a/libs/experimental/langchain_experimental/tools/python/tool.py b/libs/experimental/langchain_experimental/tools/python/tool.py index 2324063fd0..7ebcd7c914 100644 --- a/libs/experimental/langchain_experimental/tools/python/tool.py +++ b/libs/experimental/langchain_experimental/tools/python/tool.py @@ -7,12 +7,12 @@ from contextlib import redirect_stdout from io import StringIO from typing import Any, Dict, Optional, Type -from langchain.callbacks.manager import ( +from langchain.pydantic_v1 import BaseModel, Field, root_validator +from langchain.tools.base import BaseTool +from langchain_core.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) -from langchain.pydantic_v1 import BaseModel, Field, root_validator -from langchain.tools.base import BaseTool from langchain_core.runnables.config import run_in_executor from langchain_experimental.utilities.python import PythonREPL diff --git a/libs/experimental/langchain_experimental/tot/base.py b/libs/experimental/langchain_experimental/tot/base.py index 3c60b15cb3..07d2254b0c 100644 --- a/libs/experimental/langchain_experimental/tot/base.py +++ b/libs/experimental/langchain_experimental/tot/base.py @@ -4,11 +4,11 @@ from textwrap import indent from typing import Any, Dict, List, Optional, Type from langchain.base_language import BaseLanguageModel -from langchain.callbacks.manager import ( +from langchain.chains.base import Chain +from langchain_core.callbacks.manager import ( AsyncCallbackManagerForChainRun, CallbackManagerForChainRun, ) -from langchain.chains.base import Chain from langchain_experimental.pydantic_v1 import Extra from langchain_experimental.tot.checker import ToTChecker diff --git a/libs/experimental/langchain_experimental/tot/checker.py b/libs/experimental/langchain_experimental/tot/checker.py index 039ec7d5db..2642125625 100644 --- a/libs/experimental/langchain_experimental/tot/checker.py +++ b/libs/experimental/langchain_experimental/tot/checker.py @@ -1,8 +1,8 @@ from abc import ABC, abstractmethod from typing import Any, Dict, List, Optional, Tuple -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_experimental.tot.thought import ThoughtValidity diff --git a/libs/experimental/langchain_experimental/video_captioning/services/audio_service.py b/libs/experimental/langchain_experimental/video_captioning/services/audio_service.py index b7844df3f7..66f1710b97 100644 --- a/libs/experimental/langchain_experimental/video_captioning/services/audio_service.py +++ b/libs/experimental/langchain_experimental/video_captioning/services/audio_service.py @@ -2,10 +2,10 @@ import subprocess from pathlib import Path from typing import List, Optional -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.schema import Document from langchain_community.document_loaders import AssemblyAIAudioTranscriptLoader from langchain_community.document_loaders.assemblyai import TranscriptFormat +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_experimental.video_captioning.models import AudioModel, BaseModel diff --git a/libs/experimental/langchain_experimental/video_captioning/services/caption_service.py b/libs/experimental/langchain_experimental/video_captioning/services/caption_service.py index 5d844a5c1e..f6810ade77 100644 --- a/libs/experimental/langchain_experimental/video_captioning/services/caption_service.py +++ b/libs/experimental/langchain_experimental/video_captioning/services/caption_service.py @@ -1,7 +1,7 @@ from typing import Dict, List, Optional, Tuple -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.llm import LLMChain +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_core.language_models import BaseLanguageModel from langchain_experimental.video_captioning.models import VideoModel diff --git a/libs/experimental/langchain_experimental/video_captioning/services/combine_service.py b/libs/experimental/langchain_experimental/video_captioning/services/combine_service.py index 09d14c949f..fee94129cb 100644 --- a/libs/experimental/langchain_experimental/video_captioning/services/combine_service.py +++ b/libs/experimental/langchain_experimental/video_captioning/services/combine_service.py @@ -1,8 +1,8 @@ from typing import Dict, List, Optional, Tuple -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.llm import LLMChain from langchain.schema.language_model import BaseLanguageModel +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_experimental.video_captioning.models import ( AudioModel, diff --git a/libs/experimental/tests/unit_tests/chat_models/test_llm_wrapper_llama2chat.py b/libs/experimental/tests/unit_tests/chat_models/test_llm_wrapper_llama2chat.py index abf1129f60..dd25a1bf38 100644 --- a/libs/experimental/tests/unit_tests/chat_models/test_llm_wrapper_llama2chat.py +++ b/libs/experimental/tests/unit_tests/chat_models/test_llm_wrapper_llama2chat.py @@ -1,7 +1,7 @@ from typing import Any, List, Optional import pytest -from langchain.callbacks.manager import ( +from langchain_core.callbacks.manager import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/experimental/tests/unit_tests/fake_llm.py b/libs/experimental/tests/unit_tests/fake_llm.py index 6ad771efcf..73dc5f4172 100644 --- a/libs/experimental/tests/unit_tests/fake_llm.py +++ b/libs/experimental/tests/unit_tests/fake_llm.py @@ -1,7 +1,7 @@ """Fake LLM wrapper for testing purposes.""" from typing import Any, Dict, List, Mapping, Optional, cast -from langchain.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks.manager import CallbackManagerForLLMRun from langchain_core.language_models import LLM from langchain_experimental.pydantic_v1 import validator diff --git a/libs/langchain/langchain/agents/agent_toolkits/vectorstore/base.py b/libs/langchain/langchain/agents/agent_toolkits/vectorstore/base.py index 49e1626c8a..28d02f76bb 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/vectorstore/base.py +++ b/libs/langchain/langchain/agents/agent_toolkits/vectorstore/base.py @@ -1,6 +1,7 @@ """VectorStore agent.""" from typing import Any, Dict, Optional +from langchain_core.callbacks.base import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain.agents.agent import AgentExecutor @@ -10,7 +11,6 @@ from langchain.agents.agent_toolkits.vectorstore.toolkit import ( VectorStoreToolkit, ) from langchain.agents.mrkl.base import ZeroShotAgent -from langchain.callbacks.base import BaseCallbackManager from langchain.chains.llm import LLMChain diff --git a/libs/langchain/langchain/callbacks/streamlit/__init__.py b/libs/langchain/langchain/callbacks/streamlit/__init__.py index e82104a223..4b17f4d608 100644 --- a/libs/langchain/langchain/callbacks/streamlit/__init__.py +++ b/libs/langchain/langchain/callbacks/streamlit/__init__.py @@ -2,7 +2,8 @@ from __future__ import annotations from typing import TYPE_CHECKING, Optional -from langchain.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks.base import BaseCallbackHandler + from langchain.callbacks.streamlit.streamlit_callback_handler import ( LLMThoughtLabeler as LLMThoughtLabeler, ) diff --git a/libs/langchain/langchain/chains/graph_qa/base.py b/libs/langchain/langchain/chains/graph_qa/base.py index 2465bfae6a..5ca9d22f2c 100644 --- a/libs/langchain/langchain/chains/graph_qa/base.py +++ b/libs/langchain/langchain/chains/graph_qa/base.py @@ -4,11 +4,11 @@ from __future__ import annotations from typing import Any, Dict, List, Optional from langchain_community.graphs.networkx_graph import NetworkxEntityGraph, get_entities +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts import BasePromptTemplate from langchain_core.pydantic_v1 import Field -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.chains.graph_qa.prompts import ENTITY_EXTRACTION_PROMPT, GRAPH_QA_PROMPT from langchain.chains.llm import LLMChain diff --git a/libs/langchain/langchain/chains/graph_qa/neptune_sparql.py b/libs/langchain/langchain/chains/graph_qa/neptune_sparql.py index 1a5b23f587..a47053a2e3 100644 --- a/libs/langchain/langchain/chains/graph_qa/neptune_sparql.py +++ b/libs/langchain/langchain/chains/graph_qa/neptune_sparql.py @@ -6,12 +6,12 @@ from __future__ import annotations from typing import Any, Dict, List, Optional from langchain_community.graphs import NeptuneRdfGraph +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts.base import BasePromptTemplate from langchain_core.prompts.prompt import PromptTemplate from langchain_core.pydantic_v1 import Field -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.chains.graph_qa.prompts import SPARQL_QA_PROMPT from langchain.chains.llm import LLMChain diff --git a/libs/langchain/langchain/chains/graph_qa/ontotext_graphdb.py b/libs/langchain/langchain/chains/graph_qa/ontotext_graphdb.py index 29d07d9d75..d3e8d365c6 100644 --- a/libs/langchain/langchain/chains/graph_qa/ontotext_graphdb.py +++ b/libs/langchain/langchain/chains/graph_qa/ontotext_graphdb.py @@ -7,12 +7,11 @@ if TYPE_CHECKING: import rdflib from langchain_community.graphs import OntotextGraphDBGraph -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks.manager import CallbackManager, CallbackManagerForChainRun from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts.base import BasePromptTemplate from langchain_core.pydantic_v1 import Field -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.chains.graph_qa.prompts import ( GRAPHDB_QA_PROMPT, diff --git a/libs/langchain/langchain/evaluation/agents/trajectory_eval_chain.py b/libs/langchain/langchain/evaluation/agents/trajectory_eval_chain.py index 0d31a6686a..3b80f4ae98 100644 --- a/libs/langchain/langchain/evaluation/agents/trajectory_eval_chain.py +++ b/libs/langchain/langchain/evaluation/agents/trajectory_eval_chain.py @@ -19,6 +19,11 @@ from typing import ( ) from langchain_core.agents import AgentAction +from langchain_core.callbacks.manager import ( + AsyncCallbackManagerForChainRun, + CallbackManagerForChainRun, + Callbacks, +) from langchain_core.exceptions import OutputParserException from langchain_core.language_models import BaseLanguageModel from langchain_core.language_models.chat_models import BaseChatModel @@ -26,11 +31,6 @@ from langchain_core.output_parsers import BaseOutputParser from langchain_core.pydantic_v1 import Extra, Field from langchain_core.tools import BaseTool -from langchain.callbacks.manager import ( - AsyncCallbackManagerForChainRun, - CallbackManagerForChainRun, - Callbacks, -) from langchain.chains.llm import LLMChain from langchain.evaluation.agents.trajectory_eval_prompt import ( EVAL_CHAT_PROMPT, diff --git a/libs/langchain/langchain/evaluation/comparison/eval_chain.py b/libs/langchain/langchain/evaluation/comparison/eval_chain.py index decde5cc45..b0fd1e27a2 100644 --- a/libs/langchain/langchain/evaluation/comparison/eval_chain.py +++ b/libs/langchain/langchain/evaluation/comparison/eval_chain.py @@ -7,12 +7,12 @@ from typing import Any, Dict, List, Optional, Union from langchain_community.chat_models.azure_openai import AzureChatOpenAI from langchain_community.chat_models.openai import ChatOpenAI +from langchain_core.callbacks.manager import Callbacks from langchain_core.language_models import BaseLanguageModel from langchain_core.output_parsers import BaseOutputParser from langchain_core.prompts.prompt import PromptTemplate from langchain_core.pydantic_v1 import Extra, Field -from langchain.callbacks.manager import Callbacks from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple from langchain.chains.llm import LLMChain from langchain.evaluation.comparison.prompt import ( diff --git a/libs/langchain/langchain/evaluation/criteria/eval_chain.py b/libs/langchain/langchain/evaluation/criteria/eval_chain.py index 066fb54039..4a18aa081b 100644 --- a/libs/langchain/langchain/evaluation/criteria/eval_chain.py +++ b/libs/langchain/langchain/evaluation/criteria/eval_chain.py @@ -4,12 +4,12 @@ import re from enum import Enum from typing import Any, Dict, List, Mapping, Optional, Union +from langchain_core.callbacks.manager import Callbacks from langchain_core.language_models import BaseLanguageModel from langchain_core.output_parsers import BaseOutputParser from langchain_core.prompts import BasePromptTemplate from langchain_core.pydantic_v1 import Extra, Field -from langchain.callbacks.manager import Callbacks from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple from langchain.chains.llm import LLMChain from langchain.evaluation.criteria.prompt import PROMPT, PROMPT_WITH_REFERENCES diff --git a/libs/langchain/langchain/evaluation/embedding_distance/base.py b/libs/langchain/langchain/evaluation/embedding_distance/base.py index 2010d1d5e2..7fc0b0c66a 100644 --- a/libs/langchain/langchain/evaluation/embedding_distance/base.py +++ b/libs/langchain/langchain/evaluation/embedding_distance/base.py @@ -4,14 +4,14 @@ from typing import Any, Dict, List, Optional import numpy as np from langchain_community.embeddings.openai import OpenAIEmbeddings -from langchain_core.embeddings import Embeddings -from langchain_core.pydantic_v1 import Field, root_validator - -from langchain.callbacks.manager import ( +from langchain_core.callbacks.manager import ( AsyncCallbackManagerForChainRun, CallbackManagerForChainRun, Callbacks, ) +from langchain_core.embeddings import Embeddings +from langchain_core.pydantic_v1 import Field, root_validator + from langchain.chains.base import Chain from langchain.evaluation.schema import PairwiseStringEvaluator, StringEvaluator from langchain.schema import RUN_KEY diff --git a/libs/langchain/langchain/evaluation/qa/eval_chain.py b/libs/langchain/langchain/evaluation/qa/eval_chain.py index 9a465d0255..6bedc4c52d 100644 --- a/libs/langchain/langchain/evaluation/qa/eval_chain.py +++ b/libs/langchain/langchain/evaluation/qa/eval_chain.py @@ -5,11 +5,11 @@ import re import string from typing import Any, List, Optional, Sequence, Tuple +from langchain_core.callbacks.manager import Callbacks from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts import PromptTemplate from langchain_core.pydantic_v1 import Extra -from langchain.callbacks.manager import Callbacks from langchain.chains.llm import LLMChain from langchain.evaluation.qa.eval_prompt import CONTEXT_PROMPT, COT_PROMPT, PROMPT from langchain.evaluation.schema import LLMEvalChain, StringEvaluator diff --git a/libs/langchain/langchain/evaluation/scoring/eval_chain.py b/libs/langchain/langchain/evaluation/scoring/eval_chain.py index 63e9e37c2a..755ebc61eb 100644 --- a/libs/langchain/langchain/evaluation/scoring/eval_chain.py +++ b/libs/langchain/langchain/evaluation/scoring/eval_chain.py @@ -7,12 +7,12 @@ from typing import Any, Dict, List, Optional, Union from langchain_community.chat_models.azure_openai import AzureChatOpenAI from langchain_community.chat_models.openai import ChatOpenAI +from langchain_core.callbacks.manager import Callbacks from langchain_core.language_models import BaseLanguageModel from langchain_core.output_parsers import BaseOutputParser from langchain_core.prompts.prompt import PromptTemplate from langchain_core.pydantic_v1 import Extra, Field -from langchain.callbacks.manager import Callbacks from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple from langchain.chains.llm import LLMChain from langchain.evaluation.criteria.eval_chain import ( diff --git a/libs/langchain/langchain/evaluation/string_distance/base.py b/libs/langchain/langchain/evaluation/string_distance/base.py index 92f8632950..09fb42f337 100644 --- a/libs/langchain/langchain/evaluation/string_distance/base.py +++ b/libs/langchain/langchain/evaluation/string_distance/base.py @@ -3,13 +3,13 @@ from enum import Enum from typing import Any, Callable, Dict, List, Optional -from langchain_core.pydantic_v1 import Field, root_validator - -from langchain.callbacks.manager import ( +from langchain_core.callbacks.manager import ( AsyncCallbackManagerForChainRun, CallbackManagerForChainRun, Callbacks, ) +from langchain_core.pydantic_v1 import Field, root_validator + from langchain.chains.base import Chain from langchain.evaluation.schema import PairwiseStringEvaluator, StringEvaluator from langchain.schema import RUN_KEY diff --git a/libs/langchain/langchain/retrievers/document_compressors/base.py b/libs/langchain/langchain/retrievers/document_compressors/base.py index ae8efdf656..b8b01de5dc 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/base.py +++ b/libs/langchain/langchain/retrievers/document_compressors/base.py @@ -1,14 +1,13 @@ from inspect import signature from typing import List, Optional, Sequence, Union +from langchain_core.callbacks.manager import Callbacks from langchain_core.documents import ( BaseDocumentCompressor, BaseDocumentTransformer, Document, ) -from langchain.callbacks.manager import Callbacks - class DocumentCompressorPipeline(BaseDocumentCompressor): """Document compressor that uses a pipeline of Transformers.""" diff --git a/libs/langchain/langchain/retrievers/document_compressors/chain_extract.py b/libs/langchain/langchain/retrievers/document_compressors/chain_extract.py index 6cfe45b226..b6d54647de 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/chain_extract.py +++ b/libs/langchain/langchain/retrievers/document_compressors/chain_extract.py @@ -4,12 +4,12 @@ from __future__ import annotations import asyncio from typing import Any, Callable, Dict, Optional, Sequence, cast +from langchain_core.callbacks.manager import Callbacks from langchain_core.documents import Document from langchain_core.language_models import BaseLanguageModel from langchain_core.output_parsers import BaseOutputParser from langchain_core.prompts import PromptTemplate -from langchain.callbacks.manager import Callbacks from langchain.chains.llm import LLMChain from langchain.retrievers.document_compressors.base import BaseDocumentCompressor from langchain.retrievers.document_compressors.chain_extract_prompt import ( diff --git a/libs/langchain/langchain/retrievers/document_compressors/chain_filter.py b/libs/langchain/langchain/retrievers/document_compressors/chain_filter.py index 5278065ee2..4b112b2482 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/chain_filter.py +++ b/libs/langchain/langchain/retrievers/document_compressors/chain_filter.py @@ -1,11 +1,11 @@ """Filter that uses an LLM to drop documents that aren't relevant to the query.""" from typing import Any, Callable, Dict, Optional, Sequence +from langchain_core.callbacks.manager import Callbacks from langchain_core.documents import Document from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts import BasePromptTemplate, PromptTemplate -from langchain.callbacks.manager import Callbacks from langchain.chains import LLMChain from langchain.output_parsers.boolean import BooleanOutputParser from langchain.retrievers.document_compressors.base import BaseDocumentCompressor diff --git a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py index 53c2ee423b..70279061f4 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py +++ b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py @@ -4,10 +4,10 @@ from copy import deepcopy from typing import Any, Dict, List, Optional, Sequence, Union from langchain_core._api.deprecation import deprecated +from langchain_core.callbacks.manager import Callbacks from langchain_core.documents import Document from langchain_core.pydantic_v1 import Extra, root_validator -from langchain.callbacks.manager import Callbacks from langchain.retrievers.document_compressors.base import BaseDocumentCompressor from langchain.utils import get_from_dict_or_env diff --git a/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py b/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py index eb8066a352..2f2e0ec914 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py +++ b/libs/langchain/langchain/retrievers/document_compressors/embeddings_filter.py @@ -5,11 +5,11 @@ from langchain_community.document_transformers.embeddings_redundant_filter impor _get_embeddings_from_stateful_docs, get_stateful_documents, ) +from langchain_core.callbacks.manager import Callbacks from langchain_core.documents import Document from langchain_core.embeddings import Embeddings from langchain_core.pydantic_v1 import root_validator -from langchain.callbacks.manager import Callbacks from langchain.retrievers.document_compressors.base import ( BaseDocumentCompressor, ) diff --git a/libs/langchain/langchain/retrievers/document_compressors/flashrank_rerank.py b/libs/langchain/langchain/retrievers/document_compressors/flashrank_rerank.py index a05fd8c6e1..f89cfa344f 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/flashrank_rerank.py +++ b/libs/langchain/langchain/retrievers/document_compressors/flashrank_rerank.py @@ -2,10 +2,10 @@ from __future__ import annotations from typing import TYPE_CHECKING, Dict, Optional, Sequence +from langchain_core.callbacks.manager import Callbacks from langchain_core.documents import Document from langchain_core.pydantic_v1 import Extra, root_validator -from langchain.callbacks.manager import Callbacks from langchain.retrievers.document_compressors.base import BaseDocumentCompressor if TYPE_CHECKING: diff --git a/libs/langchain/langchain/retrievers/self_query/base.py b/libs/langchain/langchain/retrievers/self_query/base.py index 974c80ec0e..1fe6bad807 100644 --- a/libs/langchain/langchain/retrievers/self_query/base.py +++ b/libs/langchain/langchain/retrievers/self_query/base.py @@ -26,6 +26,10 @@ from langchain_community.vectorstores import ( from langchain_community.vectorstores import ( ElasticsearchStore as ElasticsearchStoreCommunity, ) +from langchain_core.callbacks.manager import ( + AsyncCallbackManagerForRetrieverRun, + CallbackManagerForRetrieverRun, +) from langchain_core.documents import Document from langchain_core.language_models import BaseLanguageModel from langchain_core.pydantic_v1 import Field, root_validator @@ -33,10 +37,6 @@ from langchain_core.retrievers import BaseRetriever from langchain_core.runnables import Runnable from langchain_core.vectorstores import VectorStore -from langchain.callbacks.manager import ( - AsyncCallbackManagerForRetrieverRun, - CallbackManagerForRetrieverRun, -) from langchain.chains.query_constructor.base import load_query_constructor_runnable from langchain.chains.query_constructor.ir import StructuredQuery, Visitor from langchain.chains.query_constructor.schema import AttributeInfo diff --git a/libs/langchain/langchain/smith/evaluation/runner_utils.py b/libs/langchain/langchain/smith/evaluation/runner_utils.py index 2559c8eb71..0721906dfa 100644 --- a/libs/langchain/langchain/smith/evaluation/runner_utils.py +++ b/libs/langchain/langchain/smith/evaluation/runner_utils.py @@ -22,6 +22,7 @@ from typing import ( ) from langchain_core._api import warn_deprecated +from langchain_core.callbacks.manager import Callbacks from langchain_core.language_models import BaseLanguageModel from langchain_core.messages import BaseMessage, messages_from_dict from langchain_core.outputs import ChatResult, LLMResult @@ -48,7 +49,6 @@ from langsmith.utils import LangSmithError from requests import HTTPError from typing_extensions import TypedDict -from langchain.callbacks.manager import Callbacks from langchain.chains.base import Chain from langchain.evaluation.loading import load_evaluator from langchain.evaluation.schema import ( diff --git a/libs/langchain/langchain/smith/evaluation/string_run_evaluator.py b/libs/langchain/langchain/smith/evaluation/string_run_evaluator.py index 64bd51bb9f..eea44bf98b 100644 --- a/libs/langchain/langchain/smith/evaluation/string_run_evaluator.py +++ b/libs/langchain/langchain/smith/evaluation/string_run_evaluator.py @@ -4,6 +4,10 @@ from __future__ import annotations from abc import abstractmethod from typing import Any, Dict, List, Optional +from langchain_core.callbacks.manager import ( + AsyncCallbackManagerForChainRun, + CallbackManagerForChainRun, +) from langchain_core.load.dump import dumpd from langchain_core.load.load import load from langchain_core.load.serializable import Serializable @@ -11,10 +15,6 @@ from langchain_core.messages import BaseMessage, get_buffer_string, messages_fro from langsmith import EvaluationResult, RunEvaluator from langsmith.schemas import DataType, Example, Run -from langchain.callbacks.manager import ( - AsyncCallbackManagerForChainRun, - CallbackManagerForChainRun, -) from langchain.chains.base import Chain from langchain.evaluation.schema import StringEvaluator from langchain.schema import RUN_KEY diff --git a/libs/langchain/tests/unit_tests/agents/test_agent.py b/libs/langchain/tests/unit_tests/agents/test_agent.py index f584d059f9..e4dbe338d2 100644 --- a/libs/langchain/tests/unit_tests/agents/test_agent.py +++ b/libs/langchain/tests/unit_tests/agents/test_agent.py @@ -10,6 +10,7 @@ from langchain_core.agents import ( AgentFinish, AgentStep, ) +from langchain_core.callbacks.manager import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.messages import ( AIMessage, @@ -32,7 +33,6 @@ from langchain.agents import ( initialize_agent, ) from langchain.agents.output_parsers.openai_tools import OpenAIToolAgentAction -from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.prompts import ChatPromptTemplate from langchain.tools import tool 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 f1259cebc0..e1b2c0e4fe 100644 --- a/libs/langchain/tests/unit_tests/agents/test_agent_async.py +++ b/libs/langchain/tests/unit_tests/agents/test_agent_async.py @@ -3,13 +3,13 @@ from typing import Any, Dict, List, Optional from langchain_core.agents import AgentAction, AgentStep +from langchain_core.callbacks.manager import CallbackManagerForLLMRun 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 tests.unit_tests.callbacks.fake_callback_handler import FakeCallbackHandler diff --git a/libs/langchain/tests/unit_tests/callbacks/fake_callback_handler.py b/libs/langchain/tests/unit_tests/callbacks/fake_callback_handler.py index 84d4575013..2a2af92269 100644 --- a/libs/langchain/tests/unit_tests/callbacks/fake_callback_handler.py +++ b/libs/langchain/tests/unit_tests/callbacks/fake_callback_handler.py @@ -3,11 +3,10 @@ from itertools import chain from typing import Any, Dict, List, Optional, Union from uuid import UUID +from langchain_core.callbacks.base import AsyncCallbackHandler, BaseCallbackHandler from langchain_core.messages import BaseMessage from langchain_core.pydantic_v1 import BaseModel -from langchain.callbacks.base import AsyncCallbackHandler, BaseCallbackHandler - class BaseFakeCallbackHandler(BaseModel): """Base fake callback handler for testing.""" diff --git a/libs/langchain/tests/unit_tests/callbacks/test_base.py b/libs/langchain/tests/unit_tests/callbacks/test_base.py index 62760e032d..c1f8727c1f 100644 --- a/libs/langchain/tests/unit_tests/callbacks/test_base.py +++ b/libs/langchain/tests/unit_tests/callbacks/test_base.py @@ -1,6 +1,6 @@ -from langchain.callbacks.base import __all__ +from langchain_core.callbacks import __all__ -EXPECTED_ALL = [ +EXPECTED_ALL = { "RetrieverManagerMixin", "LLMManagerMixin", "ChainManagerMixin", @@ -11,8 +11,8 @@ EXPECTED_ALL = [ "AsyncCallbackHandler", "BaseCallbackManager", "Callbacks", -] +} def test_all_imports() -> None: - assert set(__all__) == set(EXPECTED_ALL) + assert set(__all__).issuperset(EXPECTED_ALL) diff --git a/libs/langchain/tests/unit_tests/chains/test_base.py b/libs/langchain/tests/unit_tests/chains/test_base.py index c96f1d945b..2070180b63 100644 --- a/libs/langchain/tests/unit_tests/chains/test_base.py +++ b/libs/langchain/tests/unit_tests/chains/test_base.py @@ -2,9 +2,9 @@ from typing import Any, Dict, List, Optional import pytest +from langchain_core.callbacks.manager import CallbackManagerForChainRun from langchain_core.memory import BaseMemory -from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain from langchain.schema import RUN_KEY from tests.unit_tests.callbacks.fake_callback_handler import FakeCallbackHandler diff --git a/libs/langchain/tests/unit_tests/chains/test_hyde.py b/libs/langchain/tests/unit_tests/chains/test_hyde.py index 12571a6f37..263c4f1dc4 100644 --- a/libs/langchain/tests/unit_tests/chains/test_hyde.py +++ b/libs/langchain/tests/unit_tests/chains/test_hyde.py @@ -2,14 +2,14 @@ from typing import Any, List, Optional import numpy as np +from langchain_core.callbacks.manager import ( + AsyncCallbackManagerForLLMRun, + CallbackManagerForLLMRun, +) from langchain_core.embeddings import Embeddings from langchain_core.language_models.llms import BaseLLM from langchain_core.outputs import Generation, LLMResult -from langchain.callbacks.manager import ( - AsyncCallbackManagerForLLMRun, - CallbackManagerForLLMRun, -) from langchain.chains.hyde.base import HypotheticalDocumentEmbedder from langchain.chains.hyde.prompts import PROMPT_MAP diff --git a/libs/langchain/tests/unit_tests/chains/test_natbot.py b/libs/langchain/tests/unit_tests/chains/test_natbot.py index 9733142df1..3f1f79da2e 100644 --- a/libs/langchain/tests/unit_tests/chains/test_natbot.py +++ b/libs/langchain/tests/unit_tests/chains/test_natbot.py @@ -2,9 +2,9 @@ from typing import Any, Dict, List, Optional +from langchain_core.callbacks.manager import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM -from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.chains.natbot.base import NatBotChain diff --git a/libs/langchain/tests/unit_tests/chains/test_sequential.py b/libs/langchain/tests/unit_tests/chains/test_sequential.py index 5b6c4e3630..356852d6f6 100644 --- a/libs/langchain/tests/unit_tests/chains/test_sequential.py +++ b/libs/langchain/tests/unit_tests/chains/test_sequential.py @@ -3,11 +3,11 @@ from typing import Dict, List, Optional import pytest - -from langchain.callbacks.manager import ( +from langchain_core.callbacks.manager import ( AsyncCallbackManagerForChainRun, CallbackManagerForChainRun, ) + from langchain.chains.base import Chain from langchain.chains.sequential import SequentialChain, SimpleSequentialChain from langchain.memory import ConversationBufferMemory diff --git a/libs/langchain/tests/unit_tests/evaluation/agents/test_eval_chain.py b/libs/langchain/tests/unit_tests/evaluation/agents/test_eval_chain.py index e1fee6062a..5178b6b20d 100644 --- a/libs/langchain/tests/unit_tests/evaluation/agents/test_eval_chain.py +++ b/libs/langchain/tests/unit_tests/evaluation/agents/test_eval_chain.py @@ -4,11 +4,11 @@ from typing import Any, Dict, List, Optional, Tuple import pytest from langchain_core.agents import AgentAction, BaseMessage +from langchain_core.callbacks.manager import CallbackManagerForLLMRun from langchain_core.exceptions import OutputParserException from langchain_core.pydantic_v1 import Field from langchain_core.tools import tool -from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.evaluation.agents.trajectory_eval_chain import ( TrajectoryEval, TrajectoryEvalChain, diff --git a/libs/langchain/tests/unit_tests/llms/fake_chat_model.py b/libs/langchain/tests/unit_tests/llms/fake_chat_model.py index fe0d1c9c61..14e3fa84f4 100644 --- a/libs/langchain/tests/unit_tests/llms/fake_chat_model.py +++ b/libs/langchain/tests/unit_tests/llms/fake_chat_model.py @@ -2,6 +2,10 @@ import re from typing import Any, AsyncIterator, Dict, Iterator, List, Optional, cast +from langchain_core.callbacks.manager import ( + AsyncCallbackManagerForLLMRun, + CallbackManagerForLLMRun, +) from langchain_core.language_models.chat_models import BaseChatModel, SimpleChatModel from langchain_core.messages import ( AIMessage, @@ -11,11 +15,6 @@ from langchain_core.messages import ( from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult from langchain_core.runnables import run_in_executor -from langchain.callbacks.manager import ( - AsyncCallbackManagerForLLMRun, - CallbackManagerForLLMRun, -) - class FakeChatModel(SimpleChatModel): """Fake Chat Model wrapper for testing purposes.""" diff --git a/libs/langchain/tests/unit_tests/llms/fake_llm.py b/libs/langchain/tests/unit_tests/llms/fake_llm.py index 12f4f4cd1f..09a80504db 100644 --- a/libs/langchain/tests/unit_tests/llms/fake_llm.py +++ b/libs/langchain/tests/unit_tests/llms/fake_llm.py @@ -1,11 +1,10 @@ """Fake LLM wrapper for testing purposes.""" from typing import Any, Dict, List, Mapping, Optional, cast +from langchain_core.callbacks.manager import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import validator -from langchain.callbacks.manager import CallbackManagerForLLMRun - class FakeLLM(LLM): """Fake LLM wrapper for testing purposes.""" diff --git a/libs/langchain/tests/unit_tests/llms/test_fake_chat_model.py b/libs/langchain/tests/unit_tests/llms/test_fake_chat_model.py index 7a0362740c..a27683f90a 100644 --- a/libs/langchain/tests/unit_tests/llms/test_fake_chat_model.py +++ b/libs/langchain/tests/unit_tests/llms/test_fake_chat_model.py @@ -3,10 +3,10 @@ from itertools import cycle from typing import Any, Dict, List, Optional, Union from uuid import UUID +from langchain_core.callbacks.base import AsyncCallbackHandler from langchain_core.messages import AIMessage, AIMessageChunk, BaseMessage from langchain_core.outputs import ChatGenerationChunk, GenerationChunk -from langchain.callbacks.base import AsyncCallbackHandler from tests.unit_tests.llms.fake_chat_model import GenericFakeChatModel from tests.unit_tests.stubs import AnyStr diff --git a/libs/langchain/tests/unit_tests/retrievers/self_query/test_base.py b/libs/langchain/tests/unit_tests/retrievers/self_query/test_base.py index b181e964de..1eeab1dfb8 100644 --- a/libs/langchain/tests/unit_tests/retrievers/self_query/test_base.py +++ b/libs/langchain/tests/unit_tests/retrievers/self_query/test_base.py @@ -1,12 +1,12 @@ from typing import Any, Dict, List, Tuple, Union import pytest -from langchain_core.documents import Document - -from langchain.callbacks.manager import ( +from langchain_core.callbacks.manager import ( AsyncCallbackManagerForRetrieverRun, CallbackManagerForRetrieverRun, ) +from langchain_core.documents import Document + from langchain.chains.query_constructor.ir import ( Comparator, Comparison, diff --git a/libs/langchain/tests/unit_tests/runnables/test_openai_functions.py b/libs/langchain/tests/unit_tests/runnables/test_openai_functions.py index 3f6fbb2a82..ba7195c4ee 100644 --- a/libs/langchain/tests/unit_tests/runnables/test_openai_functions.py +++ b/libs/langchain/tests/unit_tests/runnables/test_openai_functions.py @@ -1,12 +1,12 @@ from typing import Any, List, Optional +from langchain_core.callbacks.manager import CallbackManagerForLLMRun from langchain_core.language_models.chat_models import BaseChatModel from langchain_core.messages import AIMessage, BaseMessage from langchain_core.outputs import ChatGeneration, ChatResult from pytest_mock import MockerFixture from syrupy import SnapshotAssertion -from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.runnables.openai_functions import OpenAIFunctionsRouter diff --git a/libs/langchain/tests/unit_tests/test_dependencies.py b/libs/langchain/tests/unit_tests/test_dependencies.py index 5e8c9d01dd..754a10823e 100644 --- a/libs/langchain/tests/unit_tests/test_dependencies.py +++ b/libs/langchain/tests/unit_tests/test_dependencies.py @@ -97,6 +97,7 @@ def test_test_group_dependencies(poetry_conf: Mapping[str, Any]) -> None: def test_imports() -> None: """Test that you can import all top level things okay.""" + from langchain_community.callbacks import OpenAICallbackHandler # noqa: F401 from langchain_community.chat_models import ChatOpenAI # noqa: F401 from langchain_community.document_loaders import BSHTMLLoader # noqa: F401 from langchain_community.embeddings import OpenAIEmbeddings # noqa: F401 @@ -109,7 +110,6 @@ def test_imports() -> None: from langchain_core.prompts import BasePromptTemplate # noqa: F401 from langchain.agents import OpenAIFunctionsAgent # noqa: F401 - from langchain.callbacks import OpenAICallbackHandler # noqa: F401 from langchain.chains import LLMChain # noqa: F401 from langchain.retrievers import VespaRetriever # noqa: F401 from langchain.tools import DuckDuckGoSearchResults # noqa: F401