diff --git a/.scripts/community_split/script_integrations.sh b/.scripts/community_split/script_integrations.sh index b7ed7ef6ab0..2aed0fc2520 100755 --- a/.scripts/community_split/script_integrations.sh +++ b/.scripts/community_split/script_integrations.sh @@ -69,6 +69,7 @@ mv langchain/langchain/callbacks community/langchain_community/callbacks mv langchain/langchain/indexes/base.py community/langchain_community/indexes mv langchain/langchain/indexes/_sql_record_manager.py community/langchain_community/indexes mv langchain/langchain/utils/math.py community/langchain_community/utils + mv langchain/langchain/utils/openai.py partners/openai/langchain_openai/utils.py mv langchain/langchain/utils/openai_functions.py partners/openai/langchain_openai/functions.py @@ -126,7 +127,10 @@ git add community cd community git grep -l 'from langchain.pydantic_v1' | xargs sed -i '' 's/from langchain.pydantic_v1/from langchain_core.pydantic_v1/g' -git grep -l 'from langchain.callbacks' | xargs sed -i '' 's/from langchain.callbacks/from langchain_core.callbacks/g' +git grep -l 'from langchain.callbacks.base' | xargs sed -i '' 's/from langchain.callbacks.base/from langchain_core.callbacks/g' +git grep -l 'from langchain.callbacks.stdout' | xargs sed -i '' 's/from langchain.callbacks.stdout/from langchain_core.callbacks/g' +git grep -l 'from langchain.callbacks.streaming_stdout' | xargs sed -i '' 's/from langchain.callbacks.streaming_stdout/from langchain_core.callbacks/g' +git grep -l 'from langchain.callbacks.manager' | xargs sed -i '' 's/from langchain.callbacks.manager/from langchain_core.callbacks/g' git grep -l 'from langchain.tools.base' | xargs sed -i '' 's/from langchain.tools.base/from langchain_core.tools/g' git grep -l 'from langchain.agents.tools' | xargs sed -i '' 's/from langchain.agents.tools/from langchain_core.tools/g' git grep -l 'from langchain.schema.output' | xargs sed -i '' 's/from langchain.schema.output/from langchain_core.outputs/g' @@ -145,8 +149,8 @@ git grep -l 'from langchain.utils' | xargs sed -i '' 's/from langchain.utils/fro git grep -l 'from langchain\.' | xargs sed -i '' 's/from langchain\./from langchain_community./g' git grep -l 'from langchain_community.memory.chat_message_histories' | xargs sed -i '' 's/from langchain_community.memory.chat_message_histories/from langchain_community.chat_message_histories/g' git grep -l 'from langchain_community.agents.agent_toolkits' | xargs sed -i '' 's/from langchain_community.agents.agent_toolkits/from langchain_community.agent_toolkits/g' -git grep -l 'from langchain_community.text_splitter' | xargs sed -i '' 's/from langchain_community.text_splitter/from langchain.text_splitter/g' +git grep -l 'from langchain_community\.text_splitter' | xargs sed -i '' 's/from langchain_community\.text_splitter/from langchain.text_splitter/g' git grep -l 'from langchain_community\.chains' | xargs sed -i '' 's/from langchain_community\.chains/from langchain.chains/g' git grep -l 'from langchain_community\.agents' | xargs sed -i '' 's/from langchain_community\.agents/from langchain.agents/g' git grep -l 'from langchain_community\.memory' | xargs sed -i '' 's/from langchain_community\.memory/from langchain.memory/g' @@ -156,6 +160,7 @@ git checkout master -- langchain/langchain cd langchain python ../../.scripts/community_split/update_imports.py langchain/chat_loaders langchain_community.chat_loaders +python ../../.scripts/community_split/update_imports.py langchain/callbacks langchain_community.callbacks python ../../.scripts/community_split/update_imports.py langchain/document_loaders langchain_community.document_loaders python ../../.scripts/community_split/update_imports.py langchain/docstore langchain_community.docstore python ../../.scripts/community_split/update_imports.py langchain/document_transformers langchain_community.document_transformers @@ -207,6 +212,8 @@ rm community/langchain_community/llms/base.py rm community/langchain_community/tools/base.py rm community/langchain_community/embeddings/base.py rm community/langchain_community/vectorstores/base.py +rm community/langchain_community/callbacks/{base,stdout,streaming_stdout}.py +rm community/langchain_community/callbacks/tracers/{base,evaluation,langchain,langchain_v1,log_stream,root_listeners,run_collector,schemas,stdout}.py git checkout master -- langchain/tests/unit_tests/chat_models/test_base.py git checkout master -- langchain/tests/unit_tests/llms/test_base.py diff --git a/libs/community/langchain_community/agent_toolkits/json/base.py b/libs/community/langchain_community/agent_toolkits/json/base.py index 2600071559c..d23ad604e01 100644 --- a/libs/community/langchain_community/agent_toolkits/json/base.py +++ b/libs/community/langchain_community/agent_toolkits/json/base.py @@ -5,7 +5,7 @@ from langchain.agents.agent import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS from langchain.chains.llm import LLMChain -from langchain_core.callbacks.base import BaseCallbackManager +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_community.agent_toolkits.json.prompt import JSON_PREFIX, JSON_SUFFIX diff --git a/libs/community/langchain_community/agent_toolkits/openapi/base.py b/libs/community/langchain_community/agent_toolkits/openapi/base.py index b72cb9e71d3..8cc68fc285f 100644 --- a/libs/community/langchain_community/agent_toolkits/openapi/base.py +++ b/libs/community/langchain_community/agent_toolkits/openapi/base.py @@ -5,7 +5,7 @@ from langchain.agents.agent import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS from langchain.chains.llm import LLMChain -from langchain_core.callbacks.base import BaseCallbackManager +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_community.agent_toolkits.openapi.prompt import ( diff --git a/libs/community/langchain_community/agent_toolkits/openapi/planner.py b/libs/community/langchain_community/agent_toolkits/openapi/planner.py index 676066bf753..f1f8bc2d4e2 100644 --- a/libs/community/langchain_community/agent_toolkits/openapi/planner.py +++ b/libs/community/langchain_community/agent_toolkits/openapi/planner.py @@ -9,7 +9,7 @@ from langchain.agents.agent import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent from langchain.chains.llm import LLMChain from langchain.memory import ReadOnlySharedMemory -from langchain_core.callbacks.base import BaseCallbackManager +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_core.prompts import BasePromptTemplate, PromptTemplate from langchain_core.pydantic_v1 import Field diff --git a/libs/community/langchain_community/agent_toolkits/powerbi/base.py b/libs/community/langchain_community/agent_toolkits/powerbi/base.py index c777da07674..f62d823b28b 100644 --- a/libs/community/langchain_community/agent_toolkits/powerbi/base.py +++ b/libs/community/langchain_community/agent_toolkits/powerbi/base.py @@ -5,7 +5,7 @@ from langchain.agents import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS from langchain.chains.llm import LLMChain -from langchain_core.callbacks.base import BaseCallbackManager +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_community.agent_toolkits.powerbi.prompt import ( diff --git a/libs/community/langchain_community/agent_toolkits/powerbi/chat_base.py b/libs/community/langchain_community/agent_toolkits/powerbi/chat_base.py index 76043736995..920b063dc7b 100644 --- a/libs/community/langchain_community/agent_toolkits/powerbi/chat_base.py +++ b/libs/community/langchain_community/agent_toolkits/powerbi/chat_base.py @@ -6,7 +6,7 @@ from langchain.agents.agent import AgentOutputParser from langchain.agents.conversational_chat.base import ConversationalChatAgent from langchain.memory import ConversationBufferMemory from langchain.memory.chat_memory import BaseChatMemory -from langchain_core.callbacks.base import BaseCallbackManager +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models.chat_models import BaseChatModel from langchain_community.agent_toolkits.powerbi.prompt import ( diff --git a/libs/community/langchain_community/agent_toolkits/powerbi/toolkit.py b/libs/community/langchain_community/agent_toolkits/powerbi/toolkit.py index 7784fdd8eaf..a0bd3852245 100644 --- a/libs/community/langchain_community/agent_toolkits/powerbi/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/powerbi/toolkit.py @@ -2,7 +2,7 @@ from typing import List, Optional, Union from langchain.chains.llm import LLMChain -from langchain_core.callbacks.base import BaseCallbackManager +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_core.language_models.chat_models import BaseChatModel from langchain_core.prompts import PromptTemplate diff --git a/libs/community/langchain_community/agent_toolkits/spark_sql/base.py b/libs/community/langchain_community/agent_toolkits/spark_sql/base.py index f2ee03ba472..c0dd96429a4 100644 --- a/libs/community/langchain_community/agent_toolkits/spark_sql/base.py +++ b/libs/community/langchain_community/agent_toolkits/spark_sql/base.py @@ -5,7 +5,7 @@ from langchain.agents.agent import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS from langchain.chains.llm import LLMChain -from langchain_core.callbacks.base import BaseCallbackManager, Callbacks +from langchain_core.callbacks import BaseCallbackManager, Callbacks from langchain_core.language_models import BaseLanguageModel from langchain_community.agent_toolkits.spark_sql.prompt import SQL_PREFIX, SQL_SUFFIX diff --git a/libs/community/langchain_community/agent_toolkits/sql/base.py b/libs/community/langchain_community/agent_toolkits/sql/base.py index 5989f82cc0e..bb46909efa9 100644 --- a/libs/community/langchain_community/agent_toolkits/sql/base.py +++ b/libs/community/langchain_community/agent_toolkits/sql/base.py @@ -7,7 +7,7 @@ from langchain.agents.mrkl.base import ZeroShotAgent from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent from langchain.chains.llm import LLMChain -from langchain_core.callbacks.base import BaseCallbackManager +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_core.messages import AIMessage, SystemMessage from langchain_core.prompts.chat import ( diff --git a/libs/community/langchain_community/agent_toolkits/vectorstore/base.py b/libs/community/langchain_community/agent_toolkits/vectorstore/base.py index 01680612dae..6d9afea2416 100644 --- a/libs/community/langchain_community/agent_toolkits/vectorstore/base.py +++ b/libs/community/langchain_community/agent_toolkits/vectorstore/base.py @@ -4,7 +4,7 @@ from typing import Any, Dict, Optional from langchain.agents.agent import AgentExecutor from langchain.agents.mrkl.base import ZeroShotAgent from langchain.chains.llm import LLMChain -from langchain_core.callbacks.base import BaseCallbackManager +from langchain_core.callbacks import BaseCallbackManager from langchain_core.language_models import BaseLanguageModel from langchain_community.agent_toolkits.vectorstore.prompt import PREFIX, ROUTER_PREFIX diff --git a/libs/community/langchain_community/callbacks/__init__.py b/libs/community/langchain_community/callbacks/__init__.py index 49ea55e599f..1fb026d4f6b 100644 --- a/libs/community/langchain_community/callbacks/__init__.py +++ b/libs/community/langchain_community/callbacks/__init__.py @@ -7,44 +7,46 @@ BaseCallbackHandler --> CallbackHandler # Example: AimCallbackHandler """ -from langchain_core.callbacks.aim_callback import AimCallbackHandler -from langchain_core.callbacks.argilla_callback import ArgillaCallbackHandler -from langchain_core.callbacks.arize_callback import ArizeCallbackHandler -from langchain_core.callbacks.arthur_callback import ArthurCallbackHandler -from langchain_core.callbacks.clearml_callback import ClearMLCallbackHandler -from langchain_core.callbacks.comet_ml_callback import CometCallbackHandler -from langchain_core.callbacks.context_callback import ContextCallbackHandler -from langchain_core.callbacks.file import FileCallbackHandler -from langchain_core.callbacks.flyte_callback import FlyteCallbackHandler -from langchain_core.callbacks.human import HumanApprovalCallbackHandler -from langchain_core.callbacks.infino_callback import InfinoCallbackHandler -from langchain_core.callbacks.labelstudio_callback import LabelStudioCallbackHandler -from langchain_core.callbacks.llmonitor_callback import LLMonitorCallbackHandler -from langchain_core.callbacks.manager import ( - collect_runs, - get_openai_callback, - tracing_enabled, - tracing_v2_enabled, - wandb_tracing_enabled, +from langchain_core.callbacks import ( + StdOutCallbackHandler, + StreamingStdOutCallbackHandler, ) -from langchain_core.callbacks.mlflow_callback import MlflowCallbackHandler -from langchain_core.callbacks.openai_info import OpenAICallbackHandler -from langchain_core.callbacks.promptlayer_callback import PromptLayerCallbackHandler -from langchain_core.callbacks.sagemaker_callback import SageMakerCallbackHandler -from langchain_core.callbacks.stdout import StdOutCallbackHandler -from langchain_core.callbacks.streaming_aiter import AsyncIteratorCallbackHandler -from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler -from langchain_core.callbacks.streaming_stdout_final_only import ( +from langchain_community.callbacks.manager import get_openai_callback, wandb_tracing_enabled + +from langchain_community.callbacks.streaming_stdout_final_only import ( FinalStreamingStdOutCallbackHandler, ) -from langchain_core.callbacks.streamlit import ( +from langchain_core.tracers.langchain import LangChainTracer + +from langchain_community.callbacks.aim_callback import AimCallbackHandler +from langchain_community.callbacks.argilla_callback import ArgillaCallbackHandler +from langchain_community.callbacks.arize_callback import ArizeCallbackHandler +from langchain_community.callbacks.arthur_callback import ArthurCallbackHandler +from langchain_community.callbacks.clearml_callback import ClearMLCallbackHandler +from langchain_community.callbacks.comet_ml_callback import CometCallbackHandler +from langchain_community.callbacks.context_callback import ContextCallbackHandler +from langchain_community.callbacks.file import FileCallbackHandler +from langchain_community.callbacks.flyte_callback import FlyteCallbackHandler +from langchain_community.callbacks.human import HumanApprovalCallbackHandler +from langchain_community.callbacks.infino_callback import InfinoCallbackHandler +from langchain_community.callbacks.labelstudio_callback import ( + LabelStudioCallbackHandler, +) +from langchain_community.callbacks.llmonitor_callback import LLMonitorCallbackHandler +from langchain_community.callbacks.mlflow_callback import MlflowCallbackHandler +from langchain_community.callbacks.openai_info import OpenAICallbackHandler +from langchain_community.callbacks.promptlayer_callback import ( + PromptLayerCallbackHandler, +) +from langchain_community.callbacks.sagemaker_callback import SageMakerCallbackHandler +from langchain_community.callbacks.streaming_aiter import AsyncIteratorCallbackHandler +from langchain_community.callbacks.streamlit import ( LLMThoughtLabeler, StreamlitCallbackHandler, ) -from langchain_core.callbacks.trubrics_callback import TrubricsCallbackHandler -from langchain_core.callbacks.wandb_callback import WandbCallbackHandler -from langchain_core.callbacks.whylabs_callback import WhyLabsCallbackHandler -from langchain_core.tracers.langchain import LangChainTracer +from langchain_community.callbacks.trubrics_callback import TrubricsCallbackHandler +from langchain_community.callbacks.wandb_callback import WandbCallbackHandler +from langchain_community.callbacks.whylabs_callback import WhyLabsCallbackHandler __all__ = [ "AimCallbackHandler", @@ -71,9 +73,6 @@ __all__ = [ "WandbCallbackHandler", "WhyLabsCallbackHandler", "get_openai_callback", - "tracing_enabled", - "tracing_v2_enabled", - "collect_runs", "wandb_tracing_enabled", "FlyteCallbackHandler", "SageMakerCallbackHandler", diff --git a/libs/community/langchain_community/callbacks/aim_callback.py b/libs/community/langchain_community/callbacks/aim_callback.py index 9d2a90e0a54..da194b34b3d 100644 --- a/libs/community/langchain_community/callbacks/aim_callback.py +++ b/libs/community/langchain_community/callbacks/aim_callback.py @@ -2,7 +2,7 @@ from copy import deepcopy from typing import Any, Dict, List, Optional from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.outputs import LLMResult diff --git a/libs/community/langchain_community/callbacks/argilla_callback.py b/libs/community/langchain_community/callbacks/argilla_callback.py index 2908a873952..b280e0ce1a6 100644 --- a/libs/community/langchain_community/callbacks/argilla_callback.py +++ b/libs/community/langchain_community/callbacks/argilla_callback.py @@ -3,7 +3,7 @@ import warnings from typing import Any, Dict, List, Optional from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.outputs import LLMResult from packaging.version import parse @@ -33,7 +33,7 @@ class ArgillaCallbackHandler(BaseCallbackHandler): Examples: >>> from langchain_community.llms import OpenAI - >>> from langchain_core.callbacks import ArgillaCallbackHandler + >>> from langchain_community.callbacks import ArgillaCallbackHandler >>> argilla_callback = ArgillaCallbackHandler( ... dataset_name="my-dataset", ... workspace_name="my-workspace", diff --git a/libs/community/langchain_community/callbacks/arize_callback.py b/libs/community/langchain_community/callbacks/arize_callback.py index fc47f6e8eb0..44212b61917 100644 --- a/libs/community/langchain_community/callbacks/arize_callback.py +++ b/libs/community/langchain_community/callbacks/arize_callback.py @@ -2,10 +2,11 @@ from datetime import datetime from typing import Any, Dict, List, Optional from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler -from langchain_core.callbacks.utils import import_pandas +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.outputs import LLMResult +from langchain_community.callbacks.utils import import_pandas + class ArizeCallbackHandler(BaseCallbackHandler): """Callback Handler that logs to Arize.""" diff --git a/libs/community/langchain_community/callbacks/arthur_callback.py b/libs/community/langchain_community/callbacks/arthur_callback.py index 6b84b4a3700..a5fce582ed1 100644 --- a/libs/community/langchain_community/callbacks/arthur_callback.py +++ b/libs/community/langchain_community/callbacks/arthur_callback.py @@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, Any, DefaultDict, Dict, List, Optional import numpy as np from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.outputs import LLMResult if TYPE_CHECKING: diff --git a/libs/community/langchain_community/callbacks/base.py b/libs/community/langchain_community/callbacks/base.py deleted file mode 100644 index 9b9d189d3f6..00000000000 --- a/libs/community/langchain_community/callbacks/base.py +++ /dev/null @@ -1,28 +0,0 @@ -"""Base callback handler that can be used to handle callbacks in langchain.""" -from __future__ import annotations - -from langchain_core.callbacks.base import ( - AsyncCallbackHandler, - BaseCallbackHandler, - BaseCallbackManager, - CallbackManagerMixin, - Callbacks, - ChainManagerMixin, - LLMManagerMixin, - RetrieverManagerMixin, - RunManagerMixin, - ToolManagerMixin, -) - -__all__ = [ - "RetrieverManagerMixin", - "LLMManagerMixin", - "ChainManagerMixin", - "ToolManagerMixin", - "CallbackManagerMixin", - "RunManagerMixin", - "BaseCallbackHandler", - "AsyncCallbackHandler", - "BaseCallbackManager", - "Callbacks", -] diff --git a/libs/community/langchain_community/callbacks/clearml_callback.py b/libs/community/langchain_community/callbacks/clearml_callback.py index b0d7cfb6024..71f30fccdd8 100644 --- a/libs/community/langchain_community/callbacks/clearml_callback.py +++ b/libs/community/langchain_community/callbacks/clearml_callback.py @@ -6,8 +6,10 @@ from pathlib import Path from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, Sequence from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler -from langchain_core.callbacks.utils import ( +from langchain_core.callbacks import BaseCallbackHandler +from langchain_core.outputs import LLMResult + +from langchain_community.callbacks.utils import ( BaseMetadataCallbackHandler, flatten_dict, hash_string, @@ -16,7 +18,6 @@ from langchain_core.callbacks.utils import ( import_textstat, load_json, ) -from langchain_core.outputs import LLMResult if TYPE_CHECKING: import pandas as pd diff --git a/libs/community/langchain_community/callbacks/comet_ml_callback.py b/libs/community/langchain_community/callbacks/comet_ml_callback.py index 93223f6d515..0f4fb0fae4e 100644 --- a/libs/community/langchain_community/callbacks/comet_ml_callback.py +++ b/libs/community/langchain_community/callbacks/comet_ml_callback.py @@ -5,15 +5,16 @@ from typing import Any, Callable, Dict, List, Optional, Sequence import langchain from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler -from langchain_core.callbacks.utils import ( +from langchain_core.callbacks import BaseCallbackHandler +from langchain_core.outputs import Generation, LLMResult + +from langchain_community.callbacks.utils import ( BaseMetadataCallbackHandler, flatten_dict, import_pandas, import_spacy, import_textstat, ) -from langchain_core.outputs import Generation, LLMResult LANGCHAIN_MODEL_NAME = "langchain-model" diff --git a/libs/community/langchain_community/callbacks/confident_callback.py b/libs/community/langchain_community/callbacks/confident_callback.py index b6b2f11f567..d9432e5d567 100644 --- a/libs/community/langchain_community/callbacks/confident_callback.py +++ b/libs/community/langchain_community/callbacks/confident_callback.py @@ -3,7 +3,7 @@ import os import warnings from typing import Any, Dict, List, Optional, Union -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.agents import AgentAction, AgentFinish from langchain_core.outputs import LLMResult @@ -20,7 +20,7 @@ class DeepEvalCallbackHandler(BaseCallbackHandler): Examples: >>> from langchain_community.llms import OpenAI - >>> from langchain_core.callbacks import DeepEvalCallbackHandler + >>> from langchain_community.callbacks import DeepEvalCallbackHandler >>> from deepeval.metrics import AnswerRelevancy >>> metric = AnswerRelevancy(minimum_score=0.3) >>> deepeval_callback = DeepEvalCallbackHandler( diff --git a/libs/community/langchain_community/callbacks/context_callback.py b/libs/community/langchain_community/callbacks/context_callback.py index 120268368b2..8514976687d 100644 --- a/libs/community/langchain_community/callbacks/context_callback.py +++ b/libs/community/langchain_community/callbacks/context_callback.py @@ -3,7 +3,7 @@ import os from typing import Any, Dict, List from uuid import UUID -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.messages import BaseMessage from langchain_core.outputs import LLMResult @@ -44,7 +44,7 @@ class ContextCallbackHandler(BaseCallbackHandler): Chat Example: >>> from langchain_community.llms import ChatOpenAI - >>> from langchain_core.callbacks import ContextCallbackHandler + >>> from langchain_community.callbacks import ContextCallbackHandler >>> context_callback = ContextCallbackHandler( ... token="", ... ) @@ -63,7 +63,7 @@ class ContextCallbackHandler(BaseCallbackHandler): Chain Example: >>> from langchain.chains import LLMChain >>> from langchain_community.chat_models import ChatOpenAI - >>> from langchain_core.callbacks import ContextCallbackHandler + >>> from langchain_community.callbacks import ContextCallbackHandler >>> context_callback = ContextCallbackHandler( ... token="", ... ) diff --git a/libs/community/langchain_community/callbacks/file.py b/libs/community/langchain_community/callbacks/file.py index 27438a01fbd..06bcecb027d 100644 --- a/libs/community/langchain_community/callbacks/file.py +++ b/libs/community/langchain_community/callbacks/file.py @@ -2,7 +2,7 @@ from typing import Any, Dict, Optional, TextIO, cast from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.utils.input import print_text diff --git a/libs/community/langchain_community/callbacks/flyte_callback.py b/libs/community/langchain_community/callbacks/flyte_callback.py index f92b41d78f6..23a8f473430 100644 --- a/libs/community/langchain_community/callbacks/flyte_callback.py +++ b/libs/community/langchain_community/callbacks/flyte_callback.py @@ -6,15 +6,16 @@ from copy import deepcopy from typing import TYPE_CHECKING, Any, Dict, List, Tuple from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler -from langchain_core.callbacks.utils import ( +from langchain_core.callbacks import BaseCallbackHandler +from langchain_core.outputs import LLMResult + +from langchain_community.callbacks.utils import ( BaseMetadataCallbackHandler, flatten_dict, import_pandas, import_spacy, import_textstat, ) -from langchain_core.outputs import LLMResult if TYPE_CHECKING: import flytekit diff --git a/libs/community/langchain_community/callbacks/human.py b/libs/community/langchain_community/callbacks/human.py index 63353562aa5..64ea01f99f5 100644 --- a/libs/community/langchain_community/callbacks/human.py +++ b/libs/community/langchain_community/callbacks/human.py @@ -1,7 +1,7 @@ from typing import Any, Awaitable, Callable, Dict, Optional from uuid import UUID -from langchain_core.callbacks.base import AsyncCallbackHandler, BaseCallbackHandler +from langchain_core.callbacks import AsyncCallbackHandler, BaseCallbackHandler def _default_approve(_input: str) -> bool: diff --git a/libs/community/langchain_community/callbacks/infino_callback.py b/libs/community/langchain_community/callbacks/infino_callback.py index 13a9d167049..57d756948ef 100644 --- a/libs/community/langchain_community/callbacks/infino_callback.py +++ b/libs/community/langchain_community/callbacks/infino_callback.py @@ -2,7 +2,7 @@ import time from typing import Any, Dict, List, Optional, cast from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.messages import BaseMessage from langchain_core.outputs import LLMResult diff --git a/libs/community/langchain_community/callbacks/labelstudio_callback.py b/libs/community/langchain_community/callbacks/labelstudio_callback.py index 6493ac45e6c..73954820b23 100644 --- a/libs/community/langchain_community/callbacks/labelstudio_callback.py +++ b/libs/community/langchain_community/callbacks/labelstudio_callback.py @@ -6,7 +6,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union from uuid import UUID from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.messages import BaseMessage, ChatMessage from langchain_core.outputs import Generation, LLMResult @@ -90,7 +90,7 @@ class LabelStudioCallbackHandler(BaseCallbackHandler): Examples: >>> from langchain_community.llms import OpenAI - >>> from langchain_core.callbacks import LabelStudioCallbackHandler + >>> from langchain_community.callbacks import LabelStudioCallbackHandler >>> handler = LabelStudioCallbackHandler( ... api_key='', ... url='http://localhost:8080', diff --git a/libs/community/langchain_community/callbacks/llmonitor_callback.py b/libs/community/langchain_community/callbacks/llmonitor_callback.py index e063ca2246e..f4f2882dac2 100644 --- a/libs/community/langchain_community/callbacks/llmonitor_callback.py +++ b/libs/community/langchain_community/callbacks/llmonitor_callback.py @@ -9,7 +9,7 @@ from uuid import UUID import requests from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.messages import BaseMessage from langchain_core.outputs import LLMResult from packaging.version import parse @@ -199,7 +199,7 @@ class LLMonitorCallbackHandler(BaseCallbackHandler): #### Example: ```python from langchain_community.llms import OpenAI - from langchain_core.callbacks import LLMonitorCallbackHandler + from langchain_community.callbacks import LLMonitorCallbackHandler llmonitor_callback = LLMonitorCallbackHandler() llm = OpenAI(callbacks=[llmonitor_callback], diff --git a/libs/community/langchain_community/callbacks/manager.py b/libs/community/langchain_community/callbacks/manager.py index bc968c685c9..abfe14ccc62 100644 --- a/libs/community/langchain_community/callbacks/manager.py +++ b/libs/community/langchain_community/callbacks/manager.py @@ -32,8 +32,6 @@ from langchain_core.callbacks.manager import ( handle_event, trace_as_chain_group, ) -from langchain_core.callbacks.openai_info import OpenAICallbackHandler -from langchain_core.callbacks.tracers.wandb import WandbTracer from langchain_core.tracers.context import ( collect_runs, register_configure_hook, @@ -42,6 +40,9 @@ from langchain_core.tracers.context import ( ) from langchain_core.utils.env import env_var_is_set +from langchain_community.callbacks.openai_info import OpenAICallbackHandler +from langchain_community.callbacks.tracers.wandb import WandbTracer + logger = logging.getLogger(__name__) openai_callback_var: ContextVar[Optional[OpenAICallbackHandler]] = ContextVar( diff --git a/libs/community/langchain_community/callbacks/mlflow_callback.py b/libs/community/langchain_community/callbacks/mlflow_callback.py index eb665632297..6d93125d564 100644 --- a/libs/community/langchain_community/callbacks/mlflow_callback.py +++ b/libs/community/langchain_community/callbacks/mlflow_callback.py @@ -8,8 +8,11 @@ from pathlib import Path from typing import Any, Dict, List, Optional, Union from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler -from langchain_core.callbacks.utils import ( +from langchain_core.callbacks import BaseCallbackHandler +from langchain_core.outputs import LLMResult +from langchain_core.utils import get_from_dict_or_env + +from langchain_community.callbacks.utils import ( BaseMetadataCallbackHandler, flatten_dict, hash_string, @@ -17,8 +20,6 @@ from langchain_core.callbacks.utils import ( import_spacy, import_textstat, ) -from langchain_core.outputs import LLMResult -from langchain_core.utils import get_from_dict_or_env def import_mlflow() -> Any: diff --git a/libs/community/langchain_community/callbacks/openai_info.py b/libs/community/langchain_community/callbacks/openai_info.py index 315c00c1b01..bf0c59b746e 100644 --- a/libs/community/langchain_community/callbacks/openai_info.py +++ b/libs/community/langchain_community/callbacks/openai_info.py @@ -1,7 +1,7 @@ """Callback Handler that prints to std out.""" from typing import Any, Dict, List -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.outputs import LLMResult MODEL_COST_PER_1K_TOKENS = { diff --git a/libs/community/langchain_community/callbacks/promptlayer_callback.py b/libs/community/langchain_community/callbacks/promptlayer_callback.py index a1d3046449e..f9431681246 100644 --- a/libs/community/langchain_community/callbacks/promptlayer_callback.py +++ b/libs/community/langchain_community/callbacks/promptlayer_callback.py @@ -5,7 +5,7 @@ import datetime from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple from uuid import UUID -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.messages import ( AIMessage, BaseMessage, diff --git a/libs/community/langchain_community/callbacks/sagemaker_callback.py b/libs/community/langchain_community/callbacks/sagemaker_callback.py index 2f07ee8f004..b791425ff00 100644 --- a/libs/community/langchain_community/callbacks/sagemaker_callback.py +++ b/libs/community/langchain_community/callbacks/sagemaker_callback.py @@ -6,11 +6,12 @@ from copy import deepcopy from typing import Any, Dict, List, Optional from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler -from langchain_core.callbacks.utils import ( +from langchain_core.callbacks import BaseCallbackHandler +from langchain_core.outputs import LLMResult + +from langchain_community.callbacks.utils import ( flatten_dict, ) -from langchain_core.outputs import LLMResult def save_json(data: dict, file_path: str) -> None: diff --git a/libs/community/langchain_community/callbacks/stdout.py b/libs/community/langchain_community/callbacks/stdout.py deleted file mode 100644 index 754e58248e4..00000000000 --- a/libs/community/langchain_community/callbacks/stdout.py +++ /dev/null @@ -1,3 +0,0 @@ -from langchain_core.callbacks.stdout import StdOutCallbackHandler - -__all__ = ["StdOutCallbackHandler"] diff --git a/libs/community/langchain_community/callbacks/streaming_aiter.py b/libs/community/langchain_community/callbacks/streaming_aiter.py index 3256b473876..2df5849db8f 100644 --- a/libs/community/langchain_community/callbacks/streaming_aiter.py +++ b/libs/community/langchain_community/callbacks/streaming_aiter.py @@ -3,7 +3,7 @@ from __future__ import annotations import asyncio from typing import Any, AsyncIterator, Dict, List, Literal, Union, cast -from langchain_core.callbacks.base import AsyncCallbackHandler +from langchain_core.callbacks import AsyncCallbackHandler from langchain_core.outputs import LLMResult # TODO If used by two LLM runs in parallel this won't work as expected diff --git a/libs/community/langchain_community/callbacks/streaming_aiter_final_only.py b/libs/community/langchain_community/callbacks/streaming_aiter_final_only.py index da7b7158b26..f5a7d6241e3 100644 --- a/libs/community/langchain_community/callbacks/streaming_aiter_final_only.py +++ b/libs/community/langchain_community/callbacks/streaming_aiter_final_only.py @@ -2,9 +2,10 @@ from __future__ import annotations from typing import Any, Dict, List, Optional -from langchain_core.callbacks.streaming_aiter import AsyncIteratorCallbackHandler from langchain_core.outputs import LLMResult +from langchain_community.callbacks.streaming_aiter import AsyncIteratorCallbackHandler + DEFAULT_ANSWER_PREFIX_TOKENS = ["Final", "Answer", ":"] diff --git a/libs/community/langchain_community/callbacks/streaming_stdout.py b/libs/community/langchain_community/callbacks/streaming_stdout.py deleted file mode 100644 index e2a22232b57..00000000000 --- a/libs/community/langchain_community/callbacks/streaming_stdout.py +++ /dev/null @@ -1,4 +0,0 @@ -"""Callback Handler streams to stdout on new llm token.""" -from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler - -__all__ = ["StreamingStdOutCallbackHandler"] diff --git a/libs/community/langchain_community/callbacks/streaming_stdout_final_only.py b/libs/community/langchain_community/callbacks/streaming_stdout_final_only.py index d56367300fd..2dce9266a7b 100644 --- a/libs/community/langchain_community/callbacks/streaming_stdout_final_only.py +++ b/libs/community/langchain_community/callbacks/streaming_stdout_final_only.py @@ -2,7 +2,7 @@ import sys from typing import Any, Dict, List, Optional -from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler +from langchain_core.callbacks import StreamingStdOutCallbackHandler DEFAULT_ANSWER_PREFIX_TOKENS = ["Final", "Answer", ":"] diff --git a/libs/community/langchain_community/callbacks/streamlit/__init__.py b/libs/community/langchain_community/callbacks/streamlit/__init__.py index 14f5c50843a..7a0fadb059d 100644 --- a/libs/community/langchain_community/callbacks/streamlit/__init__.py +++ b/libs/community/langchain_community/callbacks/streamlit/__init__.py @@ -2,11 +2,12 @@ from __future__ import annotations from typing import TYPE_CHECKING, Optional -from langchain_core.callbacks.base import BaseCallbackHandler -from langchain_core.callbacks.streamlit.streamlit_callback_handler import ( +from langchain_core.callbacks import BaseCallbackHandler + +from langchain_community.callbacks.streamlit.streamlit_callback_handler import ( LLMThoughtLabeler as LLMThoughtLabeler, ) -from langchain_core.callbacks.streamlit.streamlit_callback_handler import ( +from langchain_community.callbacks.streamlit.streamlit_callback_handler import ( StreamlitCallbackHandler as _InternalStreamlitCallbackHandler, ) diff --git a/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py b/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py index 5ed8ce1b9f7..b336a09a3a6 100644 --- a/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py +++ b/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py @@ -6,10 +6,11 @@ from enum import Enum from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, Optional from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler -from langchain_core.callbacks.streamlit.mutable_expander import MutableExpander +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.outputs import LLMResult +from langchain_community.callbacks.streamlit.mutable_expander import MutableExpander + if TYPE_CHECKING: from streamlit.delta_generator import DeltaGenerator diff --git a/libs/community/langchain_community/callbacks/tracers/__init__.py b/libs/community/langchain_community/callbacks/tracers/__init__.py index d1e9403780f..a7075974639 100644 --- a/libs/community/langchain_community/callbacks/tracers/__init__.py +++ b/libs/community/langchain_community/callbacks/tracers/__init__.py @@ -1,7 +1,5 @@ """Tracers that record execution of LangChain runs.""" -from langchain_core.callbacks.tracers.logging import LoggingCallbackHandler -from langchain_core.callbacks.tracers.wandb import WandbTracer from langchain_core.tracers.langchain import LangChainTracer from langchain_core.tracers.langchain_v1 import LangChainTracerV1 from langchain_core.tracers.stdout import ( @@ -9,6 +7,9 @@ from langchain_core.tracers.stdout import ( FunctionCallbackHandler, ) +from langchain_community.callbacks.tracers.logging import LoggingCallbackHandler +from langchain_community.callbacks.tracers.wandb import WandbTracer + __all__ = [ "ConsoleCallbackHandler", "FunctionCallbackHandler", diff --git a/libs/community/langchain_community/callbacks/tracers/base.py b/libs/community/langchain_community/callbacks/tracers/base.py deleted file mode 100644 index 1a56fa66688..00000000000 --- a/libs/community/langchain_community/callbacks/tracers/base.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Base interfaces for tracing runs.""" - -from langchain_core.tracers.base import BaseTracer, TracerException - -__all__ = ["BaseTracer", "TracerException"] diff --git a/libs/community/langchain_community/callbacks/tracers/comet.py b/libs/community/langchain_community/callbacks/tracers/comet.py index 45545736c4c..3f299967265 100644 --- a/libs/community/langchain_community/callbacks/tracers/comet.py +++ b/libs/community/langchain_community/callbacks/tracers/comet.py @@ -1,14 +1,15 @@ from types import ModuleType, SimpleNamespace from typing import TYPE_CHECKING, Any, Callable, Dict -from langchain_core.callbacks.tracers.base import BaseTracer +from langchain_community.callbacks.tracers.base import BaseTracer if TYPE_CHECKING: from uuid import UUID from comet_llm import Span from comet_llm.chains.chain import Chain - from langchain_core.callbacks.tracers.schemas import Run + + from langchain_community.callbacks.tracers.schemas import Run def _get_run_type(run: "Run") -> str: diff --git a/libs/community/langchain_community/callbacks/tracers/evaluation.py b/libs/community/langchain_community/callbacks/tracers/evaluation.py deleted file mode 100644 index 1617b825a21..00000000000 --- a/libs/community/langchain_community/callbacks/tracers/evaluation.py +++ /dev/null @@ -1,7 +0,0 @@ -"""A tracer that runs evaluators over completed runs.""" -from langchain_core.tracers.evaluation import ( - EvaluatorCallbackHandler, - wait_for_all_evaluators, -) - -__all__ = ["wait_for_all_evaluators", "EvaluatorCallbackHandler"] diff --git a/libs/community/langchain_community/callbacks/tracers/langchain.py b/libs/community/langchain_community/callbacks/tracers/langchain.py deleted file mode 100644 index 54ae9dc6cdd..00000000000 --- a/libs/community/langchain_community/callbacks/tracers/langchain.py +++ /dev/null @@ -1,8 +0,0 @@ -"""A Tracer implementation that records to LangChain endpoint.""" - -from langchain_core.tracers.langchain import ( - LangChainTracer, - wait_for_all_tracers, -) - -__all__ = ["LangChainTracer", "wait_for_all_tracers"] diff --git a/libs/community/langchain_community/callbacks/tracers/langchain_v1.py b/libs/community/langchain_community/callbacks/tracers/langchain_v1.py deleted file mode 100644 index a12b47401f7..00000000000 --- a/libs/community/langchain_community/callbacks/tracers/langchain_v1.py +++ /dev/null @@ -1,3 +0,0 @@ -from langchain_core.tracers.langchain_v1 import LangChainTracerV1 - -__all__ = ["LangChainTracerV1"] diff --git a/libs/community/langchain_community/callbacks/tracers/log_stream.py b/libs/community/langchain_community/callbacks/tracers/log_stream.py deleted file mode 100644 index 22b33c3768d..00000000000 --- a/libs/community/langchain_community/callbacks/tracers/log_stream.py +++ /dev/null @@ -1,9 +0,0 @@ -from langchain_core.tracers.log_stream import ( - LogEntry, - LogStreamCallbackHandler, - RunLog, - RunLogPatch, - RunState, -) - -__all__ = ["LogEntry", "RunState", "RunLog", "RunLogPatch", "LogStreamCallbackHandler"] diff --git a/libs/community/langchain_community/callbacks/tracers/root_listeners.py b/libs/community/langchain_community/callbacks/tracers/root_listeners.py deleted file mode 100644 index 0dee9bce2d2..00000000000 --- a/libs/community/langchain_community/callbacks/tracers/root_listeners.py +++ /dev/null @@ -1,3 +0,0 @@ -from langchain_core.tracers.root_listeners import RootListenersTracer - -__all__ = ["RootListenersTracer"] diff --git a/libs/community/langchain_community/callbacks/tracers/run_collector.py b/libs/community/langchain_community/callbacks/tracers/run_collector.py deleted file mode 100644 index 1240026bfb6..00000000000 --- a/libs/community/langchain_community/callbacks/tracers/run_collector.py +++ /dev/null @@ -1,3 +0,0 @@ -from langchain_core.tracers.run_collector import RunCollectorCallbackHandler - -__all__ = ["RunCollectorCallbackHandler"] diff --git a/libs/community/langchain_community/callbacks/tracers/schemas.py b/libs/community/langchain_community/callbacks/tracers/schemas.py deleted file mode 100644 index e8f34027d34..00000000000 --- a/libs/community/langchain_community/callbacks/tracers/schemas.py +++ /dev/null @@ -1,27 +0,0 @@ -from langchain_core.tracers.schemas import ( - BaseRun, - ChainRun, - LLMRun, - Run, - RunTypeEnum, - ToolRun, - TracerSession, - TracerSessionBase, - TracerSessionV1, - TracerSessionV1Base, - TracerSessionV1Create, -) - -__all__ = [ - "BaseRun", - "ChainRun", - "LLMRun", - "Run", - "RunTypeEnum", - "ToolRun", - "TracerSession", - "TracerSessionBase", - "TracerSessionV1", - "TracerSessionV1Base", - "TracerSessionV1Create", -] diff --git a/libs/community/langchain_community/callbacks/tracers/stdout.py b/libs/community/langchain_community/callbacks/tracers/stdout.py deleted file mode 100644 index 716e2c30ba2..00000000000 --- a/libs/community/langchain_community/callbacks/tracers/stdout.py +++ /dev/null @@ -1,6 +0,0 @@ -from langchain_core.tracers.stdout import ( - ConsoleCallbackHandler, - FunctionCallbackHandler, -) - -__all__ = ["FunctionCallbackHandler", "ConsoleCallbackHandler"] diff --git a/libs/community/langchain_community/callbacks/trubrics_callback.py b/libs/community/langchain_community/callbacks/trubrics_callback.py index f4467c75196..fa697a756ed 100644 --- a/libs/community/langchain_community/callbacks/trubrics_callback.py +++ b/libs/community/langchain_community/callbacks/trubrics_callback.py @@ -2,7 +2,7 @@ import os from typing import Any, Dict, List, Optional from uuid import UUID -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.messages import ( AIMessage, BaseMessage, diff --git a/libs/community/langchain_community/callbacks/wandb_callback.py b/libs/community/langchain_community/callbacks/wandb_callback.py index 0d069d684bd..35559ea539c 100644 --- a/libs/community/langchain_community/callbacks/wandb_callback.py +++ b/libs/community/langchain_community/callbacks/wandb_callback.py @@ -5,8 +5,10 @@ from pathlib import Path from typing import Any, Dict, List, Optional, Sequence, Union from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler -from langchain_core.callbacks.utils import ( +from langchain_core.callbacks import BaseCallbackHandler +from langchain_core.outputs import LLMResult + +from langchain_community.callbacks.utils import ( BaseMetadataCallbackHandler, flatten_dict, hash_string, @@ -14,7 +16,6 @@ from langchain_core.callbacks.utils import ( import_spacy, import_textstat, ) -from langchain_core.outputs import LLMResult def import_wandb() -> Any: diff --git a/libs/community/langchain_community/callbacks/whylabs_callback.py b/libs/community/langchain_community/callbacks/whylabs_callback.py index b6f69ed00ee..8e8f9854912 100644 --- a/libs/community/langchain_community/callbacks/whylabs_callback.py +++ b/libs/community/langchain_community/callbacks/whylabs_callback.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import TYPE_CHECKING, Any, Optional -from langchain_core.callbacks.base import BaseCallbackHandler +from langchain_core.callbacks import BaseCallbackHandler from langchain_core.utils import get_from_env if TYPE_CHECKING: diff --git a/libs/community/langchain_community/chat_models/anthropic.py b/libs/community/langchain_community/chat_models/anthropic.py index cc293b2a635..52cac612d92 100644 --- a/libs/community/langchain_community/chat_models/anthropic.py +++ b/libs/community/langchain_community/chat_models/anthropic.py @@ -1,6 +1,6 @@ from typing import Any, AsyncIterator, Dict, Iterator, List, Optional, cast -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/azureml_endpoint.py b/libs/community/langchain_community/chat_models/azureml_endpoint.py index c70c02be684..111f0502b1f 100644 --- a/libs/community/langchain_community/chat_models/azureml_endpoint.py +++ b/libs/community/langchain_community/chat_models/azureml_endpoint.py @@ -1,7 +1,7 @@ import json from typing import Any, Dict, List, Optional, cast -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.chat_models import SimpleChatModel from langchain_core.messages import ( AIMessage, diff --git a/libs/community/langchain_community/chat_models/baichuan.py b/libs/community/langchain_community/chat_models/baichuan.py index 781e57f0c7d..14cf4a57e2e 100644 --- a/libs/community/langchain_community/chat_models/baichuan.py +++ b/libs/community/langchain_community/chat_models/baichuan.py @@ -5,7 +5,7 @@ import time from typing import Any, Dict, Iterator, List, Mapping, Optional, Type import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.chat_models import ( BaseChatModel, generate_from_stream, diff --git a/libs/community/langchain_community/chat_models/baidu_qianfan_endpoint.py b/libs/community/langchain_community/chat_models/baidu_qianfan_endpoint.py index 88ad802ed55..b006325c677 100644 --- a/libs/community/langchain_community/chat_models/baidu_qianfan_endpoint.py +++ b/libs/community/langchain_community/chat_models/baidu_qianfan_endpoint.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, AsyncIterator, Dict, Iterator, List, Mapping, Optional, cast -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/bedrock.py b/libs/community/langchain_community/chat_models/bedrock.py index 71b87968f63..e0a44254d1b 100644 --- a/libs/community/langchain_community/chat_models/bedrock.py +++ b/libs/community/langchain_community/chat_models/bedrock.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Iterator, List, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( CallbackManagerForLLMRun, ) from langchain_core.language_models.chat_models import BaseChatModel diff --git a/libs/community/langchain_community/chat_models/cohere.py b/libs/community/langchain_community/chat_models/cohere.py index 252db8a297b..f74abcee3ca 100644 --- a/libs/community/langchain_community/chat_models/cohere.py +++ b/libs/community/langchain_community/chat_models/cohere.py @@ -1,6 +1,6 @@ from typing import Any, AsyncIterator, Dict, Iterator, List, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/ernie.py b/libs/community/langchain_community/chat_models/ernie.py index b48df0e8ae1..8d69669afc2 100644 --- a/libs/community/langchain_community/chat_models/ernie.py +++ b/libs/community/langchain_community/chat_models/ernie.py @@ -3,7 +3,7 @@ import threading from typing import Any, Dict, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.chat_models import BaseChatModel from langchain_core.messages import ( AIMessage, diff --git a/libs/community/langchain_community/chat_models/fake.py b/libs/community/langchain_community/chat_models/fake.py index e1268ad4fd3..2ce4b00117b 100644 --- a/libs/community/langchain_community/chat_models/fake.py +++ b/libs/community/langchain_community/chat_models/fake.py @@ -3,7 +3,7 @@ import asyncio import time from typing import Any, AsyncIterator, Dict, Iterator, List, Optional, Union -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/fireworks.py b/libs/community/langchain_community/chat_models/fireworks.py index 82216ba3cc0..5a7669c91f6 100644 --- a/libs/community/langchain_community/chat_models/fireworks.py +++ b/libs/community/langchain_community/chat_models/fireworks.py @@ -10,7 +10,7 @@ from typing import ( Union, ) -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/gigachat.py b/libs/community/langchain_community/chat_models/gigachat.py index 35db98c2239..1349a40c621 100644 --- a/libs/community/langchain_community/chat_models/gigachat.py +++ b/libs/community/langchain_community/chat_models/gigachat.py @@ -1,7 +1,7 @@ import logging from typing import Any, AsyncIterator, Iterator, List, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/google_palm.py b/libs/community/langchain_community/chat_models/google_palm.py index cd0c42d3951..fdf53b3b26b 100644 --- a/libs/community/langchain_community/chat_models/google_palm.py +++ b/libs/community/langchain_community/chat_models/google_palm.py @@ -4,7 +4,7 @@ from __future__ import annotations import logging from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, cast -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/human.py b/libs/community/langchain_community/chat_models/human.py index 98d6049954a..0ac1a407c92 100644 --- a/libs/community/langchain_community/chat_models/human.py +++ b/libs/community/langchain_community/chat_models/human.py @@ -5,7 +5,7 @@ from io import StringIO from typing import Any, Callable, Dict, List, Mapping, Optional import yaml -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/hunyuan.py b/libs/community/langchain_community/chat_models/hunyuan.py index 8822a3635f3..badbb1f2f6f 100644 --- a/libs/community/langchain_community/chat_models/hunyuan.py +++ b/libs/community/langchain_community/chat_models/hunyuan.py @@ -8,7 +8,7 @@ from typing import Any, Dict, Iterator, List, Mapping, Optional, Type from urllib.parse import urlparse import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.chat_models import ( BaseChatModel, generate_from_stream, diff --git a/libs/community/langchain_community/chat_models/javelin_ai_gateway.py b/libs/community/langchain_community/chat_models/javelin_ai_gateway.py index 51201e2d5cf..6b7001b6260 100644 --- a/libs/community/langchain_community/chat_models/javelin_ai_gateway.py +++ b/libs/community/langchain_community/chat_models/javelin_ai_gateway.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional, cast -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/jinachat.py b/libs/community/langchain_community/chat_models/jinachat.py index 0261cdca685..8846e3110cc 100644 --- a/libs/community/langchain_community/chat_models/jinachat.py +++ b/libs/community/langchain_community/chat_models/jinachat.py @@ -16,7 +16,7 @@ from typing import ( Union, ) -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/konko.py b/libs/community/langchain_community/chat_models/konko.py index 70ac4806f53..3a5269351ef 100644 --- a/libs/community/langchain_community/chat_models/konko.py +++ b/libs/community/langchain_community/chat_models/konko.py @@ -16,7 +16,7 @@ from typing import ( ) import requests -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( CallbackManagerForLLMRun, ) from langchain_core.language_models.chat_models import ( diff --git a/libs/community/langchain_community/chat_models/litellm.py b/libs/community/langchain_community/chat_models/litellm.py index 228989167e8..fb30d7463c1 100644 --- a/libs/community/langchain_community/chat_models/litellm.py +++ b/libs/community/langchain_community/chat_models/litellm.py @@ -16,7 +16,7 @@ from typing import ( Union, ) -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/minimax.py b/libs/community/langchain_community/chat_models/minimax.py index 0e71de9df1a..f2385510a43 100644 --- a/libs/community/langchain_community/chat_models/minimax.py +++ b/libs/community/langchain_community/chat_models/minimax.py @@ -2,7 +2,7 @@ import logging from typing import Any, Dict, List, Optional, cast -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/mlflow_ai_gateway.py b/libs/community/langchain_community/chat_models/mlflow_ai_gateway.py index bb9ab18f2e4..5674f69fc2c 100644 --- a/libs/community/langchain_community/chat_models/mlflow_ai_gateway.py +++ b/libs/community/langchain_community/chat_models/mlflow_ai_gateway.py @@ -4,7 +4,7 @@ import warnings from functools import partial from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/ollama.py b/libs/community/langchain_community/chat_models/ollama.py index 2776c2c4954..2a15b6dc6ef 100644 --- a/libs/community/langchain_community/chat_models/ollama.py +++ b/libs/community/langchain_community/chat_models/ollama.py @@ -1,7 +1,7 @@ import json from typing import Any, Iterator, List, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( CallbackManagerForLLMRun, ) from langchain_core.language_models.chat_models import BaseChatModel diff --git a/libs/community/langchain_community/chat_models/pai_eas_endpoint.py b/libs/community/langchain_community/chat_models/pai_eas_endpoint.py index be2ae45dd57..85f13246817 100644 --- a/libs/community/langchain_community/chat_models/pai_eas_endpoint.py +++ b/libs/community/langchain_community/chat_models/pai_eas_endpoint.py @@ -5,7 +5,7 @@ from functools import partial from typing import Any, AsyncIterator, Dict, List, Optional, cast import requests -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/promptlayer_openai.py b/libs/community/langchain_community/chat_models/promptlayer_openai.py index 0f9f0342a73..dcdaa6e4cff 100644 --- a/libs/community/langchain_community/chat_models/promptlayer_openai.py +++ b/libs/community/langchain_community/chat_models/promptlayer_openai.py @@ -2,7 +2,7 @@ import datetime from typing import Any, Dict, List, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/tongyi.py b/libs/community/langchain_community/chat_models/tongyi.py index 166ae4a4604..59ea6bec915 100644 --- a/libs/community/langchain_community/chat_models/tongyi.py +++ b/libs/community/langchain_community/chat_models/tongyi.py @@ -13,7 +13,7 @@ from typing import ( Type, ) -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.chat_models import ( BaseChatModel, generate_from_stream, diff --git a/libs/community/langchain_community/chat_models/vertexai.py b/libs/community/langchain_community/chat_models/vertexai.py index ca02ddeb96f..e3afed8c115 100644 --- a/libs/community/langchain_community/chat_models/vertexai.py +++ b/libs/community/langchain_community/chat_models/vertexai.py @@ -5,7 +5,7 @@ import logging from dataclasses import dataclass, field from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Union, cast -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/chat_models/volcengine_maas.py b/libs/community/langchain_community/chat_models/volcengine_maas.py index 8428ddcc7e3..56ca0b1236a 100644 --- a/libs/community/langchain_community/chat_models/volcengine_maas.py +++ b/libs/community/langchain_community/chat_models/volcengine_maas.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, Dict, Iterator, List, Mapping, Optional, cast -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.chat_models import BaseChatModel from langchain_core.messages import ( AIMessage, diff --git a/libs/community/langchain_community/chat_models/yandex.py b/libs/community/langchain_community/chat_models/yandex.py index 8d9766d7cb9..f94be83a899 100644 --- a/libs/community/langchain_community/chat_models/yandex.py +++ b/libs/community/langchain_community/chat_models/yandex.py @@ -2,7 +2,7 @@ import logging from typing import Any, Dict, List, Optional, Tuple, cast -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/ai21.py b/libs/community/langchain_community/llms/ai21.py index 9a39e753036..dd86ba516ae 100644 --- a/libs/community/langchain_community/llms/ai21.py +++ b/libs/community/langchain_community/llms/ai21.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Optional, cast import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import BaseModel, Extra, SecretStr, root_validator from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/aleph_alpha.py b/libs/community/langchain_community/llms/aleph_alpha.py index 4beda59a5cd..8ae891024b8 100644 --- a/libs/community/langchain_community/llms/aleph_alpha.py +++ b/libs/community/langchain_community/llms/aleph_alpha.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional, Sequence -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/amazon_api_gateway.py b/libs/community/langchain_community/llms/amazon_api_gateway.py index cd67b508263..be2266a331c 100644 --- a/libs/community/langchain_community/llms/amazon_api_gateway.py +++ b/libs/community/langchain_community/llms/amazon_api_gateway.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra diff --git a/libs/community/langchain_community/llms/anthropic.py b/libs/community/langchain_community/llms/anthropic.py index 9e6e2ef8091..0c8f48c2a36 100644 --- a/libs/community/langchain_community/llms/anthropic.py +++ b/libs/community/langchain_community/llms/anthropic.py @@ -11,7 +11,7 @@ from typing import ( Optional, ) -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/anyscale.py b/libs/community/langchain_community/llms/anyscale.py index c3a0c12cdff..3d2f37b7d81 100644 --- a/libs/community/langchain_community/llms/anyscale.py +++ b/libs/community/langchain_community/llms/anyscale.py @@ -12,7 +12,7 @@ from typing import ( cast, ) -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/arcee.py b/libs/community/langchain_community/llms/arcee.py index 6ecd102937e..cab21c60e68 100644 --- a/libs/community/langchain_community/llms/arcee.py +++ b/libs/community/langchain_community/llms/arcee.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional, Union, cast -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, SecretStr, root_validator from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/aviary.py b/libs/community/langchain_community/llms/aviary.py index 0d115745486..60c3794422d 100644 --- a/libs/community/langchain_community/llms/aviary.py +++ b/libs/community/langchain_community/llms/aviary.py @@ -3,7 +3,7 @@ import os from typing import Any, Dict, List, Mapping, Optional, Union, cast import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/azureml_endpoint.py b/libs/community/langchain_community/llms/azureml_endpoint.py index f33e8b74ef5..c9e73df6c63 100644 --- a/libs/community/langchain_community/llms/azureml_endpoint.py +++ b/libs/community/langchain_community/llms/azureml_endpoint.py @@ -4,7 +4,7 @@ import warnings from abc import abstractmethod from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import BaseModel, validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/baidu_qianfan_endpoint.py b/libs/community/langchain_community/llms/baidu_qianfan_endpoint.py index 928ce6c3944..09d765de9d4 100644 --- a/libs/community/langchain_community/llms/baidu_qianfan_endpoint.py +++ b/libs/community/langchain_community/llms/baidu_qianfan_endpoint.py @@ -10,7 +10,7 @@ from typing import ( Optional, ) -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/bananadev.py b/libs/community/langchain_community/llms/bananadev.py index 9716513c694..88ab7f5e58c 100644 --- a/libs/community/langchain_community/llms/bananadev.py +++ b/libs/community/langchain_community/llms/bananadev.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, Field, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/baseten.py b/libs/community/langchain_community/llms/baseten.py index e7cb8e9d61c..9b3f70b7744 100644 --- a/libs/community/langchain_community/llms/baseten.py +++ b/libs/community/langchain_community/llms/baseten.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Field diff --git a/libs/community/langchain_community/llms/beam.py b/libs/community/langchain_community/llms/beam.py index e8927b96f17..dfdb4375359 100644 --- a/libs/community/langchain_community/llms/beam.py +++ b/libs/community/langchain_community/llms/beam.py @@ -7,7 +7,7 @@ import time from typing import Any, Dict, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, Field, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/bedrock.py b/libs/community/langchain_community/llms/bedrock.py index c0c8ae57a56..b5e2b3c1c60 100644 --- a/libs/community/langchain_community/llms/bedrock.py +++ b/libs/community/langchain_community/llms/bedrock.py @@ -3,7 +3,7 @@ import warnings from abc import ABC from typing import Any, Dict, Iterator, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.outputs import GenerationChunk from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator diff --git a/libs/community/langchain_community/llms/bittensor.py b/libs/community/langchain_community/llms/bittensor.py index a7257c7dde5..3d28533f514 100644 --- a/libs/community/langchain_community/llms/bittensor.py +++ b/libs/community/langchain_community/llms/bittensor.py @@ -3,7 +3,7 @@ import json import ssl from typing import Any, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM diff --git a/libs/community/langchain_community/llms/cerebriumai.py b/libs/community/langchain_community/llms/cerebriumai.py index 86267672fac..9586c8544f3 100644 --- a/libs/community/langchain_community/llms/cerebriumai.py +++ b/libs/community/langchain_community/llms/cerebriumai.py @@ -2,7 +2,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, Field, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/chatglm.py b/libs/community/langchain_community/llms/chatglm.py index 2c73169b1ad..84e2294c05d 100644 --- a/libs/community/langchain_community/llms/chatglm.py +++ b/libs/community/langchain_community/llms/chatglm.py @@ -2,7 +2,7 @@ import logging from typing import Any, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_community.llms.utils import enforce_stop_tokens diff --git a/libs/community/langchain_community/llms/clarifai.py b/libs/community/langchain_community/llms/clarifai.py index 8513bf78871..7690bd9bdd2 100644 --- a/libs/community/langchain_community/llms/clarifai.py +++ b/libs/community/langchain_community/llms/clarifai.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.outputs import Generation, LLMResult from langchain_core.pydantic_v1 import Extra, root_validator diff --git a/libs/community/langchain_community/llms/cohere.py b/libs/community/langchain_community/llms/cohere.py index 5431b992afc..18a86c44613 100644 --- a/libs/community/langchain_community/llms/cohere.py +++ b/libs/community/langchain_community/llms/cohere.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, Callable, Dict, List, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/ctransformers.py b/libs/community/langchain_community/llms/ctransformers.py index 1debfcee488..b532b1585c5 100644 --- a/libs/community/langchain_community/llms/ctransformers.py +++ b/libs/community/langchain_community/llms/ctransformers.py @@ -1,7 +1,7 @@ from functools import partial from typing import Any, Dict, List, Optional, Sequence -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/ctranslate2.py b/libs/community/langchain_community/llms/ctranslate2.py index 54dacb371fd..84e357aa8e5 100644 --- a/libs/community/langchain_community/llms/ctranslate2.py +++ b/libs/community/langchain_community/llms/ctranslate2.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional, Union -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import BaseLLM from langchain_core.outputs import Generation, LLMResult from langchain_core.pydantic_v1 import Field, root_validator diff --git a/libs/community/langchain_community/llms/deepinfra.py b/libs/community/langchain_community/llms/deepinfra.py index f51bdcdbb98..412de97cf7e 100644 --- a/libs/community/langchain_community/llms/deepinfra.py +++ b/libs/community/langchain_community/llms/deepinfra.py @@ -2,7 +2,7 @@ import json from typing import Any, AsyncIterator, Dict, Iterator, List, Mapping, Optional import aiohttp -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/deepsparse.py b/libs/community/langchain_community/llms/deepsparse.py index 44059ebb615..1d8166e687c 100644 --- a/libs/community/langchain_community/llms/deepsparse.py +++ b/libs/community/langchain_community/llms/deepsparse.py @@ -1,7 +1,7 @@ # flake8: noqa from typing import Any, AsyncIterator, Dict, Iterator, List, Optional, Union from langchain_core.pydantic_v1 import root_validator -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/edenai.py b/libs/community/langchain_community/llms/edenai.py index e6ed5767e72..5a4bd8754c1 100644 --- a/libs/community/langchain_community/llms/edenai.py +++ b/libs/community/langchain_community/llms/edenai.py @@ -3,7 +3,7 @@ import logging from typing import Any, Dict, List, Literal, Optional from aiohttp import ClientSession -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/fake.py b/libs/community/langchain_community/llms/fake.py index 63ab214ff5e..929fd19eb24 100644 --- a/libs/community/langchain_community/llms/fake.py +++ b/libs/community/langchain_community/llms/fake.py @@ -2,7 +2,7 @@ import asyncio import time from typing import Any, AsyncIterator, Iterator, List, Mapping, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/fireworks.py b/libs/community/langchain_community/llms/fireworks.py index e986839db4c..205f64aa452 100644 --- a/libs/community/langchain_community/llms/fireworks.py +++ b/libs/community/langchain_community/llms/fireworks.py @@ -2,7 +2,7 @@ import asyncio from concurrent.futures import ThreadPoolExecutor from typing import Any, AsyncIterator, Callable, Dict, Iterator, List, Optional, Union -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/forefrontai.py b/libs/community/langchain_community/llms/forefrontai.py index 25b03619201..b4220ad9a92 100644 --- a/libs/community/langchain_community/llms/forefrontai.py +++ b/libs/community/langchain_community/llms/forefrontai.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, SecretStr, root_validator from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/gigachat.py b/libs/community/langchain_community/llms/gigachat.py index db6a4541a1d..61f0893980a 100644 --- a/libs/community/langchain_community/llms/gigachat.py +++ b/libs/community/langchain_community/llms/gigachat.py @@ -4,7 +4,7 @@ import logging from functools import cached_property from typing import Any, AsyncIterator, Dict, Iterator, List, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/google_palm.py b/libs/community/langchain_community/llms/google_palm.py index 03e1ab8d60a..0027af6244f 100644 --- a/libs/community/langchain_community/llms/google_palm.py +++ b/libs/community/langchain_community/llms/google_palm.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, Dict, List, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.outputs import Generation, LLMResult from langchain_core.pydantic_v1 import BaseModel, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/gooseai.py b/libs/community/langchain_community/llms/gooseai.py index 42b585d78c3..27ff257ab63 100644 --- a/libs/community/langchain_community/llms/gooseai.py +++ b/libs/community/langchain_community/llms/gooseai.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, Field, SecretStr, root_validator from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/gpt4all.py b/libs/community/langchain_community/llms/gpt4all.py index 8cecb06c066..83dace226bb 100644 --- a/libs/community/langchain_community/llms/gpt4all.py +++ b/libs/community/langchain_community/llms/gpt4all.py @@ -1,7 +1,7 @@ from functools import partial from typing import Any, Dict, List, Mapping, Optional, Set -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, Field, root_validator diff --git a/libs/community/langchain_community/llms/gradient_ai.py b/libs/community/langchain_community/llms/gradient_ai.py index aa1b4641503..23ffc1a193f 100644 --- a/libs/community/langchain_community/llms/gradient_ai.py +++ b/libs/community/langchain_community/llms/gradient_ai.py @@ -5,7 +5,7 @@ from typing import Any, Dict, List, Mapping, Optional, Sequence, TypedDict import aiohttp import requests -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/huggingface_endpoint.py b/libs/community/langchain_community/llms/huggingface_endpoint.py index 238cc9c2f77..d429e2fd935 100644 --- a/libs/community/langchain_community/llms/huggingface_endpoint.py +++ b/libs/community/langchain_community/llms/huggingface_endpoint.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/huggingface_hub.py b/libs/community/langchain_community/llms/huggingface_hub.py index bdcf84941d5..32facc244b0 100644 --- a/libs/community/langchain_community/llms/huggingface_hub.py +++ b/libs/community/langchain_community/llms/huggingface_hub.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/huggingface_pipeline.py b/libs/community/langchain_community/llms/huggingface_pipeline.py index 1f8689517f7..9b2e94db326 100644 --- a/libs/community/langchain_community/llms/huggingface_pipeline.py +++ b/libs/community/langchain_community/llms/huggingface_pipeline.py @@ -4,7 +4,7 @@ import importlib.util import logging from typing import Any, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import BaseLLM from langchain_core.outputs import Generation, LLMResult from langchain_core.pydantic_v1 import Extra diff --git a/libs/community/langchain_community/llms/huggingface_text_gen_inference.py b/libs/community/langchain_community/llms/huggingface_text_gen_inference.py index cc35c844e2e..b23aaa6e9bd 100644 --- a/libs/community/langchain_community/llms/huggingface_text_gen_inference.py +++ b/libs/community/langchain_community/llms/huggingface_text_gen_inference.py @@ -1,7 +1,7 @@ import logging from typing import Any, AsyncIterator, Dict, Iterator, List, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) @@ -36,7 +36,7 @@ class HuggingFaceTextGenInference(LLM): print(llm("What is Deep Learning?")) # Streaming response example - from langchain_core.callbacks import streaming_stdout + from langchain_community.callbacks import streaming_stdout callbacks = [streaming_stdout.StreamingStdOutCallbackHandler()] llm = HuggingFaceTextGenInference( diff --git a/libs/community/langchain_community/llms/human.py b/libs/community/langchain_community/llms/human.py index c4dd88dec1c..8ee75db3c4a 100644 --- a/libs/community/langchain_community/llms/human.py +++ b/libs/community/langchain_community/llms/human.py @@ -1,6 +1,6 @@ from typing import Any, Callable, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Field diff --git a/libs/community/langchain_community/llms/javelin_ai_gateway.py b/libs/community/langchain_community/llms/javelin_ai_gateway.py index ef57dd7849f..d53e4a9bf72 100644 --- a/libs/community/langchain_community/llms/javelin_ai_gateway.py +++ b/libs/community/langchain_community/llms/javelin_ai_gateway.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/koboldai.py b/libs/community/langchain_community/llms/koboldai.py index 152b4ded9f3..ad121755386 100644 --- a/libs/community/langchain_community/llms/koboldai.py +++ b/libs/community/langchain_community/llms/koboldai.py @@ -2,7 +2,7 @@ import logging from typing import Any, Dict, List, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM logger = logging.getLogger(__name__) diff --git a/libs/community/langchain_community/llms/llamacpp.py b/libs/community/langchain_community/llms/llamacpp.py index c89383812a4..c29ca74ef75 100644 --- a/libs/community/langchain_community/llms/llamacpp.py +++ b/libs/community/langchain_community/llms/llamacpp.py @@ -4,7 +4,7 @@ import logging from pathlib import Path from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Union -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.outputs import GenerationChunk from langchain_core.pydantic_v1 import Field, root_validator diff --git a/libs/community/langchain_community/llms/manifest.py b/libs/community/langchain_community/llms/manifest.py index fe855d6e0a5..2852ab1d7c7 100644 --- a/libs/community/langchain_community/llms/manifest.py +++ b/libs/community/langchain_community/llms/manifest.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, root_validator diff --git a/libs/community/langchain_community/llms/minimax.py b/libs/community/langchain_community/llms/minimax.py index 57c40202f4b..a2375b7445f 100644 --- a/libs/community/langchain_community/llms/minimax.py +++ b/libs/community/langchain_community/llms/minimax.py @@ -10,7 +10,7 @@ from typing import ( ) import requests -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( CallbackManagerForLLMRun, ) from langchain_core.language_models.llms import LLM diff --git a/libs/community/langchain_community/llms/mlflow_ai_gateway.py b/libs/community/langchain_community/llms/mlflow_ai_gateway.py index 607537048d8..776307a6bd3 100644 --- a/libs/community/langchain_community/llms/mlflow_ai_gateway.py +++ b/libs/community/langchain_community/llms/mlflow_ai_gateway.py @@ -3,7 +3,7 @@ from __future__ import annotations import warnings from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import BaseModel, Extra diff --git a/libs/community/langchain_community/llms/modal.py b/libs/community/langchain_community/llms/modal.py index 2b349434264..6ccac3c0d8e 100644 --- a/libs/community/langchain_community/llms/modal.py +++ b/libs/community/langchain_community/llms/modal.py @@ -2,7 +2,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, Field, root_validator diff --git a/libs/community/langchain_community/llms/mosaicml.py b/libs/community/langchain_community/llms/mosaicml.py index 74c5654626f..b73e0d5e214 100644 --- a/libs/community/langchain_community/llms/mosaicml.py +++ b/libs/community/langchain_community/llms/mosaicml.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/nlpcloud.py b/libs/community/langchain_community/llms/nlpcloud.py index 2472bdfa4f2..bdff6404290 100644 --- a/libs/community/langchain_community/llms/nlpcloud.py +++ b/libs/community/langchain_community/llms/nlpcloud.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, SecretStr, root_validator from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/octoai_endpoint.py b/libs/community/langchain_community/llms/octoai_endpoint.py index 6467795add9..a6002b8ae06 100644 --- a/libs/community/langchain_community/llms/octoai_endpoint.py +++ b/libs/community/langchain_community/llms/octoai_endpoint.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/ollama.py b/libs/community/langchain_community/llms/ollama.py index a81a45a4be0..3551ba446ef 100644 --- a/libs/community/langchain_community/llms/ollama.py +++ b/libs/community/langchain_community/llms/ollama.py @@ -2,7 +2,7 @@ import json from typing import Any, Dict, Iterator, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models import BaseLanguageModel from langchain_core.language_models.llms import BaseLLM from langchain_core.outputs import GenerationChunk, LLMResult diff --git a/libs/community/langchain_community/llms/opaqueprompts.py b/libs/community/langchain_community/llms/opaqueprompts.py index b1983f1085f..34f14c515c1 100644 --- a/libs/community/langchain_community/llms/opaqueprompts.py +++ b/libs/community/langchain_community/llms/opaqueprompts.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models import BaseLanguageModel from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, root_validator diff --git a/libs/community/langchain_community/llms/openllm.py b/libs/community/langchain_community/llms/openllm.py index 5270632876e..afb5a18f9ba 100644 --- a/libs/community/langchain_community/llms/openllm.py +++ b/libs/community/langchain_community/llms/openllm.py @@ -15,7 +15,7 @@ from typing import ( overload, ) -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/pai_eas_endpoint.py b/libs/community/langchain_community/llms/pai_eas_endpoint.py index 5a12a80db5f..b74b9ca2a3d 100644 --- a/libs/community/langchain_community/llms/pai_eas_endpoint.py +++ b/libs/community/langchain_community/llms/pai_eas_endpoint.py @@ -3,7 +3,7 @@ import logging from typing import Any, Dict, Iterator, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.outputs import GenerationChunk from langchain_core.pydantic_v1 import root_validator diff --git a/libs/community/langchain_community/llms/petals.py b/libs/community/langchain_community/llms/petals.py index c1d5cff8dec..1508d9d3036 100644 --- a/libs/community/langchain_community/llms/petals.py +++ b/libs/community/langchain_community/llms/petals.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, Field, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/pipelineai.py b/libs/community/langchain_community/llms/pipelineai.py index a171d596a89..91182d99760 100644 --- a/libs/community/langchain_community/llms/pipelineai.py +++ b/libs/community/langchain_community/llms/pipelineai.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/predibase.py b/libs/community/langchain_community/llms/predibase.py index cd8679f6c5e..2aaafd9128f 100644 --- a/libs/community/langchain_community/llms/predibase.py +++ b/libs/community/langchain_community/llms/predibase.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Field diff --git a/libs/community/langchain_community/llms/predictionguard.py b/libs/community/langchain_community/llms/predictionguard.py index 3b953ecedaa..51291500ca7 100644 --- a/libs/community/langchain_community/llms/predictionguard.py +++ b/libs/community/langchain_community/llms/predictionguard.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict, List, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/promptlayer_openai.py b/libs/community/langchain_community/llms/promptlayer_openai.py index dbcf98cbd99..d74b6dd4495 100644 --- a/libs/community/langchain_community/llms/promptlayer_openai.py +++ b/libs/community/langchain_community/llms/promptlayer_openai.py @@ -1,7 +1,7 @@ import datetime from typing import Any, List, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/replicate.py b/libs/community/langchain_community/llms/replicate.py index 86c35a7a24d..041c664d73f 100644 --- a/libs/community/langchain_community/llms/replicate.py +++ b/libs/community/langchain_community/llms/replicate.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.outputs import GenerationChunk from langchain_core.pydantic_v1 import Extra, Field, root_validator diff --git a/libs/community/langchain_community/llms/rwkv.py b/libs/community/langchain_community/llms/rwkv.py index fa91b293b35..470c2005372 100644 --- a/libs/community/langchain_community/llms/rwkv.py +++ b/libs/community/langchain_community/llms/rwkv.py @@ -5,7 +5,7 @@ Based on https://github.com/saharNooby/rwkv.cpp/blob/master/rwkv/chat_with_bot.p """ from typing import Any, Dict, List, Mapping, Optional, Set -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator diff --git a/libs/community/langchain_community/llms/sagemaker_endpoint.py b/libs/community/langchain_community/llms/sagemaker_endpoint.py index 072998f42ce..7ca76fc411b 100644 --- a/libs/community/langchain_community/llms/sagemaker_endpoint.py +++ b/libs/community/langchain_community/llms/sagemaker_endpoint.py @@ -4,7 +4,7 @@ import json from abc import abstractmethod from typing import Any, Dict, Generic, Iterator, List, Mapping, Optional, TypeVar, Union -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, root_validator diff --git a/libs/community/langchain_community/llms/self_hosted.py b/libs/community/langchain_community/llms/self_hosted.py index 6b6b4a7eb0a..043ffca136c 100644 --- a/libs/community/langchain_community/llms/self_hosted.py +++ b/libs/community/langchain_community/llms/self_hosted.py @@ -3,7 +3,7 @@ import logging import pickle from typing import Any, Callable, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra diff --git a/libs/community/langchain_community/llms/self_hosted_hugging_face.py b/libs/community/langchain_community/llms/self_hosted_hugging_face.py index 9901fed99c6..465d74c6770 100644 --- a/libs/community/langchain_community/llms/self_hosted_hugging_face.py +++ b/libs/community/langchain_community/llms/self_hosted_hugging_face.py @@ -2,7 +2,7 @@ import importlib.util import logging from typing import Any, Callable, List, Mapping, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.pydantic_v1 import Extra from langchain_community.llms.self_hosted import SelfHostedPipeline diff --git a/libs/community/langchain_community/llms/stochasticai.py b/libs/community/langchain_community/llms/stochasticai.py index 1f2bf0aadcb..0b3637e9aff 100644 --- a/libs/community/langchain_community/llms/stochasticai.py +++ b/libs/community/langchain_community/llms/stochasticai.py @@ -3,7 +3,7 @@ import time from typing import Any, Dict, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, Field, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/symblai_nebula.py b/libs/community/langchain_community/llms/symblai_nebula.py index c5c0a43fed2..afe6598f238 100644 --- a/libs/community/langchain_community/llms/symblai_nebula.py +++ b/libs/community/langchain_community/llms/symblai_nebula.py @@ -3,7 +3,7 @@ import logging from typing import Any, Callable, Dict, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, SecretStr, root_validator from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/textgen.py b/libs/community/langchain_community/llms/textgen.py index 1068e5de013..d9e569e8d0c 100644 --- a/libs/community/langchain_community/llms/textgen.py +++ b/libs/community/langchain_community/llms/textgen.py @@ -3,7 +3,7 @@ import logging from typing import Any, AsyncIterator, Dict, Iterator, List, Optional import requests -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/titan_takeoff.py b/libs/community/langchain_community/llms/titan_takeoff.py index 3d52bcecb1b..103a81b59c6 100644 --- a/libs/community/langchain_community/llms/titan_takeoff.py +++ b/libs/community/langchain_community/llms/titan_takeoff.py @@ -1,7 +1,7 @@ from typing import Any, Iterator, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.outputs import GenerationChunk from requests.exceptions import ConnectionError diff --git a/libs/community/langchain_community/llms/titan_takeoff_pro.py b/libs/community/langchain_community/llms/titan_takeoff_pro.py index 62289f2fa47..52679cc3e84 100644 --- a/libs/community/langchain_community/llms/titan_takeoff_pro.py +++ b/libs/community/langchain_community/llms/titan_takeoff_pro.py @@ -1,7 +1,7 @@ from typing import Any, Iterator, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.outputs import GenerationChunk from requests.exceptions import ConnectionError diff --git a/libs/community/langchain_community/llms/together.py b/libs/community/langchain_community/llms/together.py index 5c63bdd79ba..a0fc2242692 100644 --- a/libs/community/langchain_community/llms/together.py +++ b/libs/community/langchain_community/llms/together.py @@ -3,7 +3,7 @@ import logging from typing import Any, Dict, List, Optional from aiohttp import ClientSession -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/tongyi.py b/libs/community/langchain_community/llms/tongyi.py index 0ee21cfa4f4..d4c225ba07a 100644 --- a/libs/community/langchain_community/llms/tongyi.py +++ b/libs/community/langchain_community/llms/tongyi.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, Callable, Dict, List, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.outputs import Generation, LLMResult from langchain_core.pydantic_v1 import Field, root_validator diff --git a/libs/community/langchain_community/llms/vertexai.py b/libs/community/langchain_community/llms/vertexai.py index e03c8f8dc5b..d4689d68e9e 100644 --- a/libs/community/langchain_community/llms/vertexai.py +++ b/libs/community/langchain_community/llms/vertexai.py @@ -11,7 +11,7 @@ from typing import ( Optional, ) -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/llms/vllm.py b/libs/community/langchain_community/llms/vllm.py index 897dc43fad6..b3a33c0bf93 100644 --- a/libs/community/langchain_community/llms/vllm.py +++ b/libs/community/langchain_community/llms/vllm.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import BaseLLM from langchain_core.outputs import Generation, LLMResult from langchain_core.pydantic_v1 import Field, root_validator diff --git a/libs/community/langchain_community/llms/volcengine_maas.py b/libs/community/langchain_community/llms/volcengine_maas.py index eeb18e1b1ce..9f32005f464 100644 --- a/libs/community/langchain_community/llms/volcengine_maas.py +++ b/libs/community/langchain_community/llms/volcengine_maas.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, Dict, Iterator, List, Optional -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.outputs import GenerationChunk from langchain_core.pydantic_v1 import BaseModel, Field, root_validator diff --git a/libs/community/langchain_community/llms/watsonxllm.py b/libs/community/langchain_community/llms/watsonxllm.py index 3836af679ae..5efbd31234e 100644 --- a/libs/community/langchain_community/llms/watsonxllm.py +++ b/libs/community/langchain_community/llms/watsonxllm.py @@ -2,7 +2,7 @@ import logging import os from typing import Any, Dict, Iterator, List, Mapping, Optional, Union -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import BaseLLM from langchain_core.outputs import Generation, GenerationChunk from langchain_core.pydantic_v1 import Extra, SecretStr, root_validator diff --git a/libs/community/langchain_community/llms/writer.py b/libs/community/langchain_community/llms/writer.py index 490dc1d5231..3b7bc6a06c4 100644 --- a/libs/community/langchain_community/llms/writer.py +++ b/libs/community/langchain_community/llms/writer.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Mapping, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/llms/xinference.py b/libs/community/langchain_community/llms/xinference.py index 4af7edae764..0c44daa3880 100644 --- a/libs/community/langchain_community/llms/xinference.py +++ b/libs/community/langchain_community/llms/xinference.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Dict, Generator, List, Mapping, Optional, Union -from langchain_core.callbacks.manager import CallbackManagerForLLMRun +from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM if TYPE_CHECKING: diff --git a/libs/community/langchain_community/llms/yandex.py b/libs/community/langchain_community/llms/yandex.py index 8f372043928..d82daeba55c 100644 --- a/libs/community/langchain_community/llms/yandex.py +++ b/libs/community/langchain_community/llms/yandex.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/tools/ainetwork/app.py b/libs/community/langchain_community/tools/ainetwork/app.py index 6e1b4e69c7e..faef6120f9f 100644 --- a/libs/community/langchain_community/tools/ainetwork/app.py +++ b/libs/community/langchain_community/tools/ainetwork/app.py @@ -3,7 +3,7 @@ import json from enum import Enum from typing import List, Optional, Type, Union -from langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun +from langchain_core.callbacks import AsyncCallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.ainetwork.base import AINBaseTool diff --git a/libs/community/langchain_community/tools/ainetwork/base.py b/libs/community/langchain_community/tools/ainetwork/base.py index 4cea1864c11..2f941275769 100644 --- a/libs/community/langchain_community/tools/ainetwork/base.py +++ b/libs/community/langchain_community/tools/ainetwork/base.py @@ -5,7 +5,7 @@ import threading from enum import Enum from typing import TYPE_CHECKING, Any, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/ainetwork/owner.py b/libs/community/langchain_community/tools/ainetwork/owner.py index 6708682fe60..a89134f2a05 100644 --- a/libs/community/langchain_community/tools/ainetwork/owner.py +++ b/libs/community/langchain_community/tools/ainetwork/owner.py @@ -2,7 +2,7 @@ import builtins import json from typing import List, Optional, Type, Union -from langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun +from langchain_core.callbacks import AsyncCallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.ainetwork.base import AINBaseTool, OperationType diff --git a/libs/community/langchain_community/tools/ainetwork/rule.py b/libs/community/langchain_community/tools/ainetwork/rule.py index 8555530684c..309010f5ba3 100644 --- a/libs/community/langchain_community/tools/ainetwork/rule.py +++ b/libs/community/langchain_community/tools/ainetwork/rule.py @@ -2,7 +2,7 @@ import builtins import json from typing import Optional, Type -from langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun +from langchain_core.callbacks import AsyncCallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.ainetwork.base import AINBaseTool, OperationType diff --git a/libs/community/langchain_community/tools/ainetwork/transfer.py b/libs/community/langchain_community/tools/ainetwork/transfer.py index 47c1cce4b76..deab34ad9c2 100644 --- a/libs/community/langchain_community/tools/ainetwork/transfer.py +++ b/libs/community/langchain_community/tools/ainetwork/transfer.py @@ -1,7 +1,7 @@ import json from typing import Optional, Type -from langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun +from langchain_core.callbacks import AsyncCallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.ainetwork.base import AINBaseTool diff --git a/libs/community/langchain_community/tools/ainetwork/value.py b/libs/community/langchain_community/tools/ainetwork/value.py index f1da3491561..300e36c573c 100644 --- a/libs/community/langchain_community/tools/ainetwork/value.py +++ b/libs/community/langchain_community/tools/ainetwork/value.py @@ -2,7 +2,7 @@ import builtins import json from typing import Optional, Type, Union -from langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun +from langchain_core.callbacks import AsyncCallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.ainetwork.base import AINBaseTool, OperationType diff --git a/libs/community/langchain_community/tools/amadeus/closest_airport.py b/libs/community/langchain_community/tools/amadeus/closest_airport.py index a5988143dba..6838a6cb51b 100644 --- a/libs/community/langchain_community/tools/amadeus/closest_airport.py +++ b/libs/community/langchain_community/tools/amadeus/closest_airport.py @@ -1,7 +1,7 @@ from typing import Optional, Type from langchain.chains import LLMChain -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.chat_models import ChatOpenAI diff --git a/libs/community/langchain_community/tools/amadeus/flight_search.py b/libs/community/langchain_community/tools/amadeus/flight_search.py index a046ae462e3..85c173c1198 100644 --- a/libs/community/langchain_community/tools/amadeus/flight_search.py +++ b/libs/community/langchain_community/tools/amadeus/flight_search.py @@ -2,7 +2,7 @@ import logging from datetime import datetime as dt from typing import Dict, Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.amadeus.base import AmadeusBaseTool diff --git a/libs/community/langchain_community/tools/arxiv/tool.py b/libs/community/langchain_community/tools/arxiv/tool.py index 2b459dda4c7..023cd8939c3 100644 --- a/libs/community/langchain_community/tools/arxiv/tool.py +++ b/libs/community/langchain_community/tools/arxiv/tool.py @@ -2,7 +2,7 @@ from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/azure_cognitive_services/form_recognizer.py b/libs/community/langchain_community/tools/azure_cognitive_services/form_recognizer.py index 72ed7df440d..42d11b4ac4e 100644 --- a/libs/community/langchain_community/tools/azure_cognitive_services/form_recognizer.py +++ b/libs/community/langchain_community/tools/azure_cognitive_services/form_recognizer.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, Dict, List, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import root_validator from langchain_core.tools import BaseTool from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/tools/azure_cognitive_services/image_analysis.py b/libs/community/langchain_community/tools/azure_cognitive_services/image_analysis.py index 2d85a312f19..801aa57bd2d 100644 --- a/libs/community/langchain_community/tools/azure_cognitive_services/image_analysis.py +++ b/libs/community/langchain_community/tools/azure_cognitive_services/image_analysis.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, Dict, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import root_validator from langchain_core.tools import BaseTool from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/tools/azure_cognitive_services/speech2text.py b/libs/community/langchain_community/tools/azure_cognitive_services/speech2text.py index 03b38460790..b1aa90cb701 100644 --- a/libs/community/langchain_community/tools/azure_cognitive_services/speech2text.py +++ b/libs/community/langchain_community/tools/azure_cognitive_services/speech2text.py @@ -4,7 +4,7 @@ import logging import time from typing import Any, Dict, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import root_validator from langchain_core.tools import BaseTool from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/tools/azure_cognitive_services/text2speech.py b/libs/community/langchain_community/tools/azure_cognitive_services/text2speech.py index 0e230cb7078..f65049f13a9 100644 --- a/libs/community/langchain_community/tools/azure_cognitive_services/text2speech.py +++ b/libs/community/langchain_community/tools/azure_cognitive_services/text2speech.py @@ -4,7 +4,7 @@ import logging import tempfile from typing import Any, Dict, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import root_validator from langchain_core.tools import BaseTool from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/tools/azure_cognitive_services/text_analytics_health.py b/libs/community/langchain_community/tools/azure_cognitive_services/text_analytics_health.py index 896c723e150..00e97dfc55a 100644 --- a/libs/community/langchain_community/tools/azure_cognitive_services/text_analytics_health.py +++ b/libs/community/langchain_community/tools/azure_cognitive_services/text_analytics_health.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Any, Dict, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import root_validator from langchain_core.tools import BaseTool from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/tools/bing_search/tool.py b/libs/community/langchain_community/tools/bing_search/tool.py index a808eea0dbc..027f2750c94 100644 --- a/libs/community/langchain_community/tools/bing_search/tool.py +++ b/libs/community/langchain_community/tools/bing_search/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.bing_search import BingSearchAPIWrapper diff --git a/libs/community/langchain_community/tools/brave_search/tool.py b/libs/community/langchain_community/tools/brave_search/tool.py index e5870cb1f09..4ca8d68501e 100644 --- a/libs/community/langchain_community/tools/brave_search/tool.py +++ b/libs/community/langchain_community/tools/brave_search/tool.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.brave_search import BraveSearchWrapper diff --git a/libs/community/langchain_community/tools/clickup/tool.py b/libs/community/langchain_community/tools/clickup/tool.py index 41ef90c5ea4..02762a5139b 100644 --- a/libs/community/langchain_community/tools/clickup/tool.py +++ b/libs/community/langchain_community/tools/clickup/tool.py @@ -28,7 +28,7 @@ agent = initialize_agent( """ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/dataforseo_api_search/tool.py b/libs/community/langchain_community/tools/dataforseo_api_search/tool.py index bf367d48ddf..bb10187f8d5 100644 --- a/libs/community/langchain_community/tools/dataforseo_api_search/tool.py +++ b/libs/community/langchain_community/tools/dataforseo_api_search/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/ddg_search/tool.py b/libs/community/langchain_community/tools/ddg_search/tool.py index 2af4b6e5edf..c748422a03f 100644 --- a/libs/community/langchain_community/tools/ddg_search/tool.py +++ b/libs/community/langchain_community/tools/ddg_search/tool.py @@ -3,7 +3,7 @@ import warnings from typing import Any, Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/e2b_data_analysis/tool.py b/libs/community/langchain_community/tools/e2b_data_analysis/tool.py index de1e0642d27..0794b87469e 100644 --- a/libs/community/langchain_community/tools/e2b_data_analysis/tool.py +++ b/libs/community/langchain_community/tools/e2b_data_analysis/tool.py @@ -7,7 +7,7 @@ from io import StringIO from sys import version_info from typing import IO, TYPE_CHECKING, Any, Callable, List, Optional, Type -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManager, CallbackManagerForToolRun, diff --git a/libs/community/langchain_community/tools/edenai/audio_speech_to_text.py b/libs/community/langchain_community/tools/edenai/audio_speech_to_text.py index 54e03e5b1c0..00f158ed53b 100644 --- a/libs/community/langchain_community/tools/edenai/audio_speech_to_text.py +++ b/libs/community/langchain_community/tools/edenai/audio_speech_to_text.py @@ -6,7 +6,7 @@ import time from typing import List, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import validator from langchain_community.tools.edenai.edenai_base_tool import EdenaiTool diff --git a/libs/community/langchain_community/tools/edenai/audio_text_to_speech.py b/libs/community/langchain_community/tools/edenai/audio_text_to_speech.py index 6728f6df78e..575b9a70b52 100644 --- a/libs/community/langchain_community/tools/edenai/audio_text_to_speech.py +++ b/libs/community/langchain_community/tools/edenai/audio_text_to_speech.py @@ -4,7 +4,7 @@ import logging from typing import Dict, List, Literal, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import Field, root_validator, validator from langchain_community.tools.edenai.edenai_base_tool import EdenaiTool diff --git a/libs/community/langchain_community/tools/edenai/edenai_base_tool.py b/libs/community/langchain_community/tools/edenai/edenai_base_tool.py index 23041dc4057..ac28df9dc4e 100644 --- a/libs/community/langchain_community/tools/edenai/edenai_base_tool.py +++ b/libs/community/langchain_community/tools/edenai/edenai_base_tool.py @@ -5,7 +5,7 @@ from abc import abstractmethod from typing import Any, Dict, List, Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import root_validator from langchain_core.tools import BaseTool from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/tools/edenai/image_explicitcontent.py b/libs/community/langchain_community/tools/edenai/image_explicitcontent.py index f9a924f5a01..fbeb4c1ec19 100644 --- a/libs/community/langchain_community/tools/edenai/image_explicitcontent.py +++ b/libs/community/langchain_community/tools/edenai/image_explicitcontent.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_community.tools.edenai.edenai_base_tool import EdenaiTool diff --git a/libs/community/langchain_community/tools/edenai/image_objectdetection.py b/libs/community/langchain_community/tools/edenai/image_objectdetection.py index 2c0ac5454ec..e40d464d5c7 100644 --- a/libs/community/langchain_community/tools/edenai/image_objectdetection.py +++ b/libs/community/langchain_community/tools/edenai/image_objectdetection.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_community.tools.edenai.edenai_base_tool import EdenaiTool diff --git a/libs/community/langchain_community/tools/edenai/ocr_identityparser.py b/libs/community/langchain_community/tools/edenai/ocr_identityparser.py index 5177f41375a..6af27c92fd6 100644 --- a/libs/community/langchain_community/tools/edenai/ocr_identityparser.py +++ b/libs/community/langchain_community/tools/edenai/ocr_identityparser.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_community.tools.edenai.edenai_base_tool import EdenaiTool diff --git a/libs/community/langchain_community/tools/edenai/ocr_invoiceparser.py b/libs/community/langchain_community/tools/edenai/ocr_invoiceparser.py index 87824157650..6b2e7d8befe 100644 --- a/libs/community/langchain_community/tools/edenai/ocr_invoiceparser.py +++ b/libs/community/langchain_community/tools/edenai/ocr_invoiceparser.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_community.tools.edenai.edenai_base_tool import EdenaiTool diff --git a/libs/community/langchain_community/tools/edenai/text_moderation.py b/libs/community/langchain_community/tools/edenai/text_moderation.py index 47e6f1d9ab9..44d1308117f 100644 --- a/libs/community/langchain_community/tools/edenai/text_moderation.py +++ b/libs/community/langchain_community/tools/edenai/text_moderation.py @@ -3,7 +3,7 @@ from __future__ import annotations import logging from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_community.tools.edenai.edenai_base_tool import EdenaiTool diff --git a/libs/community/langchain_community/tools/eleven_labs/text2speech.py b/libs/community/langchain_community/tools/eleven_labs/text2speech.py index fa0bc6aa65e..d1a68ba7a5c 100644 --- a/libs/community/langchain_community/tools/eleven_labs/text2speech.py +++ b/libs/community/langchain_community/tools/eleven_labs/text2speech.py @@ -2,7 +2,7 @@ import tempfile from enum import Enum from typing import Any, Dict, Optional, Union -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import root_validator from langchain_core.tools import BaseTool from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/tools/file_management/copy.py b/libs/community/langchain_community/tools/file_management/copy.py index 9ba38a40967..f91081003d1 100644 --- a/libs/community/langchain_community/tools/file_management/copy.py +++ b/libs/community/langchain_community/tools/file_management/copy.py @@ -1,7 +1,7 @@ import shutil from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/file_management/delete.py b/libs/community/langchain_community/tools/file_management/delete.py index 25c822d2e16..c2694762aed 100644 --- a/libs/community/langchain_community/tools/file_management/delete.py +++ b/libs/community/langchain_community/tools/file_management/delete.py @@ -1,7 +1,7 @@ import os from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/file_management/file_search.py b/libs/community/langchain_community/tools/file_management/file_search.py index 28366e75b13..c77abd0bef9 100644 --- a/libs/community/langchain_community/tools/file_management/file_search.py +++ b/libs/community/langchain_community/tools/file_management/file_search.py @@ -2,7 +2,7 @@ import fnmatch import os from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/file_management/list_dir.py b/libs/community/langchain_community/tools/file_management/list_dir.py index 3c54b65e68f..d8b700134ae 100644 --- a/libs/community/langchain_community/tools/file_management/list_dir.py +++ b/libs/community/langchain_community/tools/file_management/list_dir.py @@ -1,7 +1,7 @@ import os from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/file_management/move.py b/libs/community/langchain_community/tools/file_management/move.py index bc633a79e3a..fc3bb778d8e 100644 --- a/libs/community/langchain_community/tools/file_management/move.py +++ b/libs/community/langchain_community/tools/file_management/move.py @@ -1,7 +1,7 @@ import shutil from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/file_management/read.py b/libs/community/langchain_community/tools/file_management/read.py index fd011250a3f..42cc1515e7e 100644 --- a/libs/community/langchain_community/tools/file_management/read.py +++ b/libs/community/langchain_community/tools/file_management/read.py @@ -1,6 +1,6 @@ from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/file_management/write.py b/libs/community/langchain_community/tools/file_management/write.py index 9f600b03c91..b42b70256b7 100644 --- a/libs/community/langchain_community/tools/file_management/write.py +++ b/libs/community/langchain_community/tools/file_management/write.py @@ -1,6 +1,6 @@ from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/github/tool.py b/libs/community/langchain_community/tools/github/tool.py index 1ad9f101d93..89253183632 100644 --- a/libs/community/langchain_community/tools/github/tool.py +++ b/libs/community/langchain_community/tools/github/tool.py @@ -9,7 +9,7 @@ To use this tool, you must first set as environment variables: """ from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/gitlab/tool.py b/libs/community/langchain_community/tools/gitlab/tool.py index d10de6ec042..92ea8b98bf9 100644 --- a/libs/community/langchain_community/tools/gitlab/tool.py +++ b/libs/community/langchain_community/tools/gitlab/tool.py @@ -9,7 +9,7 @@ To use this tool, you must first set as environment variables: """ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/gmail/create_draft.py b/libs/community/langchain_community/tools/gmail/create_draft.py index 7d59d8355d9..b8e6ac93c61 100644 --- a/libs/community/langchain_community/tools/gmail/create_draft.py +++ b/libs/community/langchain_community/tools/gmail/create_draft.py @@ -2,7 +2,7 @@ import base64 from email.message import EmailMessage from typing import List, Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.gmail.base import GmailBaseTool diff --git a/libs/community/langchain_community/tools/gmail/get_message.py b/libs/community/langchain_community/tools/gmail/get_message.py index e4e841bdf65..79b963453e8 100644 --- a/libs/community/langchain_community/tools/gmail/get_message.py +++ b/libs/community/langchain_community/tools/gmail/get_message.py @@ -2,7 +2,7 @@ import base64 import email from typing import Dict, Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.gmail.base import GmailBaseTool diff --git a/libs/community/langchain_community/tools/gmail/get_thread.py b/libs/community/langchain_community/tools/gmail/get_thread.py index 8605771a526..c42c90924b6 100644 --- a/libs/community/langchain_community/tools/gmail/get_thread.py +++ b/libs/community/langchain_community/tools/gmail/get_thread.py @@ -1,6 +1,6 @@ from typing import Dict, Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.gmail.base import GmailBaseTool diff --git a/libs/community/langchain_community/tools/gmail/search.py b/libs/community/langchain_community/tools/gmail/search.py index 7018bb432d4..bcd16e09311 100644 --- a/libs/community/langchain_community/tools/gmail/search.py +++ b/libs/community/langchain_community/tools/gmail/search.py @@ -3,7 +3,7 @@ import email from enum import Enum from typing import Any, Dict, List, Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.gmail.base import GmailBaseTool diff --git a/libs/community/langchain_community/tools/gmail/send_message.py b/libs/community/langchain_community/tools/gmail/send_message.py index ceb7b0db4f7..52a2b97d29c 100644 --- a/libs/community/langchain_community/tools/gmail/send_message.py +++ b/libs/community/langchain_community/tools/gmail/send_message.py @@ -4,7 +4,7 @@ from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from typing import Any, Dict, List, Optional, Union -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.gmail.base import GmailBaseTool diff --git a/libs/community/langchain_community/tools/golden_query/tool.py b/libs/community/langchain_community/tools/golden_query/tool.py index 877034f1993..78e08cd7cf9 100644 --- a/libs/community/langchain_community/tools/golden_query/tool.py +++ b/libs/community/langchain_community/tools/golden_query/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.golden_query import GoldenQueryAPIWrapper diff --git a/libs/community/langchain_community/tools/google_cloud/texttospeech.py b/libs/community/langchain_community/tools/google_cloud/texttospeech.py index e4065a6c6d7..fc1e5852efb 100644 --- a/libs/community/langchain_community/tools/google_cloud/texttospeech.py +++ b/libs/community/langchain_community/tools/google_cloud/texttospeech.py @@ -3,7 +3,7 @@ from __future__ import annotations import tempfile from typing import TYPE_CHECKING, Any, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.vertexai import get_client_info diff --git a/libs/community/langchain_community/tools/google_finance/tool.py b/libs/community/langchain_community/tools/google_finance/tool.py index 77ac3ccc2dc..82eb82de318 100644 --- a/libs/community/langchain_community/tools/google_finance/tool.py +++ b/libs/community/langchain_community/tools/google_finance/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper diff --git a/libs/community/langchain_community/tools/google_jobs/tool.py b/libs/community/langchain_community/tools/google_jobs/tool.py index 85ee9b1b190..6a83b3043d9 100644 --- a/libs/community/langchain_community/tools/google_jobs/tool.py +++ b/libs/community/langchain_community/tools/google_jobs/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.google_jobs import GoogleJobsAPIWrapper diff --git a/libs/community/langchain_community/tools/google_lens/tool.py b/libs/community/langchain_community/tools/google_lens/tool.py index 88e32be9e21..0a69739e352 100644 --- a/libs/community/langchain_community/tools/google_lens/tool.py +++ b/libs/community/langchain_community/tools/google_lens/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.google_lens import GoogleLensAPIWrapper diff --git a/libs/community/langchain_community/tools/google_places/tool.py b/libs/community/langchain_community/tools/google_places/tool.py index 5883aa32d90..d198350126e 100644 --- a/libs/community/langchain_community/tools/google_places/tool.py +++ b/libs/community/langchain_community/tools/google_places/tool.py @@ -2,7 +2,7 @@ from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/google_scholar/tool.py b/libs/community/langchain_community/tools/google_scholar/tool.py index eaa9e4b484e..49f8769696f 100644 --- a/libs/community/langchain_community/tools/google_scholar/tool.py +++ b/libs/community/langchain_community/tools/google_scholar/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.google_scholar import GoogleScholarAPIWrapper diff --git a/libs/community/langchain_community/tools/google_search/tool.py b/libs/community/langchain_community/tools/google_search/tool.py index ae99bc1c33a..4b6ea4685b4 100644 --- a/libs/community/langchain_community/tools/google_search/tool.py +++ b/libs/community/langchain_community/tools/google_search/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.google_search import GoogleSearchAPIWrapper diff --git a/libs/community/langchain_community/tools/google_serper/tool.py b/libs/community/langchain_community/tools/google_serper/tool.py index 649eeb096de..b94771a894f 100644 --- a/libs/community/langchain_community/tools/google_serper/tool.py +++ b/libs/community/langchain_community/tools/google_serper/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/google_trends/tool.py b/libs/community/langchain_community/tools/google_trends/tool.py index cf7ac1b359e..8b2b5dd8bfb 100644 --- a/libs/community/langchain_community/tools/google_trends/tool.py +++ b/libs/community/langchain_community/tools/google_trends/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.google_trends import GoogleTrendsAPIWrapper diff --git a/libs/community/langchain_community/tools/graphql/tool.py b/libs/community/langchain_community/tools/graphql/tool.py index cfc9281d2c2..a794334cbdb 100644 --- a/libs/community/langchain_community/tools/graphql/tool.py +++ b/libs/community/langchain_community/tools/graphql/tool.py @@ -1,7 +1,7 @@ import json from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.graphql import GraphQLAPIWrapper diff --git a/libs/community/langchain_community/tools/human/tool.py b/libs/community/langchain_community/tools/human/tool.py index df042aacc5a..7b7911577ce 100644 --- a/libs/community/langchain_community/tools/human/tool.py +++ b/libs/community/langchain_community/tools/human/tool.py @@ -2,7 +2,7 @@ from typing import Callable, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/ifttt.py b/libs/community/langchain_community/tools/ifttt.py index 3299f491254..5df673061dc 100644 --- a/libs/community/langchain_community/tools/ifttt.py +++ b/libs/community/langchain_community/tools/ifttt.py @@ -35,7 +35,7 @@ https://maker.ifttt.com/use/YOUR_IFTTT_KEY. Grab the YOUR_IFTTT_KEY value. from typing import Optional import requests -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/jira/tool.py b/libs/community/langchain_community/tools/jira/tool.py index 4900c62cf14..a950d0f7c6d 100644 --- a/libs/community/langchain_community/tools/jira/tool.py +++ b/libs/community/langchain_community/tools/jira/tool.py @@ -30,7 +30,7 @@ agent = initialize_agent( """ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/json/tool.py b/libs/community/langchain_community/tools/json/tool.py index f291c82864d..af392c96cef 100644 --- a/libs/community/langchain_community/tools/json/tool.py +++ b/libs/community/langchain_community/tools/json/tool.py @@ -9,7 +9,7 @@ from typing import Dict, List, Optional, Union from langchain_core.pydantic_v1 import BaseModel -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/memorize/tool.py b/libs/community/langchain_community/tools/memorize/tool.py index 9967274195a..2813c870dcc 100644 --- a/libs/community/langchain_community/tools/memorize/tool.py +++ b/libs/community/langchain_community/tools/memorize/tool.py @@ -1,7 +1,7 @@ from abc import abstractmethod from typing import Any, Optional, Protocol, Sequence, runtime_checkable -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/merriam_webster/tool.py b/libs/community/langchain_community/tools/merriam_webster/tool.py index 26da372ab44..a3d1fa881bb 100644 --- a/libs/community/langchain_community/tools/merriam_webster/tool.py +++ b/libs/community/langchain_community/tools/merriam_webster/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.merriam_webster import MerriamWebsterAPIWrapper diff --git a/libs/community/langchain_community/tools/metaphor_search/tool.py b/libs/community/langchain_community/tools/metaphor_search/tool.py index 15364611799..d81ea0a0ba3 100644 --- a/libs/community/langchain_community/tools/metaphor_search/tool.py +++ b/libs/community/langchain_community/tools/metaphor_search/tool.py @@ -2,7 +2,7 @@ from typing import Dict, List, Optional, Union -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/multion/close_session.py b/libs/community/langchain_community/tools/multion/close_session.py index 5534b126191..7aaead7fa0c 100644 --- a/libs/community/langchain_community/tools/multion/close_session.py +++ b/libs/community/langchain_community/tools/multion/close_session.py @@ -1,7 +1,7 @@ import asyncio from typing import TYPE_CHECKING, Optional, Type -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/multion/create_session.py b/libs/community/langchain_community/tools/multion/create_session.py index d5f0c9fe6b7..9f93676ee18 100644 --- a/libs/community/langchain_community/tools/multion/create_session.py +++ b/libs/community/langchain_community/tools/multion/create_session.py @@ -1,7 +1,7 @@ import asyncio from typing import TYPE_CHECKING, Optional, Type -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/multion/update_session.py b/libs/community/langchain_community/tools/multion/update_session.py index 21f9db7f3ec..97a8f1ff4a3 100644 --- a/libs/community/langchain_community/tools/multion/update_session.py +++ b/libs/community/langchain_community/tools/multion/update_session.py @@ -1,7 +1,7 @@ import asyncio from typing import TYPE_CHECKING, Optional, Type -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/nasa/tool.py b/libs/community/langchain_community/tools/nasa/tool.py index 23ca207779f..f5644661536 100644 --- a/libs/community/langchain_community/tools/nasa/tool.py +++ b/libs/community/langchain_community/tools/nasa/tool.py @@ -5,7 +5,7 @@ the the NASA Image & Video Library and Exoplanet from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/nuclia/tool.py b/libs/community/langchain_community/tools/nuclia/tool.py index 7e2b53c80ef..2f8bae73ff3 100644 --- a/libs/community/langchain_community/tools/nuclia/tool.py +++ b/libs/community/langchain_community/tools/nuclia/tool.py @@ -16,7 +16,7 @@ import os from typing import Any, Dict, Optional, Type, Union import requests -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/office365/create_draft_message.py b/libs/community/langchain_community/tools/office365/create_draft_message.py index 01086423ed0..88c94578a83 100644 --- a/libs/community/langchain_community/tools/office365/create_draft_message.py +++ b/libs/community/langchain_community/tools/office365/create_draft_message.py @@ -1,6 +1,6 @@ from typing import List, Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.office365.base import O365BaseTool diff --git a/libs/community/langchain_community/tools/office365/events_search.py b/libs/community/langchain_community/tools/office365/events_search.py index f6942fd6148..8cb16f7a299 100644 --- a/libs/community/langchain_community/tools/office365/events_search.py +++ b/libs/community/langchain_community/tools/office365/events_search.py @@ -7,7 +7,7 @@ https://learn.microsoft.com/en-us/graph/auth/ from datetime import datetime as dt from typing import Any, Dict, List, Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Extra, Field from langchain_community.tools.office365.base import O365BaseTool diff --git a/libs/community/langchain_community/tools/office365/messages_search.py b/libs/community/langchain_community/tools/office365/messages_search.py index b4c0a90d19e..ad26e42de4e 100644 --- a/libs/community/langchain_community/tools/office365/messages_search.py +++ b/libs/community/langchain_community/tools/office365/messages_search.py @@ -6,7 +6,7 @@ https://learn.microsoft.com/en-us/graph/auth/ from typing import Any, Dict, List, Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Extra, Field from langchain_community.tools.office365.base import O365BaseTool diff --git a/libs/community/langchain_community/tools/office365/send_event.py b/libs/community/langchain_community/tools/office365/send_event.py index 4147b561eee..e8b9d023af7 100644 --- a/libs/community/langchain_community/tools/office365/send_event.py +++ b/libs/community/langchain_community/tools/office365/send_event.py @@ -7,7 +7,7 @@ https://learn.microsoft.com/en-us/graph/auth/ from datetime import datetime as dt from typing import List, Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.office365.base import O365BaseTool diff --git a/libs/community/langchain_community/tools/office365/send_message.py b/libs/community/langchain_community/tools/office365/send_message.py index f9753847ef1..cd7abef976b 100644 --- a/libs/community/langchain_community/tools/office365/send_message.py +++ b/libs/community/langchain_community/tools/office365/send_message.py @@ -1,6 +1,6 @@ from typing import List, Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.office365.base import O365BaseTool diff --git a/libs/community/langchain_community/tools/openweathermap/tool.py b/libs/community/langchain_community/tools/openweathermap/tool.py index f43d00e536b..6060321047c 100644 --- a/libs/community/langchain_community/tools/openweathermap/tool.py +++ b/libs/community/langchain_community/tools/openweathermap/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/playwright/click.py b/libs/community/langchain_community/tools/playwright/click.py index 277bcaf8e20..5cf5cdda148 100644 --- a/libs/community/langchain_community/tools/playwright/click.py +++ b/libs/community/langchain_community/tools/playwright/click.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Optional, Type -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/playwright/current_page.py b/libs/community/langchain_community/tools/playwright/current_page.py index 03b93211f8f..9ea5e0e1f9d 100644 --- a/libs/community/langchain_community/tools/playwright/current_page.py +++ b/libs/community/langchain_community/tools/playwright/current_page.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Optional, Type -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/playwright/extract_hyperlinks.py b/libs/community/langchain_community/tools/playwright/extract_hyperlinks.py index 73dfdbb2bd7..9c6f64911cc 100644 --- a/libs/community/langchain_community/tools/playwright/extract_hyperlinks.py +++ b/libs/community/langchain_community/tools/playwright/extract_hyperlinks.py @@ -3,7 +3,7 @@ from __future__ import annotations import json from typing import TYPE_CHECKING, Any, Optional, Type -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/playwright/extract_text.py b/libs/community/langchain_community/tools/playwright/extract_text.py index 71e62207a71..4f01ea925d0 100644 --- a/libs/community/langchain_community/tools/playwright/extract_text.py +++ b/libs/community/langchain_community/tools/playwright/extract_text.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Optional, Type -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/playwright/get_elements.py b/libs/community/langchain_community/tools/playwright/get_elements.py index f170232b534..3b88529fc75 100644 --- a/libs/community/langchain_community/tools/playwright/get_elements.py +++ b/libs/community/langchain_community/tools/playwright/get_elements.py @@ -3,7 +3,7 @@ from __future__ import annotations import json from typing import TYPE_CHECKING, List, Optional, Sequence, Type -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/playwright/navigate.py b/libs/community/langchain_community/tools/playwright/navigate.py index dc2921e9b01..82f6349ff06 100644 --- a/libs/community/langchain_community/tools/playwright/navigate.py +++ b/libs/community/langchain_community/tools/playwright/navigate.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Optional, Type from urllib.parse import urlparse -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/playwright/navigate_back.py b/libs/community/langchain_community/tools/playwright/navigate_back.py index bb11c9e29b8..5988fa7fe89 100644 --- a/libs/community/langchain_community/tools/playwright/navigate_back.py +++ b/libs/community/langchain_community/tools/playwright/navigate_back.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Optional, Type -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/plugin.py b/libs/community/langchain_community/tools/plugin.py index 491e9a49c41..0966ed5bede 100644 --- a/libs/community/langchain_community/tools/plugin.py +++ b/libs/community/langchain_community/tools/plugin.py @@ -5,7 +5,7 @@ from typing import Optional, Type import requests import yaml -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/powerbi/tool.py b/libs/community/langchain_community/tools/powerbi/tool.py index 33183e33694..56e44eb90d2 100644 --- a/libs/community/langchain_community/tools/powerbi/tool.py +++ b/libs/community/langchain_community/tools/powerbi/tool.py @@ -4,7 +4,7 @@ from time import perf_counter from typing import Any, Dict, Optional, Tuple from langchain.chains.llm import LLMChain -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/pubmed/tool.py b/libs/community/langchain_community/tools/pubmed/tool.py index e603b87ddd0..cd9e1a38884 100644 --- a/libs/community/langchain_community/tools/pubmed/tool.py +++ b/libs/community/langchain_community/tools/pubmed/tool.py @@ -1,6 +1,6 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/reddit_search/tool.py b/libs/community/langchain_community/tools/reddit_search/tool.py index 9d40ce33850..7c0da2a01e7 100644 --- a/libs/community/langchain_community/tools/reddit_search/tool.py +++ b/libs/community/langchain_community/tools/reddit_search/tool.py @@ -2,7 +2,7 @@ from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/requests/tool.py b/libs/community/langchain_community/tools/requests/tool.py index d113f6317a4..ae2a2ca9546 100644 --- a/libs/community/langchain_community/tools/requests/tool.py +++ b/libs/community/langchain_community/tools/requests/tool.py @@ -4,7 +4,7 @@ import json from typing import Any, Dict, Optional from langchain_core.pydantic_v1 import BaseModel -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/scenexplain/tool.py b/libs/community/langchain_community/tools/scenexplain/tool.py index ca6c5ed13e1..5806cd7bb25 100644 --- a/libs/community/langchain_community/tools/scenexplain/tool.py +++ b/libs/community/langchain_community/tools/scenexplain/tool.py @@ -1,7 +1,7 @@ """Tool for the SceneXplain API.""" from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/searchapi/tool.py b/libs/community/langchain_community/tools/searchapi/tool.py index ebf6d5e6611..5e7f5e8917c 100644 --- a/libs/community/langchain_community/tools/searchapi/tool.py +++ b/libs/community/langchain_community/tools/searchapi/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/searx_search/tool.py b/libs/community/langchain_community/tools/searx_search/tool.py index 7a493d0121d..005faf239bf 100644 --- a/libs/community/langchain_community/tools/searx_search/tool.py +++ b/libs/community/langchain_community/tools/searx_search/tool.py @@ -1,7 +1,7 @@ """Tool for the SearxNG search API.""" from typing import Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/shell/tool.py b/libs/community/langchain_community/tools/shell/tool.py index 98db3c4a0a8..e92d51445aa 100644 --- a/libs/community/langchain_community/tools/shell/tool.py +++ b/libs/community/langchain_community/tools/shell/tool.py @@ -3,7 +3,7 @@ import platform import warnings from typing import Any, List, Optional, Type, Union -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/slack/get_channel.py b/libs/community/langchain_community/tools/slack/get_channel.py index 9f7ff106737..3cb4f513ee2 100644 --- a/libs/community/langchain_community/tools/slack/get_channel.py +++ b/libs/community/langchain_community/tools/slack/get_channel.py @@ -2,7 +2,7 @@ import json import logging from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_community.tools.slack.base import SlackBaseTool diff --git a/libs/community/langchain_community/tools/slack/get_message.py b/libs/community/langchain_community/tools/slack/get_message.py index 3ae1f0af34c..a6504f38b76 100644 --- a/libs/community/langchain_community/tools/slack/get_message.py +++ b/libs/community/langchain_community/tools/slack/get_message.py @@ -2,7 +2,7 @@ import json import logging from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.slack.base import SlackBaseTool diff --git a/libs/community/langchain_community/tools/slack/schedule_message.py b/libs/community/langchain_community/tools/slack/schedule_message.py index 2711112a2f1..90edc9bcb9d 100644 --- a/libs/community/langchain_community/tools/slack/schedule_message.py +++ b/libs/community/langchain_community/tools/slack/schedule_message.py @@ -2,7 +2,7 @@ import logging from datetime import datetime as dt from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.slack.base import SlackBaseTool diff --git a/libs/community/langchain_community/tools/slack/send_message.py b/libs/community/langchain_community/tools/slack/send_message.py index 53dffe78a4c..c5e8a875ad0 100644 --- a/libs/community/langchain_community/tools/slack/send_message.py +++ b/libs/community/langchain_community/tools/slack/send_message.py @@ -1,6 +1,6 @@ from typing import Optional, Type -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import BaseModel, Field from langchain_community.tools.slack.base import SlackBaseTool diff --git a/libs/community/langchain_community/tools/sleep/tool.py b/libs/community/langchain_community/tools/sleep/tool.py index b3b939d52f5..d56a114ace4 100644 --- a/libs/community/langchain_community/tools/sleep/tool.py +++ b/libs/community/langchain_community/tools/sleep/tool.py @@ -3,7 +3,7 @@ from asyncio import sleep as asleep from time import sleep from typing import Optional, Type -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/spark_sql/tool.py b/libs/community/langchain_community/tools/spark_sql/tool.py index d5726c9cbac..340962db421 100644 --- a/libs/community/langchain_community/tools/spark_sql/tool.py +++ b/libs/community/langchain_community/tools/spark_sql/tool.py @@ -5,7 +5,7 @@ from typing import Any, Dict, Optional from langchain_core.pydantic_v1 import BaseModel, Field, root_validator from langchain_core.language_models import BaseLanguageModel -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/sql_database/tool.py b/libs/community/langchain_community/tools/sql_database/tool.py index 24184caae3a..6ba0e43406e 100644 --- a/libs/community/langchain_community/tools/sql_database/tool.py +++ b/libs/community/langchain_community/tools/sql_database/tool.py @@ -5,7 +5,7 @@ from typing import Any, Dict, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain_core.language_models import BaseLanguageModel -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/stackexchange/tool.py b/libs/community/langchain_community/tools/stackexchange/tool.py index dcf22b6c190..fa398b0f148 100644 --- a/libs/community/langchain_community/tools/stackexchange/tool.py +++ b/libs/community/langchain_community/tools/stackexchange/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.stackexchange import StackExchangeAPIWrapper diff --git a/libs/community/langchain_community/tools/steam/tool.py b/libs/community/langchain_community/tools/steam/tool.py index cd0cfdbc8b9..69706c8ada9 100644 --- a/libs/community/langchain_community/tools/steam/tool.py +++ b/libs/community/langchain_community/tools/steam/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.steam import SteamWebAPIWrapper diff --git a/libs/community/langchain_community/tools/steamship_image_generation/tool.py b/libs/community/langchain_community/tools/steamship_image_generation/tool.py index 79c5e5563a6..145f362785a 100644 --- a/libs/community/langchain_community/tools/steamship_image_generation/tool.py +++ b/libs/community/langchain_community/tools/steamship_image_generation/tool.py @@ -16,7 +16,7 @@ from __future__ import annotations from enum import Enum from typing import TYPE_CHECKING, Dict, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.pydantic_v1 import root_validator from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/langchain_community/tools/tavily_search/tool.py b/libs/community/langchain_community/tools/tavily_search/tool.py index cc6dec1b7a9..af33cacc4f7 100644 --- a/libs/community/langchain_community/tools/tavily_search/tool.py +++ b/libs/community/langchain_community/tools/tavily_search/tool.py @@ -2,7 +2,7 @@ from typing import Dict, List, Optional, Type, Union -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/tools/vectorstore/tool.py b/libs/community/langchain_community/tools/vectorstore/tool.py index b4d5aa1d2bd..c4cb10fc47a 100644 --- a/libs/community/langchain_community/tools/vectorstore/tool.py +++ b/libs/community/langchain_community/tools/vectorstore/tool.py @@ -3,7 +3,7 @@ import json from typing import Any, Dict, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.language_models import BaseLanguageModel from langchain_core.pydantic_v1 import BaseModel, Field from langchain_core.tools import BaseTool diff --git a/libs/community/langchain_community/tools/wikipedia/tool.py b/libs/community/langchain_community/tools/wikipedia/tool.py index 10de0db8006..0ccab574f23 100644 --- a/libs/community/langchain_community/tools/wikipedia/tool.py +++ b/libs/community/langchain_community/tools/wikipedia/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.wikipedia import WikipediaAPIWrapper diff --git a/libs/community/langchain_community/tools/wolfram_alpha/tool.py b/libs/community/langchain_community/tools/wolfram_alpha/tool.py index ab1a0c3bda7..e4364e669a0 100644 --- a/libs/community/langchain_community/tools/wolfram_alpha/tool.py +++ b/libs/community/langchain_community/tools/wolfram_alpha/tool.py @@ -2,7 +2,7 @@ from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.tools import BaseTool from langchain_community.utilities.wolfram_alpha import WolframAlphaAPIWrapper diff --git a/libs/community/langchain_community/tools/yahoo_finance_news.py b/libs/community/langchain_community/tools/yahoo_finance_news.py index c9f7abb8da3..c470fa01d2b 100644 --- a/libs/community/langchain_community/tools/yahoo_finance_news.py +++ b/libs/community/langchain_community/tools/yahoo_finance_news.py @@ -1,6 +1,6 @@ from typing import Iterable, Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_core.documents import Document from langchain_core.tools import BaseTool from requests.exceptions import HTTPError, ReadTimeout diff --git a/libs/community/langchain_community/tools/youtube/search.py b/libs/community/langchain_community/tools/youtube/search.py index bae1382d1f8..580815c3922 100644 --- a/libs/community/langchain_community/tools/youtube/search.py +++ b/libs/community/langchain_community/tools/youtube/search.py @@ -11,7 +11,7 @@ Input to this tool should be a comma separated list, import json from typing import Optional -from langchain_core.callbacks.manager import CallbackManagerForToolRun +from langchain_core.callbacks import CallbackManagerForToolRun from langchain_community.tools import BaseTool diff --git a/libs/community/langchain_community/tools/zapier/tool.py b/libs/community/langchain_community/tools/zapier/tool.py index b33d779c58c..15044070052 100644 --- a/libs/community/langchain_community/tools/zapier/tool.py +++ b/libs/community/langchain_community/tools/zapier/tool.py @@ -82,7 +82,7 @@ agent.run(("Summarize the last email I received regarding Silicon Valley Bank. " from typing import Any, Dict, Optional from langchain_core._api import warn_deprecated -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) diff --git a/libs/community/langchain_community/utilities/vertexai.py b/libs/community/langchain_community/utilities/vertexai.py index 05fd03bf389..f85a009df87 100644 --- a/libs/community/langchain_community/utilities/vertexai.py +++ b/libs/community/langchain_community/utilities/vertexai.py @@ -2,7 +2,7 @@ from importlib import metadata from typing import TYPE_CHECKING, Any, Callable, Optional, Union -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/langchain_community/vectorstores/azuresearch.py b/libs/community/langchain_community/vectorstores/azuresearch.py index a47ffd70944..0b449688bd8 100644 --- a/libs/community/langchain_community/vectorstores/azuresearch.py +++ b/libs/community/langchain_community/vectorstores/azuresearch.py @@ -18,7 +18,7 @@ from typing import ( ) import numpy as np -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForRetrieverRun, CallbackManagerForRetrieverRun, ) diff --git a/libs/community/langchain_community/vectorstores/redis/base.py b/libs/community/langchain_community/vectorstores/redis/base.py index 538e54398cc..6b7732bb4e1 100644 --- a/libs/community/langchain_community/vectorstores/redis/base.py +++ b/libs/community/langchain_community/vectorstores/redis/base.py @@ -23,7 +23,7 @@ from typing import ( import numpy as np import yaml from langchain_core._api import deprecated -from langchain_core.callbacks.manager import CallbackManagerForRetrieverRun +from langchain_core.callbacks import CallbackManagerForRetrieverRun from langchain_core.documents import Document from langchain_core.embeddings import Embeddings from langchain_core.utils import get_from_dict_or_env diff --git a/libs/community/tests/integration_tests/callbacks/test_langchain_tracer.py b/libs/community/tests/integration_tests/callbacks/test_langchain_tracer.py index 8b0352c3cd7..1b347421d25 100644 --- a/libs/community/tests/integration_tests/callbacks/test_langchain_tracer.py +++ b/libs/community/tests/integration_tests/callbacks/test_langchain_tracer.py @@ -7,14 +7,14 @@ from langchain.agents import AgentType, initialize_agent, load_tools from langchain.chains import LLMChain from langchain.chains.constitutional_ai.base import ConstitutionalChain from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple -from langchain_core.callbacks import tracing_enabled -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( atrace_as_chain_group, trace_as_chain_group, tracing_v2_enabled, ) from langchain_core.prompts import PromptTemplate +from langchain_community.callbacks import tracing_enabled from langchain_community.chat_models import ChatOpenAI from langchain_community.llms import OpenAI diff --git a/libs/community/tests/integration_tests/callbacks/test_openai_callback.py b/libs/community/tests/integration_tests/callbacks/test_openai_callback.py index 6131949fdd4..c58ace26600 100644 --- a/libs/community/tests/integration_tests/callbacks/test_openai_callback.py +++ b/libs/community/tests/integration_tests/callbacks/test_openai_callback.py @@ -2,8 +2,8 @@ import asyncio from langchain.agents import AgentType, initialize_agent, load_tools -from langchain_core.callbacks import get_openai_callback +from langchain_community.callbacks import get_openai_callback from langchain_community.llms import OpenAI diff --git a/libs/community/tests/integration_tests/callbacks/test_streamlit_callback.py b/libs/community/tests/integration_tests/callbacks/test_streamlit_callback.py index 3362ad6e475..ba551e5ab71 100644 --- a/libs/community/tests/integration_tests/callbacks/test_streamlit_callback.py +++ b/libs/community/tests/integration_tests/callbacks/test_streamlit_callback.py @@ -6,10 +6,9 @@ from langchain.agents import AgentType, initialize_agent, load_tools # Import the internal StreamlitCallbackHandler from its module - and not from # the `langchain.callbacks.streamlit` package - so that we don't end up using # Streamlit's externally-provided callback handler. -from langchain_core.callbacks.streamlit.streamlit_callback_handler import ( +from langchain_community.callbacks.streamlit.streamlit_callback_handler import ( StreamlitCallbackHandler, ) - from langchain_community.llms import OpenAI diff --git a/libs/community/tests/integration_tests/callbacks/test_wandb_tracer.py b/libs/community/tests/integration_tests/callbacks/test_wandb_tracer.py index eb1046b929d..09565558d9e 100644 --- a/libs/community/tests/integration_tests/callbacks/test_wandb_tracer.py +++ b/libs/community/tests/integration_tests/callbacks/test_wandb_tracer.py @@ -4,7 +4,7 @@ import os from aiohttp import ClientSession from langchain.agents import AgentType, initialize_agent, load_tools -from langchain_core.callbacks.manager import wandb_tracing_enabled +from langchain_core.callbacks import wandb_tracing_enabled from langchain_community.llms import OpenAI diff --git a/libs/community/tests/integration_tests/chat_models/test_anthropic.py b/libs/community/tests/integration_tests/chat_models/test_anthropic.py index 0e5c9a5b4dd..a1ddc14ead1 100644 --- a/libs/community/tests/integration_tests/chat_models/test_anthropic.py +++ b/libs/community/tests/integration_tests/chat_models/test_anthropic.py @@ -2,7 +2,7 @@ from typing import List import pytest -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.messages import AIMessage, BaseMessage, HumanMessage from langchain_core.outputs import ChatGeneration, LLMResult diff --git a/libs/community/tests/integration_tests/chat_models/test_azure_openai.py b/libs/community/tests/integration_tests/chat_models/test_azure_openai.py index bfed4b61b7b..b152d24c908 100644 --- a/libs/community/tests/integration_tests/chat_models/test_azure_openai.py +++ b/libs/community/tests/integration_tests/chat_models/test_azure_openai.py @@ -3,7 +3,7 @@ import os from typing import Any import pytest -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.messages import BaseMessage, HumanMessage from langchain_core.outputs import ChatGeneration, ChatResult, LLMResult diff --git a/libs/community/tests/integration_tests/chat_models/test_bedrock.py b/libs/community/tests/integration_tests/chat_models/test_bedrock.py index 93bdbee7305..301260803d9 100644 --- a/libs/community/tests/integration_tests/chat_models/test_bedrock.py +++ b/libs/community/tests/integration_tests/chat_models/test_bedrock.py @@ -2,7 +2,7 @@ from typing import Any import pytest -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage from langchain_core.outputs import ChatGeneration, LLMResult diff --git a/libs/community/tests/integration_tests/chat_models/test_jinachat.py b/libs/community/tests/integration_tests/chat_models/test_jinachat.py index c263a622fda..0d704ce3867 100644 --- a/libs/community/tests/integration_tests/chat_models/test_jinachat.py +++ b/libs/community/tests/integration_tests/chat_models/test_jinachat.py @@ -3,7 +3,7 @@ from typing import cast import pytest -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage from langchain_core.outputs import ChatGeneration, LLMResult from langchain_core.pydantic_v1 import SecretStr diff --git a/libs/community/tests/integration_tests/chat_models/test_konko.py b/libs/community/tests/integration_tests/chat_models/test_konko.py index a0d08d6ccdf..7cfb5be1c25 100644 --- a/libs/community/tests/integration_tests/chat_models/test_konko.py +++ b/libs/community/tests/integration_tests/chat_models/test_konko.py @@ -2,7 +2,7 @@ from typing import Any import pytest -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage from langchain_core.outputs import ChatGeneration, ChatResult, LLMResult diff --git a/libs/community/tests/integration_tests/chat_models/test_litellm.py b/libs/community/tests/integration_tests/chat_models/test_litellm.py index 86e72ab36df..c71d0d3ac1c 100644 --- a/libs/community/tests/integration_tests/chat_models/test_litellm.py +++ b/libs/community/tests/integration_tests/chat_models/test_litellm.py @@ -1,7 +1,7 @@ """Test Anthropic API wrapper.""" from typing import List -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( CallbackManager, ) from langchain_core.messages import AIMessage, BaseMessage, HumanMessage diff --git a/libs/community/tests/integration_tests/chat_models/test_openai.py b/libs/community/tests/integration_tests/chat_models/test_openai.py index 9eb5b596735..5aaf1596a27 100644 --- a/libs/community/tests/integration_tests/chat_models/test_openai.py +++ b/libs/community/tests/integration_tests/chat_models/test_openai.py @@ -5,8 +5,7 @@ import pytest from langchain.chains.openai_functions import ( create_openai_fn_chain, ) -from langchain_core.callbacks.base import AsyncCallbackHandler -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import AsyncCallbackHandler, CallbackManager from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage from langchain_core.outputs import ( ChatGeneration, diff --git a/libs/community/tests/integration_tests/chat_models/test_pai_eas_chat_endpoint.py b/libs/community/tests/integration_tests/chat_models/test_pai_eas_chat_endpoint.py index 21be21e699d..136153e5855 100644 --- a/libs/community/tests/integration_tests/chat_models/test_pai_eas_chat_endpoint.py +++ b/libs/community/tests/integration_tests/chat_models/test_pai_eas_chat_endpoint.py @@ -1,7 +1,7 @@ """Test AliCloud Pai Eas Chat Model.""" import os -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.messages import AIMessage, BaseMessage, HumanMessage from langchain_core.outputs import ChatGeneration, LLMResult diff --git a/libs/community/tests/integration_tests/chat_models/test_promptlayer_openai.py b/libs/community/tests/integration_tests/chat_models/test_promptlayer_openai.py index 74f61b0d8c8..d037056d72d 100644 --- a/libs/community/tests/integration_tests/chat_models/test_promptlayer_openai.py +++ b/libs/community/tests/integration_tests/chat_models/test_promptlayer_openai.py @@ -1,7 +1,7 @@ """Test PromptLayerChatOpenAI wrapper.""" import pytest -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage from langchain_core.outputs import ChatGeneration, ChatResult, LLMResult diff --git a/libs/community/tests/integration_tests/chat_models/test_qianfan_endpoint.py b/libs/community/tests/integration_tests/chat_models/test_qianfan_endpoint.py index a75e0ec37ce..cd11f76f479 100644 --- a/libs/community/tests/integration_tests/chat_models/test_qianfan_endpoint.py +++ b/libs/community/tests/integration_tests/chat_models/test_qianfan_endpoint.py @@ -5,7 +5,7 @@ from typing import Any from langchain.chains.openai_functions import ( create_openai_fn_chain, ) -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.messages import ( AIMessage, BaseMessage, diff --git a/libs/community/tests/integration_tests/chat_models/test_tongyi.py b/libs/community/tests/integration_tests/chat_models/test_tongyi.py index c0dc3e993fd..ebb92b24b23 100644 --- a/libs/community/tests/integration_tests/chat_models/test_tongyi.py +++ b/libs/community/tests/integration_tests/chat_models/test_tongyi.py @@ -1,6 +1,6 @@ """Test Alibaba Tongyi Chat Model.""" -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.messages import AIMessage, BaseMessage, HumanMessage from langchain_core.outputs import ChatGeneration, LLMResult diff --git a/libs/community/tests/integration_tests/chat_models/test_volcengine_maas.py b/libs/community/tests/integration_tests/chat_models/test_volcengine_maas.py index 1ccb275a83b..06b5f99813a 100644 --- a/libs/community/tests/integration_tests/chat_models/test_volcengine_maas.py +++ b/libs/community/tests/integration_tests/chat_models/test_volcengine_maas.py @@ -1,6 +1,6 @@ """Test volc engine maas chat model.""" -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_community.chat_models.volcengine_maas import VolcEngineMaasChat from langchain_community.schema import ( diff --git a/libs/community/tests/integration_tests/llms/test_anthropic.py b/libs/community/tests/integration_tests/llms/test_anthropic.py index c58ac43d620..c0c10335bdf 100644 --- a/libs/community/tests/integration_tests/llms/test_anthropic.py +++ b/libs/community/tests/integration_tests/llms/test_anthropic.py @@ -2,7 +2,7 @@ from typing import Generator import pytest -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.outputs import LLMResult from langchain_community.llms.anthropic import Anthropic diff --git a/libs/community/tests/integration_tests/llms/test_azure_openai.py b/libs/community/tests/integration_tests/llms/test_azure_openai.py index 643b2a522fb..84a13b4dd2f 100644 --- a/libs/community/tests/integration_tests/llms/test_azure_openai.py +++ b/libs/community/tests/integration_tests/llms/test_azure_openai.py @@ -3,7 +3,7 @@ import os from typing import Any, Generator import pytest -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.outputs import LLMResult from langchain_community.llms import AzureOpenAI diff --git a/libs/community/tests/integration_tests/llms/test_confident.py b/libs/community/tests/integration_tests/llms/test_confident.py index 65598b59b46..843dedef688 100644 --- a/libs/community/tests/integration_tests/llms/test_confident.py +++ b/libs/community/tests/integration_tests/llms/test_confident.py @@ -4,8 +4,8 @@ def test_confident_deepeval() -> None: """Test valid call to Beam.""" from deepeval.metrics.answer_relevancy import AnswerRelevancy - from langchain_core.callbacks.confident_callback import DeepEvalCallbackHandler + from langchain_community.callbacks.confident_callback import DeepEvalCallbackHandler from langchain_community.llms import OpenAI answer_relevancy = AnswerRelevancy(minimum_score=0.3) diff --git a/libs/community/tests/integration_tests/llms/test_openai.py b/libs/community/tests/integration_tests/llms/test_openai.py index a2d215fa7cc..9f3aff0c5e7 100644 --- a/libs/community/tests/integration_tests/llms/test_openai.py +++ b/libs/community/tests/integration_tests/llms/test_openai.py @@ -3,7 +3,7 @@ from pathlib import Path from typing import Generator import pytest -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.outputs import LLMResult from langchain_openai.chat_models import ChatOpenAI from langchain_openai.llms import OpenAI diff --git a/libs/community/tests/integration_tests/llms/test_replicate.py b/libs/community/tests/integration_tests/llms/test_replicate.py index 4a35d8d62e3..a5de0889b46 100644 --- a/libs/community/tests/integration_tests/llms/test_replicate.py +++ b/libs/community/tests/integration_tests/llms/test_replicate.py @@ -1,6 +1,6 @@ """Test Replicate API wrapper.""" -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_community.llms.replicate import Replicate from tests.unit_tests.callbacks.fake_callback_handler import FakeCallbackHandler diff --git a/libs/community/tests/unit_tests/callbacks/fake_callback_handler.py b/libs/community/tests/unit_tests/callbacks/fake_callback_handler.py index 2a2af92269f..66b5425692b 100644 --- a/libs/community/tests/unit_tests/callbacks/fake_callback_handler.py +++ b/libs/community/tests/unit_tests/callbacks/fake_callback_handler.py @@ -3,7 +3,7 @@ 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.callbacks import AsyncCallbackHandler, BaseCallbackHandler from langchain_core.messages import BaseMessage from langchain_core.pydantic_v1 import BaseModel diff --git a/libs/community/tests/unit_tests/callbacks/test_base.py b/libs/community/tests/unit_tests/callbacks/test_base.py index 3df3064e073..b8b00305c99 100644 --- a/libs/community/tests/unit_tests/callbacks/test_base.py +++ b/libs/community/tests/unit_tests/callbacks/test_base.py @@ -1,4 +1,4 @@ -from langchain_core.callbacks.base import __all__ +from langchain_core.callbacks import __all__ EXPECTED_ALL = [ "RetrieverManagerMixin", diff --git a/libs/community/tests/unit_tests/callbacks/test_callback_manager.py b/libs/community/tests/unit_tests/callbacks/test_callback_manager.py index f2d6de04467..30e3196bdaf 100644 --- a/libs/community/tests/unit_tests/callbacks/test_callback_manager.py +++ b/libs/community/tests/unit_tests/callbacks/test_callback_manager.py @@ -4,15 +4,15 @@ from unittest.mock import patch import pytest from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.callbacks.base import BaseCallbackHandler -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManager, + BaseCallbackHandler, CallbackManager, + StdOutCallbackHandler, get_openai_callback, trace_as_chain_group, tracing_v2_enabled, ) -from langchain_core.callbacks.stdout import StdOutCallbackHandler from langchain_core.outputs import LLMResult from langchain_core.tracers.langchain import LangChainTracer, wait_for_all_tracers from langchain_openai.llms import BaseOpenAI diff --git a/libs/community/tests/unit_tests/callbacks/test_imports.py b/libs/community/tests/unit_tests/callbacks/test_imports.py index f031cc1eaa2..d149992fbb1 100644 --- a/libs/community/tests/unit_tests/callbacks/test_imports.py +++ b/libs/community/tests/unit_tests/callbacks/test_imports.py @@ -1,4 +1,4 @@ -from langchain_core.callbacks import __all__ +from langchain_community.callbacks import __all__ EXPECTED_ALL = [ "AimCallbackHandler", diff --git a/libs/community/tests/unit_tests/callbacks/test_manager.py b/libs/community/tests/unit_tests/callbacks/test_manager.py index 1a40fa5c283..2bfaee6e6de 100644 --- a/libs/community/tests/unit_tests/callbacks/test_manager.py +++ b/libs/community/tests/unit_tests/callbacks/test_manager.py @@ -1,4 +1,4 @@ -from langchain_core.callbacks.manager import __all__ +from langchain_core.callbacks import __all__ EXPECTED_ALL = [ "BaseRunManager", diff --git a/libs/community/tests/unit_tests/callbacks/test_openai_info.py b/libs/community/tests/unit_tests/callbacks/test_openai_info.py index 2686d80896c..2aa5b593d88 100644 --- a/libs/community/tests/unit_tests/callbacks/test_openai_info.py +++ b/libs/community/tests/unit_tests/callbacks/test_openai_info.py @@ -2,10 +2,11 @@ from unittest.mock import MagicMock from uuid import uuid4 import pytest -from langchain_core.callbacks import OpenAICallbackHandler from langchain_core.outputs import LLMResult from langchain_openai.llms import BaseOpenAI +from langchain_community.callbacks import OpenAICallbackHandler + @pytest.fixture def handler() -> OpenAICallbackHandler: diff --git a/libs/community/tests/unit_tests/callbacks/test_streamlit_callback.py b/libs/community/tests/unit_tests/callbacks/test_streamlit_callback.py index 12575672c5c..9e75b71f19b 100644 --- a/libs/community/tests/unit_tests/callbacks/test_streamlit_callback.py +++ b/libs/community/tests/unit_tests/callbacks/test_streamlit_callback.py @@ -4,7 +4,7 @@ from typing import Any from unittest import mock from unittest.mock import MagicMock -from langchain_core.callbacks.streamlit import StreamlitCallbackHandler +from langchain_community.callbacks.streamlit import StreamlitCallbackHandler class TestImport(unittest.TestCase): diff --git a/libs/community/tests/unit_tests/callbacks/tracers/test_base_tracer.py b/libs/community/tests/unit_tests/callbacks/tracers/test_base_tracer.py index 92ea3a1a4d0..78163fb9128 100644 --- a/libs/community/tests/unit_tests/callbacks/tracers/test_base_tracer.py +++ b/libs/community/tests/unit_tests/callbacks/tracers/test_base_tracer.py @@ -7,7 +7,7 @@ from uuid import uuid4 import pytest from freezegun import freeze_time -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.messages import HumanMessage from langchain_core.outputs import LLMResult from langchain_core.tracers.base import BaseTracer, TracerException diff --git a/libs/community/tests/unit_tests/callbacks/tracers/test_comet.py b/libs/community/tests/unit_tests/callbacks/tracers/test_comet.py index 7aa2c41c2ee..ffb6c09511d 100644 --- a/libs/community/tests/unit_tests/callbacks/tracers/test_comet.py +++ b/libs/community/tests/unit_tests/callbacks/tracers/test_comet.py @@ -2,9 +2,10 @@ import uuid from types import SimpleNamespace from unittest import mock -from langchain_core.callbacks.tracers import comet from langchain_core.outputs import LLMResult +from langchain_community.callbacks.tracers import comet + def test_comet_tracer__trace_chain_with_single_span__happyflow() -> None: # Setup mocks diff --git a/libs/community/tests/unit_tests/callbacks/tracers/test_langchain_v1.py b/libs/community/tests/unit_tests/callbacks/tracers/test_langchain_v1.py index a3f2b8ea2a2..60afae20225 100644 --- a/libs/community/tests/unit_tests/callbacks/tracers/test_langchain_v1.py +++ b/libs/community/tests/unit_tests/callbacks/tracers/test_langchain_v1.py @@ -7,7 +7,7 @@ from uuid import uuid4 import pytest from freezegun import freeze_time -from langchain_core.callbacks.manager import CallbackManager +from langchain_core.callbacks import CallbackManager from langchain_core.messages import HumanMessage from langchain_core.outputs import LLMResult from langchain_core.tracers.base import BaseTracer, TracerException diff --git a/libs/community/tests/unit_tests/callbacks/tracers/test_logging.py b/libs/community/tests/unit_tests/callbacks/tracers/test_logging.py index 4a500015677..576032ee4e0 100644 --- a/libs/community/tests/unit_tests/callbacks/tracers/test_logging.py +++ b/libs/community/tests/unit_tests/callbacks/tracers/test_logging.py @@ -3,7 +3,8 @@ import sys import uuid import pytest -from langchain_core.callbacks.tracers import LoggingCallbackHandler + +from langchain_community.callbacks.tracers import LoggingCallbackHandler def test_logging( diff --git a/libs/community/tests/unit_tests/llms/fake_chat_model.py b/libs/community/tests/unit_tests/llms/fake_chat_model.py index 7b13dda0680..0582eb5c5cc 100644 --- a/libs/community/tests/unit_tests/llms/fake_chat_model.py +++ b/libs/community/tests/unit_tests/llms/fake_chat_model.py @@ -1,7 +1,7 @@ """Fake Chat Model wrapper for testing purposes.""" from typing import Any, Dict, List, Optional -from langchain_core.callbacks.manager import ( +from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) diff --git a/libs/community/tests/unit_tests/llms/fake_llm.py b/libs/community/tests/unit_tests/llms/fake_llm.py index 09a80504dbe..f4d8ab1228c 100644 --- a/libs/community/tests/unit_tests/llms/fake_llm.py +++ b/libs/community/tests/unit_tests/llms/fake_llm.py @@ -1,7 +1,7 @@ """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.callbacks import CallbackManagerForLLMRun from langchain_core.language_models.llms import LLM from langchain_core.pydantic_v1 import validator diff --git a/libs/langchain/langchain/callbacks/__init__.py b/libs/langchain/langchain/callbacks/__init__.py index 5bd09a2ea00..e2ccae82056 100644 --- a/libs/langchain/langchain/callbacks/__init__.py +++ b/libs/langchain/langchain/callbacks/__init__.py @@ -7,6 +7,11 @@ BaseCallbackHandler --> CallbackHandler # Example: AimCallbackHandler """ +from langchain_core.tracers.context import ( + collect_runs, + tracing_enabled, + tracing_v2_enabled, +) from langchain_core.tracers.langchain import LangChainTracer from langchain.callbacks.aim_callback import AimCallbackHandler @@ -22,13 +27,7 @@ from langchain.callbacks.human import HumanApprovalCallbackHandler from langchain.callbacks.infino_callback import InfinoCallbackHandler from langchain.callbacks.labelstudio_callback import LabelStudioCallbackHandler from langchain.callbacks.llmonitor_callback import LLMonitorCallbackHandler -from langchain.callbacks.manager import ( - collect_runs, - get_openai_callback, - tracing_enabled, - tracing_v2_enabled, - wandb_tracing_enabled, -) +from langchain.callbacks.manager import get_openai_callback, wandb_tracing_enabled from langchain.callbacks.mlflow_callback import MlflowCallbackHandler from langchain.callbacks.openai_info import OpenAICallbackHandler from langchain.callbacks.promptlayer_callback import PromptLayerCallbackHandler diff --git a/libs/langchain/langchain/callbacks/aim_callback.py b/libs/langchain/langchain/callbacks/aim_callback.py index 06e3d52d72f..563cba49061 100644 --- a/libs/langchain/langchain/callbacks/aim_callback.py +++ b/libs/langchain/langchain/callbacks/aim_callback.py @@ -1,431 +1,7 @@ -from copy import deepcopy -from typing import Any, Dict, List, Optional +from langchain_community.callbacks.aim_callback import ( + AimCallbackHandler, + BaseMetadataCallbackHandler, + import_aim, +) -from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.outputs import LLMResult - -from langchain.callbacks.base import BaseCallbackHandler - - -def import_aim() -> Any: - """Import the aim python package and raise an error if it is not installed.""" - try: - import aim - except ImportError: - raise ImportError( - "To use the Aim callback manager you need to have the" - " `aim` python package installed." - "Please install it with `pip install aim`" - ) - return aim - - -class BaseMetadataCallbackHandler: - """This class handles the metadata and associated function states for callbacks. - - Attributes: - step (int): The current step. - starts (int): The number of times the start method has been called. - ends (int): The number of times the end method has been called. - errors (int): The number of times the error method has been called. - text_ctr (int): The number of times the text method has been called. - ignore_llm_ (bool): Whether to ignore llm callbacks. - ignore_chain_ (bool): Whether to ignore chain callbacks. - ignore_agent_ (bool): Whether to ignore agent callbacks. - ignore_retriever_ (bool): Whether to ignore retriever callbacks. - always_verbose_ (bool): Whether to always be verbose. - chain_starts (int): The number of times the chain start method has been called. - chain_ends (int): The number of times the chain end method has been called. - llm_starts (int): The number of times the llm start method has been called. - llm_ends (int): The number of times the llm end method has been called. - llm_streams (int): The number of times the text method has been called. - tool_starts (int): The number of times the tool start method has been called. - tool_ends (int): The number of times the tool end method has been called. - agent_ends (int): The number of times the agent end method has been called. - """ - - def __init__(self) -> None: - self.step = 0 - - self.starts = 0 - self.ends = 0 - self.errors = 0 - self.text_ctr = 0 - - self.ignore_llm_ = False - self.ignore_chain_ = False - self.ignore_agent_ = False - self.ignore_retriever_ = False - self.always_verbose_ = False - - self.chain_starts = 0 - self.chain_ends = 0 - - self.llm_starts = 0 - self.llm_ends = 0 - self.llm_streams = 0 - - self.tool_starts = 0 - self.tool_ends = 0 - - self.agent_ends = 0 - - @property - def always_verbose(self) -> bool: - """Whether to call verbose callbacks even if verbose is False.""" - return self.always_verbose_ - - @property - def ignore_llm(self) -> bool: - """Whether to ignore LLM callbacks.""" - return self.ignore_llm_ - - @property - def ignore_chain(self) -> bool: - """Whether to ignore chain callbacks.""" - return self.ignore_chain_ - - @property - def ignore_agent(self) -> bool: - """Whether to ignore agent callbacks.""" - return self.ignore_agent_ - - @property - def ignore_retriever(self) -> bool: - """Whether to ignore retriever callbacks.""" - return self.ignore_retriever_ - - def get_custom_callback_meta(self) -> Dict[str, Any]: - return { - "step": self.step, - "starts": self.starts, - "ends": self.ends, - "errors": self.errors, - "text_ctr": self.text_ctr, - "chain_starts": self.chain_starts, - "chain_ends": self.chain_ends, - "llm_starts": self.llm_starts, - "llm_ends": self.llm_ends, - "llm_streams": self.llm_streams, - "tool_starts": self.tool_starts, - "tool_ends": self.tool_ends, - "agent_ends": self.agent_ends, - } - - def reset_callback_meta(self) -> None: - """Reset the callback metadata.""" - self.step = 0 - - self.starts = 0 - self.ends = 0 - self.errors = 0 - self.text_ctr = 0 - - self.ignore_llm_ = False - self.ignore_chain_ = False - self.ignore_agent_ = False - self.always_verbose_ = False - - self.chain_starts = 0 - self.chain_ends = 0 - - self.llm_starts = 0 - self.llm_ends = 0 - self.llm_streams = 0 - - self.tool_starts = 0 - self.tool_ends = 0 - - self.agent_ends = 0 - - return None - - -class AimCallbackHandler(BaseMetadataCallbackHandler, BaseCallbackHandler): - """Callback Handler that logs to Aim. - - Parameters: - repo (:obj:`str`, optional): Aim repository path or Repo object to which - Run object is bound. If skipped, default Repo is used. - experiment_name (:obj:`str`, optional): Sets Run's `experiment` property. - 'default' if not specified. Can be used later to query runs/sequences. - system_tracking_interval (:obj:`int`, optional): Sets the tracking interval - in seconds for system usage metrics (CPU, Memory, etc.). Set to `None` - to disable system metrics tracking. - log_system_params (:obj:`bool`, optional): Enable/Disable logging of system - params such as installed packages, git info, environment variables, etc. - - This handler will utilize the associated callback method called and formats - the input of each callback function with metadata regarding the state of LLM run - and then logs the response to Aim. - """ - - def __init__( - self, - repo: Optional[str] = None, - experiment_name: Optional[str] = None, - system_tracking_interval: Optional[int] = 10, - log_system_params: bool = True, - ) -> None: - """Initialize callback handler.""" - - super().__init__() - - aim = import_aim() - self.repo = repo - self.experiment_name = experiment_name - self.system_tracking_interval = system_tracking_interval - self.log_system_params = log_system_params - self._run = aim.Run( - repo=self.repo, - experiment=self.experiment_name, - system_tracking_interval=self.system_tracking_interval, - log_system_params=self.log_system_params, - ) - self._run_hash = self._run.hash - self.action_records: list = [] - - def setup(self, **kwargs: Any) -> None: - aim = import_aim() - - if not self._run: - if self._run_hash: - self._run = aim.Run( - self._run_hash, - repo=self.repo, - system_tracking_interval=self.system_tracking_interval, - ) - else: - self._run = aim.Run( - repo=self.repo, - experiment=self.experiment_name, - system_tracking_interval=self.system_tracking_interval, - log_system_params=self.log_system_params, - ) - self._run_hash = self._run.hash - - if kwargs: - for key, value in kwargs.items(): - self._run.set(key, value, strict=False) - - def on_llm_start( - self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any - ) -> None: - """Run when LLM starts.""" - aim = import_aim() - - self.step += 1 - self.llm_starts += 1 - self.starts += 1 - - resp = {"action": "on_llm_start"} - resp.update(self.get_custom_callback_meta()) - - prompts_res = deepcopy(prompts) - - self._run.track( - [aim.Text(prompt) for prompt in prompts_res], - name="on_llm_start", - context=resp, - ) - - def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None: - """Run when LLM ends running.""" - aim = import_aim() - self.step += 1 - self.llm_ends += 1 - self.ends += 1 - - resp = {"action": "on_llm_end"} - resp.update(self.get_custom_callback_meta()) - - response_res = deepcopy(response) - - generated = [ - aim.Text(generation.text) - for generations in response_res.generations - for generation in generations - ] - self._run.track( - generated, - name="on_llm_end", - context=resp, - ) - - def on_llm_new_token(self, token: str, **kwargs: Any) -> None: - """Run when LLM generates a new token.""" - self.step += 1 - self.llm_streams += 1 - - def on_llm_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when LLM errors.""" - self.step += 1 - self.errors += 1 - - def on_chain_start( - self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any - ) -> None: - """Run when chain starts running.""" - aim = import_aim() - self.step += 1 - self.chain_starts += 1 - self.starts += 1 - - resp = {"action": "on_chain_start"} - resp.update(self.get_custom_callback_meta()) - - inputs_res = deepcopy(inputs) - - self._run.track( - aim.Text(inputs_res["input"]), name="on_chain_start", context=resp - ) - - def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - """Run when chain ends running.""" - aim = import_aim() - self.step += 1 - self.chain_ends += 1 - self.ends += 1 - - resp = {"action": "on_chain_end"} - resp.update(self.get_custom_callback_meta()) - - outputs_res = deepcopy(outputs) - - self._run.track( - aim.Text(outputs_res["output"]), name="on_chain_end", context=resp - ) - - def on_chain_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when chain errors.""" - self.step += 1 - self.errors += 1 - - def on_tool_start( - self, serialized: Dict[str, Any], input_str: str, **kwargs: Any - ) -> None: - """Run when tool starts running.""" - aim = import_aim() - self.step += 1 - self.tool_starts += 1 - self.starts += 1 - - resp = {"action": "on_tool_start"} - resp.update(self.get_custom_callback_meta()) - - self._run.track(aim.Text(input_str), name="on_tool_start", context=resp) - - def on_tool_end(self, output: str, **kwargs: Any) -> None: - """Run when tool ends running.""" - aim = import_aim() - self.step += 1 - self.tool_ends += 1 - self.ends += 1 - - resp = {"action": "on_tool_end"} - resp.update(self.get_custom_callback_meta()) - - self._run.track(aim.Text(output), name="on_tool_end", context=resp) - - def on_tool_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when tool errors.""" - self.step += 1 - self.errors += 1 - - def on_text(self, text: str, **kwargs: Any) -> None: - """ - Run when agent is ending. - """ - self.step += 1 - self.text_ctr += 1 - - def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> None: - """Run when agent ends running.""" - aim = import_aim() - self.step += 1 - self.agent_ends += 1 - self.ends += 1 - - resp = {"action": "on_agent_finish"} - resp.update(self.get_custom_callback_meta()) - - finish_res = deepcopy(finish) - - text = "OUTPUT:\n{}\n\nLOG:\n{}".format( - finish_res.return_values["output"], finish_res.log - ) - self._run.track(aim.Text(text), name="on_agent_finish", context=resp) - - def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any: - """Run on agent action.""" - aim = import_aim() - self.step += 1 - self.tool_starts += 1 - self.starts += 1 - - resp = { - "action": "on_agent_action", - "tool": action.tool, - } - resp.update(self.get_custom_callback_meta()) - - action_res = deepcopy(action) - - text = "TOOL INPUT:\n{}\n\nLOG:\n{}".format( - action_res.tool_input, action_res.log - ) - self._run.track(aim.Text(text), name="on_agent_action", context=resp) - - def flush_tracker( - self, - repo: Optional[str] = None, - experiment_name: Optional[str] = None, - system_tracking_interval: Optional[int] = 10, - log_system_params: bool = True, - langchain_asset: Any = None, - reset: bool = True, - finish: bool = False, - ) -> None: - """Flush the tracker and reset the session. - - Args: - repo (:obj:`str`, optional): Aim repository path or Repo object to which - Run object is bound. If skipped, default Repo is used. - experiment_name (:obj:`str`, optional): Sets Run's `experiment` property. - 'default' if not specified. Can be used later to query runs/sequences. - system_tracking_interval (:obj:`int`, optional): Sets the tracking interval - in seconds for system usage metrics (CPU, Memory, etc.). Set to `None` - to disable system metrics tracking. - log_system_params (:obj:`bool`, optional): Enable/Disable logging of system - params such as installed packages, git info, environment variables, etc. - langchain_asset: The langchain asset to save. - reset: Whether to reset the session. - finish: Whether to finish the run. - - Returns: - None - """ - - if langchain_asset: - try: - for key, value in langchain_asset.dict().items(): - self._run.set(key, value, strict=False) - except Exception: - pass - - if finish or reset: - self._run.close() - self.reset_callback_meta() - if reset: - self.__init__( # type: ignore - repo=repo if repo else self.repo, - experiment_name=experiment_name - if experiment_name - else self.experiment_name, - system_tracking_interval=system_tracking_interval - if system_tracking_interval - else self.system_tracking_interval, - log_system_params=log_system_params - if log_system_params - else self.log_system_params, - ) +__all__ = ["import_aim", "BaseMetadataCallbackHandler", "AimCallbackHandler"] diff --git a/libs/langchain/langchain/callbacks/argilla_callback.py b/libs/langchain/langchain/callbacks/argilla_callback.py index 7934b36fb14..b3d085faf71 100644 --- a/libs/langchain/langchain/callbacks/argilla_callback.py +++ b/libs/langchain/langchain/callbacks/argilla_callback.py @@ -1,353 +1,3 @@ -import os -import warnings -from typing import Any, Dict, List, Optional +from langchain_community.callbacks.argilla_callback import ArgillaCallbackHandler -from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.outputs import LLMResult -from packaging.version import parse - -from langchain.callbacks.base import BaseCallbackHandler - - -class ArgillaCallbackHandler(BaseCallbackHandler): - """Callback Handler that logs into Argilla. - - Args: - dataset_name: name of the `FeedbackDataset` in Argilla. Note that it must - exist in advance. If you need help on how to create a `FeedbackDataset` in - Argilla, please visit - https://docs.argilla.io/en/latest/guides/llms/practical_guides/use_argilla_callback_in_langchain.html. - workspace_name: name of the workspace in Argilla where the specified - `FeedbackDataset` lives in. Defaults to `None`, which means that the - default workspace will be used. - api_url: URL of the Argilla Server that we want to use, and where the - `FeedbackDataset` lives in. Defaults to `None`, which means that either - `ARGILLA_API_URL` environment variable or the default will be used. - api_key: API Key to connect to the Argilla Server. Defaults to `None`, which - means that either `ARGILLA_API_KEY` environment variable or the default - will be used. - - Raises: - ImportError: if the `argilla` package is not installed. - ConnectionError: if the connection to Argilla fails. - FileNotFoundError: if the `FeedbackDataset` retrieval from Argilla fails. - - Examples: - >>> from langchain.llms import OpenAI - >>> from langchain.callbacks import ArgillaCallbackHandler - >>> argilla_callback = ArgillaCallbackHandler( - ... dataset_name="my-dataset", - ... workspace_name="my-workspace", - ... api_url="http://localhost:6900", - ... api_key="argilla.apikey", - ... ) - >>> llm = OpenAI( - ... temperature=0, - ... callbacks=[argilla_callback], - ... verbose=True, - ... openai_api_key="API_KEY_HERE", - ... ) - >>> llm.generate([ - ... "What is the best NLP-annotation tool out there? (no bias at all)", - ... ]) - "Argilla, no doubt about it." - """ - - REPO_URL: str = "https://github.com/argilla-io/argilla" - ISSUES_URL: str = f"{REPO_URL}/issues" - BLOG_URL: str = "https://docs.argilla.io/en/latest/guides/llms/practical_guides/use_argilla_callback_in_langchain.html" # noqa: E501 - - DEFAULT_API_URL: str = "http://localhost:6900" - - def __init__( - self, - dataset_name: str, - workspace_name: Optional[str] = None, - api_url: Optional[str] = None, - api_key: Optional[str] = None, - ) -> None: - """Initializes the `ArgillaCallbackHandler`. - - Args: - dataset_name: name of the `FeedbackDataset` in Argilla. Note that it must - exist in advance. If you need help on how to create a `FeedbackDataset` - in Argilla, please visit - https://docs.argilla.io/en/latest/guides/llms/practical_guides/use_argilla_callback_in_langchain.html. - workspace_name: name of the workspace in Argilla where the specified - `FeedbackDataset` lives in. Defaults to `None`, which means that the - default workspace will be used. - api_url: URL of the Argilla Server that we want to use, and where the - `FeedbackDataset` lives in. Defaults to `None`, which means that either - `ARGILLA_API_URL` environment variable or the default will be used. - api_key: API Key to connect to the Argilla Server. Defaults to `None`, which - means that either `ARGILLA_API_KEY` environment variable or the default - will be used. - - Raises: - ImportError: if the `argilla` package is not installed. - ConnectionError: if the connection to Argilla fails. - FileNotFoundError: if the `FeedbackDataset` retrieval from Argilla fails. - """ - - super().__init__() - - # Import Argilla (not via `import_argilla` to keep hints in IDEs) - try: - import argilla as rg # noqa: F401 - - self.ARGILLA_VERSION = rg.__version__ - except ImportError: - raise ImportError( - "To use the Argilla callback manager you need to have the `argilla` " - "Python package installed. Please install it with `pip install argilla`" - ) - - # Check whether the Argilla version is compatible - if parse(self.ARGILLA_VERSION) < parse("1.8.0"): - raise ImportError( - f"The installed `argilla` version is {self.ARGILLA_VERSION} but " - "`ArgillaCallbackHandler` requires at least version 1.8.0. Please " - "upgrade `argilla` with `pip install --upgrade argilla`." - ) - - # Show a warning message if Argilla will assume the default values will be used - if api_url is None and os.getenv("ARGILLA_API_URL") is None: - warnings.warn( - ( - "Since `api_url` is None, and the env var `ARGILLA_API_URL` is not" - f" set, it will default to `{self.DEFAULT_API_URL}`, which is the" - " default API URL in Argilla Quickstart." - ), - ) - api_url = self.DEFAULT_API_URL - - if api_key is None and os.getenv("ARGILLA_API_KEY") is None: - self.DEFAULT_API_KEY = ( - "admin.apikey" - if parse(self.ARGILLA_VERSION) < parse("1.11.0") - else "owner.apikey" - ) - - warnings.warn( - ( - "Since `api_key` is None, and the env var `ARGILLA_API_KEY` is not" - f" set, it will default to `{self.DEFAULT_API_KEY}`, which is the" - " default API key in Argilla Quickstart." - ), - ) - api_url = self.DEFAULT_API_URL - - # Connect to Argilla with the provided credentials, if applicable - try: - rg.init(api_key=api_key, api_url=api_url) - except Exception as e: - raise ConnectionError( - f"Could not connect to Argilla with exception: '{e}'.\n" - "Please check your `api_key` and `api_url`, and make sure that " - "the Argilla server is up and running. If the problem persists " - f"please report it to {self.ISSUES_URL} as an `integration` issue." - ) from e - - # Set the Argilla variables - self.dataset_name = dataset_name - self.workspace_name = workspace_name or rg.get_workspace() - - # Retrieve the `FeedbackDataset` from Argilla (without existing records) - try: - extra_args = {} - if parse(self.ARGILLA_VERSION) < parse("1.14.0"): - warnings.warn( - f"You have Argilla {self.ARGILLA_VERSION}, but Argilla 1.14.0 or" - " higher is recommended.", - UserWarning, - ) - extra_args = {"with_records": False} - self.dataset = rg.FeedbackDataset.from_argilla( - name=self.dataset_name, - workspace=self.workspace_name, - **extra_args, - ) - except Exception as e: - raise FileNotFoundError( - f"`FeedbackDataset` retrieval from Argilla failed with exception `{e}`." - f"\nPlease check that the dataset with name={self.dataset_name} in the" - f" workspace={self.workspace_name} exists in advance. If you need help" - " on how to create a `langchain`-compatible `FeedbackDataset` in" - f" Argilla, please visit {self.BLOG_URL}. If the problem persists" - f" please report it to {self.ISSUES_URL} as an `integration` issue." - ) from e - - supported_fields = ["prompt", "response"] - if supported_fields != [field.name for field in self.dataset.fields]: - raise ValueError( - f"`FeedbackDataset` with name={self.dataset_name} in the workspace=" - f"{self.workspace_name} had fields that are not supported yet for the" - f"`langchain` integration. Supported fields are: {supported_fields}," - f" and the current `FeedbackDataset` fields are {[field.name for field in self.dataset.fields]}." # noqa: E501 - " For more information on how to create a `langchain`-compatible" - f" `FeedbackDataset` in Argilla, please visit {self.BLOG_URL}." - ) - - self.prompts: Dict[str, List[str]] = {} - - warnings.warn( - ( - "The `ArgillaCallbackHandler` is currently in beta and is subject to" - " change based on updates to `langchain`. Please report any issues to" - f" {self.ISSUES_URL} as an `integration` issue." - ), - ) - - def on_llm_start( - self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any - ) -> None: - """Save the prompts in memory when an LLM starts.""" - self.prompts.update({str(kwargs["parent_run_id"] or kwargs["run_id"]): prompts}) - - def on_llm_new_token(self, token: str, **kwargs: Any) -> None: - """Do nothing when a new token is generated.""" - pass - - def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None: - """Log records to Argilla when an LLM ends.""" - # Do nothing if there's a parent_run_id, since we will log the records when - # the chain ends - if kwargs["parent_run_id"]: - return - - # Creates the records and adds them to the `FeedbackDataset` - prompts = self.prompts[str(kwargs["run_id"])] - for prompt, generations in zip(prompts, response.generations): - self.dataset.add_records( - records=[ - { - "fields": { - "prompt": prompt, - "response": generation.text.strip(), - }, - } - for generation in generations - ] - ) - - # Pop current run from `self.runs` - self.prompts.pop(str(kwargs["run_id"])) - - if parse(self.ARGILLA_VERSION) < parse("1.14.0"): - # Push the records to Argilla - self.dataset.push_to_argilla() - - def on_llm_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing when LLM outputs an error.""" - pass - - def on_chain_start( - self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any - ) -> None: - """If the key `input` is in `inputs`, then save it in `self.prompts` using - either the `parent_run_id` or the `run_id` as the key. This is done so that - we don't log the same input prompt twice, once when the LLM starts and once - when the chain starts. - """ - if "input" in inputs: - self.prompts.update( - { - str(kwargs["parent_run_id"] or kwargs["run_id"]): ( - inputs["input"] - if isinstance(inputs["input"], list) - else [inputs["input"]] - ) - } - ) - - def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - """If either the `parent_run_id` or the `run_id` is in `self.prompts`, then - log the outputs to Argilla, and pop the run from `self.prompts`. The behavior - differs if the output is a list or not. - """ - if not any( - key in self.prompts - for key in [str(kwargs["parent_run_id"]), str(kwargs["run_id"])] - ): - return - prompts = self.prompts.get(str(kwargs["parent_run_id"])) or self.prompts.get( - str(kwargs["run_id"]) - ) - for chain_output_key, chain_output_val in outputs.items(): - if isinstance(chain_output_val, list): - # Creates the records and adds them to the `FeedbackDataset` - self.dataset.add_records( - records=[ - { - "fields": { - "prompt": prompt, - "response": output["text"].strip(), - }, - } - for prompt, output in zip( - prompts, # type: ignore - chain_output_val, - ) - ] - ) - else: - # Creates the records and adds them to the `FeedbackDataset` - self.dataset.add_records( - records=[ - { - "fields": { - "prompt": " ".join(prompts), # type: ignore - "response": chain_output_val.strip(), - }, - } - ] - ) - - # Pop current run from `self.runs` - if str(kwargs["parent_run_id"]) in self.prompts: - self.prompts.pop(str(kwargs["parent_run_id"])) - if str(kwargs["run_id"]) in self.prompts: - self.prompts.pop(str(kwargs["run_id"])) - - if parse(self.ARGILLA_VERSION) < parse("1.14.0"): - # Push the records to Argilla - self.dataset.push_to_argilla() - - def on_chain_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing when LLM chain outputs an error.""" - pass - - def on_tool_start( - self, - serialized: Dict[str, Any], - input_str: str, - **kwargs: Any, - ) -> None: - """Do nothing when tool starts.""" - pass - - def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any: - """Do nothing when agent takes a specific action.""" - pass - - def on_tool_end( - self, - output: str, - observation_prefix: Optional[str] = None, - llm_prefix: Optional[str] = None, - **kwargs: Any, - ) -> None: - """Do nothing when tool ends.""" - pass - - def on_tool_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing when tool outputs an error.""" - pass - - def on_text(self, text: str, **kwargs: Any) -> None: - """Do nothing""" - pass - - def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> None: - """Do nothing""" - pass +__all__ = ["ArgillaCallbackHandler"] diff --git a/libs/langchain/langchain/callbacks/arize_callback.py b/libs/langchain/langchain/callbacks/arize_callback.py index c0c81ce3308..c120de398f6 100644 --- a/libs/langchain/langchain/callbacks/arize_callback.py +++ b/libs/langchain/langchain/callbacks/arize_callback.py @@ -1,213 +1,3 @@ -from datetime import datetime -from typing import Any, Dict, List, Optional +from langchain_community.callbacks.arize_callback import ArizeCallbackHandler -from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.outputs import LLMResult - -from langchain.callbacks.base import BaseCallbackHandler -from langchain.callbacks.utils import import_pandas - - -class ArizeCallbackHandler(BaseCallbackHandler): - """Callback Handler that logs to Arize.""" - - def __init__( - self, - model_id: Optional[str] = None, - model_version: Optional[str] = None, - SPACE_KEY: Optional[str] = None, - API_KEY: Optional[str] = None, - ) -> None: - """Initialize callback handler.""" - - super().__init__() - self.model_id = model_id - self.model_version = model_version - self.space_key = SPACE_KEY - self.api_key = API_KEY - self.prompt_records: List[str] = [] - self.response_records: List[str] = [] - self.prediction_ids: List[str] = [] - self.pred_timestamps: List[int] = [] - self.response_embeddings: List[float] = [] - self.prompt_embeddings: List[float] = [] - self.prompt_tokens = 0 - self.completion_tokens = 0 - self.total_tokens = 0 - self.step = 0 - - from arize.pandas.embeddings import EmbeddingGenerator, UseCases - from arize.pandas.logger import Client - - self.generator = EmbeddingGenerator.from_use_case( - use_case=UseCases.NLP.SEQUENCE_CLASSIFICATION, - model_name="distilbert-base-uncased", - tokenizer_max_length=512, - batch_size=256, - ) - self.arize_client = Client(space_key=SPACE_KEY, api_key=API_KEY) - if SPACE_KEY == "SPACE_KEY" or API_KEY == "API_KEY": - raise ValueError("❌ CHANGE SPACE AND API KEYS") - else: - print("✅ Arize client setup done! Now you can start using Arize!") - - def on_llm_start( - self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any - ) -> None: - for prompt in prompts: - self.prompt_records.append(prompt.replace("\n", "")) - - def on_llm_new_token(self, token: str, **kwargs: Any) -> None: - """Do nothing.""" - pass - - def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None: - pd = import_pandas() - from arize.utils.types import ( - EmbeddingColumnNames, - Environments, - ModelTypes, - Schema, - ) - - # Safe check if 'llm_output' and 'token_usage' exist - if response.llm_output and "token_usage" in response.llm_output: - self.prompt_tokens = response.llm_output["token_usage"].get( - "prompt_tokens", 0 - ) - self.total_tokens = response.llm_output["token_usage"].get( - "total_tokens", 0 - ) - self.completion_tokens = response.llm_output["token_usage"].get( - "completion_tokens", 0 - ) - else: - self.prompt_tokens = ( - self.total_tokens - ) = self.completion_tokens = 0 # assign default value - - for generations in response.generations: - for generation in generations: - prompt = self.prompt_records[self.step] - self.step = self.step + 1 - prompt_embedding = pd.Series( - self.generator.generate_embeddings( - text_col=pd.Series(prompt.replace("\n", " ")) - ).reset_index(drop=True) - ) - - # Assigning text to response_text instead of response - response_text = generation.text.replace("\n", " ") - response_embedding = pd.Series( - self.generator.generate_embeddings( - text_col=pd.Series(generation.text.replace("\n", " ")) - ).reset_index(drop=True) - ) - pred_timestamp = datetime.now().timestamp() - - # Define the columns and data - columns = [ - "prediction_ts", - "response", - "prompt", - "response_vector", - "prompt_vector", - "prompt_token", - "completion_token", - "total_token", - ] - data = [ - [ - pred_timestamp, - response_text, - prompt, - response_embedding[0], - prompt_embedding[0], - self.prompt_tokens, - self.total_tokens, - self.completion_tokens, - ] - ] - - # Create the DataFrame - df = pd.DataFrame(data, columns=columns) - - # Declare prompt and response columns - prompt_columns = EmbeddingColumnNames( - vector_column_name="prompt_vector", data_column_name="prompt" - ) - - response_columns = EmbeddingColumnNames( - vector_column_name="response_vector", data_column_name="response" - ) - - schema = Schema( - timestamp_column_name="prediction_ts", - tag_column_names=[ - "prompt_token", - "completion_token", - "total_token", - ], - prompt_column_names=prompt_columns, - response_column_names=response_columns, - ) - - response_from_arize = self.arize_client.log( - dataframe=df, - schema=schema, - model_id=self.model_id, - model_version=self.model_version, - model_type=ModelTypes.GENERATIVE_LLM, - environment=Environments.PRODUCTION, - ) - if response_from_arize.status_code == 200: - print("✅ Successfully logged data to Arize!") - else: - print(f'❌ Logging failed "{response_from_arize.text}"') - - def on_llm_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing.""" - pass - - def on_chain_start( - self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any - ) -> None: - pass - - def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - """Do nothing.""" - pass - - def on_chain_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing.""" - pass - - def on_tool_start( - self, - serialized: Dict[str, Any], - input_str: str, - **kwargs: Any, - ) -> None: - pass - - def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any: - """Do nothing.""" - pass - - def on_tool_end( - self, - output: str, - observation_prefix: Optional[str] = None, - llm_prefix: Optional[str] = None, - **kwargs: Any, - ) -> None: - pass - - def on_tool_error(self, error: BaseException, **kwargs: Any) -> None: - pass - - def on_text(self, text: str, **kwargs: Any) -> None: - pass - - def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> None: - pass +__all__ = ["ArizeCallbackHandler"] diff --git a/libs/langchain/langchain/callbacks/arthur_callback.py b/libs/langchain/langchain/callbacks/arthur_callback.py index cd01c7263fc..f83a5c959f7 100644 --- a/libs/langchain/langchain/callbacks/arthur_callback.py +++ b/libs/langchain/langchain/callbacks/arthur_callback.py @@ -1,297 +1,19 @@ -"""ArthurAI's Callback Handler.""" -from __future__ import annotations +from langchain_community.callbacks.arthur_callback import ( + COMPLETION_TOKENS, + DURATION, + FINISH_REASON, + PROMPT_TOKENS, + TOKEN_USAGE, + ArthurCallbackHandler, + _lazy_load_arthur, +) -import os -import uuid -from collections import defaultdict -from datetime import datetime -from time import time -from typing import TYPE_CHECKING, Any, DefaultDict, Dict, List, Optional - -import numpy as np -from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.outputs import LLMResult - -from langchain.callbacks.base import BaseCallbackHandler - -if TYPE_CHECKING: - import arthurai - from arthurai.core.models import ArthurModel - -PROMPT_TOKENS = "prompt_tokens" -COMPLETION_TOKENS = "completion_tokens" -TOKEN_USAGE = "token_usage" -FINISH_REASON = "finish_reason" -DURATION = "duration" - - -def _lazy_load_arthur() -> arthurai: - """Lazy load Arthur.""" - try: - import arthurai - except ImportError as e: - raise ImportError( - "To use the ArthurCallbackHandler you need the" - " `arthurai` package. Please install it with" - " `pip install arthurai`.", - e, - ) - - return arthurai - - -class ArthurCallbackHandler(BaseCallbackHandler): - """Callback Handler that logs to Arthur platform. - - Arthur helps enterprise teams optimize model operations - and performance at scale. The Arthur API tracks model - performance, explainability, and fairness across tabular, - NLP, and CV models. Our API is model- and platform-agnostic, - and continuously scales with complex and dynamic enterprise needs. - To learn more about Arthur, visit our website at - https://www.arthur.ai/ or read the Arthur docs at - https://docs.arthur.ai/ - """ - - def __init__( - self, - arthur_model: ArthurModel, - ) -> None: - """Initialize callback handler.""" - super().__init__() - arthurai = _lazy_load_arthur() - Stage = arthurai.common.constants.Stage - ValueType = arthurai.common.constants.ValueType - self.arthur_model = arthur_model - # save the attributes of this model to be used when preparing - # inferences to log to Arthur in on_llm_end() - self.attr_names = set([a.name for a in self.arthur_model.get_attributes()]) - self.input_attr = [ - x - for x in self.arthur_model.get_attributes() - if x.stage == Stage.ModelPipelineInput - and x.value_type == ValueType.Unstructured_Text - ][0].name - self.output_attr = [ - x - for x in self.arthur_model.get_attributes() - if x.stage == Stage.PredictedValue - and x.value_type == ValueType.Unstructured_Text - ][0].name - self.token_likelihood_attr = None - if ( - len( - [ - x - for x in self.arthur_model.get_attributes() - if x.value_type == ValueType.TokenLikelihoods - ] - ) - > 0 - ): - self.token_likelihood_attr = [ - x - for x in self.arthur_model.get_attributes() - if x.value_type == ValueType.TokenLikelihoods - ][0].name - - self.run_map: DefaultDict[str, Any] = defaultdict(dict) - - @classmethod - def from_credentials( - cls, - model_id: str, - arthur_url: Optional[str] = "https://app.arthur.ai", - arthur_login: Optional[str] = None, - arthur_password: Optional[str] = None, - ) -> ArthurCallbackHandler: - """Initialize callback handler from Arthur credentials. - - Args: - model_id (str): The ID of the arthur model to log to. - arthur_url (str, optional): The URL of the Arthur instance to log to. - Defaults to "https://app.arthur.ai". - arthur_login (str, optional): The login to use to connect to Arthur. - Defaults to None. - arthur_password (str, optional): The password to use to connect to - Arthur. Defaults to None. - - Returns: - ArthurCallbackHandler: The initialized callback handler. - """ - arthurai = _lazy_load_arthur() - ArthurAI = arthurai.ArthurAI - ResponseClientError = arthurai.common.exceptions.ResponseClientError - - # connect to Arthur - if arthur_login is None: - try: - arthur_api_key = os.environ["ARTHUR_API_KEY"] - except KeyError: - raise ValueError( - "No Arthur authentication provided. Either give" - " a login to the ArthurCallbackHandler" - " or set an ARTHUR_API_KEY as an environment variable." - ) - arthur = ArthurAI(url=arthur_url, access_key=arthur_api_key) - else: - if arthur_password is None: - arthur = ArthurAI(url=arthur_url, login=arthur_login) - else: - arthur = ArthurAI( - url=arthur_url, login=arthur_login, password=arthur_password - ) - # get model from Arthur by the provided model ID - try: - arthur_model = arthur.get_model(model_id) - except ResponseClientError: - raise ValueError( - f"Was unable to retrieve model with id {model_id} from Arthur." - " Make sure the ID corresponds to a model that is currently" - " registered with your Arthur account." - ) - return cls(arthur_model) - - def on_llm_start( - self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any - ) -> None: - """On LLM start, save the input prompts""" - run_id = kwargs["run_id"] - self.run_map[run_id]["input_texts"] = prompts - self.run_map[run_id]["start_time"] = time() - - def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None: - """On LLM end, send data to Arthur.""" - try: - import pytz # type: ignore[import] - except ImportError as e: - raise ImportError( - "Could not import pytz. Please install it with 'pip install pytz'." - ) from e - - run_id = kwargs["run_id"] - - # get the run params from this run ID, - # or raise an error if this run ID has no corresponding metadata in self.run_map - try: - run_map_data = self.run_map[run_id] - except KeyError as e: - raise KeyError( - "This function has been called with a run_id" - " that was never registered in on_llm_start()." - " Restart and try running the LLM again" - ) from e - - # mark the duration time between on_llm_start() and on_llm_end() - time_from_start_to_end = time() - run_map_data["start_time"] - - # create inferences to log to Arthur - inferences = [] - for i, generations in enumerate(response.generations): - for generation in generations: - inference = { - "partner_inference_id": str(uuid.uuid4()), - "inference_timestamp": datetime.now(tz=pytz.UTC), - self.input_attr: run_map_data["input_texts"][i], - self.output_attr: generation.text, - } - - if generation.generation_info is not None: - # add finish reason to the inference - # if generation info contains a finish reason and - # if the ArthurModel was registered to monitor finish_reason - if ( - FINISH_REASON in generation.generation_info - and FINISH_REASON in self.attr_names - ): - inference[FINISH_REASON] = generation.generation_info[ - FINISH_REASON - ] - - # add token likelihoods data to the inference if the ArthurModel - # was registered to monitor token likelihoods - logprobs_data = generation.generation_info["logprobs"] - if ( - logprobs_data is not None - and self.token_likelihood_attr is not None - ): - logprobs = logprobs_data["top_logprobs"] - likelihoods = [ - {k: np.exp(v) for k, v in logprobs[i].items()} - for i in range(len(logprobs)) - ] - inference[self.token_likelihood_attr] = likelihoods - - # add token usage counts to the inference if the - # ArthurModel was registered to monitor token usage - if ( - isinstance(response.llm_output, dict) - and TOKEN_USAGE in response.llm_output - ): - token_usage = response.llm_output[TOKEN_USAGE] - if ( - PROMPT_TOKENS in token_usage - and PROMPT_TOKENS in self.attr_names - ): - inference[PROMPT_TOKENS] = token_usage[PROMPT_TOKENS] - if ( - COMPLETION_TOKENS in token_usage - and COMPLETION_TOKENS in self.attr_names - ): - inference[COMPLETION_TOKENS] = token_usage[COMPLETION_TOKENS] - - # add inference duration to the inference if the ArthurModel - # was registered to monitor inference duration - if DURATION in self.attr_names: - inference[DURATION] = time_from_start_to_end - - inferences.append(inference) - - # send inferences to arthur - self.arthur_model.send_inferences(inferences) - - def on_chain_start( - self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any - ) -> None: - """On chain start, do nothing.""" - - def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - """On chain end, do nothing.""" - - def on_llm_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing when LLM outputs an error.""" - - def on_llm_new_token(self, token: str, **kwargs: Any) -> None: - """On new token, pass.""" - - def on_chain_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing when LLM chain outputs an error.""" - - def on_tool_start( - self, - serialized: Dict[str, Any], - input_str: str, - **kwargs: Any, - ) -> None: - """Do nothing when tool starts.""" - - def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any: - """Do nothing when agent takes a specific action.""" - - def on_tool_end( - self, - output: str, - observation_prefix: Optional[str] = None, - llm_prefix: Optional[str] = None, - **kwargs: Any, - ) -> None: - """Do nothing when tool ends.""" - - def on_tool_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing when tool outputs an error.""" - - def on_text(self, text: str, **kwargs: Any) -> None: - """Do nothing""" - - def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> None: - """Do nothing""" +__all__ = [ + "PROMPT_TOKENS", + "COMPLETION_TOKENS", + "TOKEN_USAGE", + "FINISH_REASON", + "DURATION", + "_lazy_load_arthur", + "ArthurCallbackHandler", +] diff --git a/libs/langchain/langchain/callbacks/clearml_callback.py b/libs/langchain/langchain/callbacks/clearml_callback.py index fd3899e8043..18bcc478af3 100644 --- a/libs/langchain/langchain/callbacks/clearml_callback.py +++ b/libs/langchain/langchain/callbacks/clearml_callback.py @@ -1,527 +1,6 @@ -from __future__ import annotations - -import tempfile -from copy import deepcopy -from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, Sequence - -from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.outputs import LLMResult - -from langchain.callbacks.base import BaseCallbackHandler -from langchain.callbacks.utils import ( - BaseMetadataCallbackHandler, - flatten_dict, - hash_string, - import_pandas, - import_spacy, - import_textstat, - load_json, +from langchain_community.callbacks.clearml_callback import ( + ClearMLCallbackHandler, + import_clearml, ) -if TYPE_CHECKING: - import pandas as pd - - -def import_clearml() -> Any: - """Import the clearml python package and raise an error if it is not installed.""" - try: - import clearml # noqa: F401 - except ImportError: - raise ImportError( - "To use the clearml callback manager you need to have the `clearml` python " - "package installed. Please install it with `pip install clearml`" - ) - return clearml - - -class ClearMLCallbackHandler(BaseMetadataCallbackHandler, BaseCallbackHandler): - """Callback Handler that logs to ClearML. - - Parameters: - job_type (str): The type of clearml task such as "inference", "testing" or "qc" - project_name (str): The clearml project name - tags (list): Tags to add to the task - task_name (str): Name of the clearml task - visualize (bool): Whether to visualize the run. - complexity_metrics (bool): Whether to log complexity metrics - stream_logs (bool): Whether to stream callback actions to ClearML - - This handler will utilize the associated callback method and formats - the input of each callback function with metadata regarding the state of LLM run, - and adds the response to the list of records for both the {method}_records and - action. It then logs the response to the ClearML console. - """ - - def __init__( - self, - task_type: Optional[str] = "inference", - project_name: Optional[str] = "langchain_callback_demo", - tags: Optional[Sequence] = None, - task_name: Optional[str] = None, - visualize: bool = False, - complexity_metrics: bool = False, - stream_logs: bool = False, - ) -> None: - """Initialize callback handler.""" - - clearml = import_clearml() - spacy = import_spacy() - super().__init__() - - self.task_type = task_type - self.project_name = project_name - self.tags = tags - self.task_name = task_name - self.visualize = visualize - self.complexity_metrics = complexity_metrics - self.stream_logs = stream_logs - - self.temp_dir = tempfile.TemporaryDirectory() - - # Check if ClearML task already exists (e.g. in pipeline) - if clearml.Task.current_task(): - self.task = clearml.Task.current_task() - else: - self.task = clearml.Task.init( # type: ignore - task_type=self.task_type, - project_name=self.project_name, - tags=self.tags, - task_name=self.task_name, - output_uri=True, - ) - self.logger = self.task.get_logger() - warning = ( - "The clearml callback is currently in beta and is subject to change " - "based on updates to `langchain`. Please report any issues to " - "https://github.com/allegroai/clearml/issues with the tag `langchain`." - ) - self.logger.report_text(warning, level=30, print_console=True) - self.callback_columns: list = [] - self.action_records: list = [] - self.complexity_metrics = complexity_metrics - self.visualize = visualize - self.nlp = spacy.load("en_core_web_sm") - - def _init_resp(self) -> Dict: - return {k: None for k in self.callback_columns} - - def on_llm_start( - self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any - ) -> None: - """Run when LLM starts.""" - self.step += 1 - self.llm_starts += 1 - self.starts += 1 - - resp = self._init_resp() - resp.update({"action": "on_llm_start"}) - resp.update(flatten_dict(serialized)) - resp.update(self.get_custom_callback_meta()) - - for prompt in prompts: - prompt_resp = deepcopy(resp) - prompt_resp["prompts"] = prompt - self.on_llm_start_records.append(prompt_resp) - self.action_records.append(prompt_resp) - if self.stream_logs: - self.logger.report_text(prompt_resp) - - def on_llm_new_token(self, token: str, **kwargs: Any) -> None: - """Run when LLM generates a new token.""" - self.step += 1 - self.llm_streams += 1 - - resp = self._init_resp() - resp.update({"action": "on_llm_new_token", "token": token}) - resp.update(self.get_custom_callback_meta()) - - self.on_llm_token_records.append(resp) - self.action_records.append(resp) - if self.stream_logs: - self.logger.report_text(resp) - - def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None: - """Run when LLM ends running.""" - self.step += 1 - self.llm_ends += 1 - self.ends += 1 - - resp = self._init_resp() - resp.update({"action": "on_llm_end"}) - resp.update(flatten_dict(response.llm_output or {})) - resp.update(self.get_custom_callback_meta()) - - for generations in response.generations: - for generation in generations: - generation_resp = deepcopy(resp) - generation_resp.update(flatten_dict(generation.dict())) - generation_resp.update(self.analyze_text(generation.text)) - self.on_llm_end_records.append(generation_resp) - self.action_records.append(generation_resp) - if self.stream_logs: - self.logger.report_text(generation_resp) - - def on_llm_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when LLM errors.""" - self.step += 1 - self.errors += 1 - - def on_chain_start( - self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any - ) -> None: - """Run when chain starts running.""" - self.step += 1 - self.chain_starts += 1 - self.starts += 1 - - resp = self._init_resp() - resp.update({"action": "on_chain_start"}) - resp.update(flatten_dict(serialized)) - resp.update(self.get_custom_callback_meta()) - - chain_input = inputs.get("input", inputs.get("human_input")) - - if isinstance(chain_input, str): - input_resp = deepcopy(resp) - input_resp["input"] = chain_input - self.on_chain_start_records.append(input_resp) - self.action_records.append(input_resp) - if self.stream_logs: - self.logger.report_text(input_resp) - elif isinstance(chain_input, list): - for inp in chain_input: - input_resp = deepcopy(resp) - input_resp.update(inp) - self.on_chain_start_records.append(input_resp) - self.action_records.append(input_resp) - if self.stream_logs: - self.logger.report_text(input_resp) - else: - raise ValueError("Unexpected data format provided!") - - def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - """Run when chain ends running.""" - self.step += 1 - self.chain_ends += 1 - self.ends += 1 - - resp = self._init_resp() - resp.update( - { - "action": "on_chain_end", - "outputs": outputs.get("output", outputs.get("text")), - } - ) - resp.update(self.get_custom_callback_meta()) - - self.on_chain_end_records.append(resp) - self.action_records.append(resp) - if self.stream_logs: - self.logger.report_text(resp) - - def on_chain_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when chain errors.""" - self.step += 1 - self.errors += 1 - - def on_tool_start( - self, serialized: Dict[str, Any], input_str: str, **kwargs: Any - ) -> None: - """Run when tool starts running.""" - self.step += 1 - self.tool_starts += 1 - self.starts += 1 - - resp = self._init_resp() - resp.update({"action": "on_tool_start", "input_str": input_str}) - resp.update(flatten_dict(serialized)) - resp.update(self.get_custom_callback_meta()) - - self.on_tool_start_records.append(resp) - self.action_records.append(resp) - if self.stream_logs: - self.logger.report_text(resp) - - def on_tool_end(self, output: str, **kwargs: Any) -> None: - """Run when tool ends running.""" - self.step += 1 - self.tool_ends += 1 - self.ends += 1 - - resp = self._init_resp() - resp.update({"action": "on_tool_end", "output": output}) - resp.update(self.get_custom_callback_meta()) - - self.on_tool_end_records.append(resp) - self.action_records.append(resp) - if self.stream_logs: - self.logger.report_text(resp) - - def on_tool_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when tool errors.""" - self.step += 1 - self.errors += 1 - - def on_text(self, text: str, **kwargs: Any) -> None: - """ - Run when agent is ending. - """ - self.step += 1 - self.text_ctr += 1 - - resp = self._init_resp() - resp.update({"action": "on_text", "text": text}) - resp.update(self.get_custom_callback_meta()) - - self.on_text_records.append(resp) - self.action_records.append(resp) - if self.stream_logs: - self.logger.report_text(resp) - - def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> None: - """Run when agent ends running.""" - self.step += 1 - self.agent_ends += 1 - self.ends += 1 - - resp = self._init_resp() - resp.update( - { - "action": "on_agent_finish", - "output": finish.return_values["output"], - "log": finish.log, - } - ) - resp.update(self.get_custom_callback_meta()) - - self.on_agent_finish_records.append(resp) - self.action_records.append(resp) - if self.stream_logs: - self.logger.report_text(resp) - - def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any: - """Run on agent action.""" - self.step += 1 - self.tool_starts += 1 - self.starts += 1 - - resp = self._init_resp() - resp.update( - { - "action": "on_agent_action", - "tool": action.tool, - "tool_input": action.tool_input, - "log": action.log, - } - ) - resp.update(self.get_custom_callback_meta()) - self.on_agent_action_records.append(resp) - self.action_records.append(resp) - if self.stream_logs: - self.logger.report_text(resp) - - def analyze_text(self, text: str) -> dict: - """Analyze text using textstat and spacy. - - Parameters: - text (str): The text to analyze. - - Returns: - (dict): A dictionary containing the complexity metrics. - """ - resp = {} - textstat = import_textstat() - spacy = import_spacy() - if self.complexity_metrics: - text_complexity_metrics = { - "flesch_reading_ease": textstat.flesch_reading_ease(text), - "flesch_kincaid_grade": textstat.flesch_kincaid_grade(text), - "smog_index": textstat.smog_index(text), - "coleman_liau_index": textstat.coleman_liau_index(text), - "automated_readability_index": textstat.automated_readability_index( - text - ), - "dale_chall_readability_score": textstat.dale_chall_readability_score( - text - ), - "difficult_words": textstat.difficult_words(text), - "linsear_write_formula": textstat.linsear_write_formula(text), - "gunning_fog": textstat.gunning_fog(text), - "text_standard": textstat.text_standard(text), - "fernandez_huerta": textstat.fernandez_huerta(text), - "szigriszt_pazos": textstat.szigriszt_pazos(text), - "gutierrez_polini": textstat.gutierrez_polini(text), - "crawford": textstat.crawford(text), - "gulpease_index": textstat.gulpease_index(text), - "osman": textstat.osman(text), - } - resp.update(text_complexity_metrics) - - if self.visualize and self.nlp and self.temp_dir.name is not None: - doc = self.nlp(text) - - dep_out = spacy.displacy.render( # type: ignore - doc, style="dep", jupyter=False, page=True - ) - dep_output_path = Path( - self.temp_dir.name, hash_string(f"dep-{text}") + ".html" - ) - dep_output_path.open("w", encoding="utf-8").write(dep_out) - - ent_out = spacy.displacy.render( # type: ignore - doc, style="ent", jupyter=False, page=True - ) - ent_output_path = Path( - self.temp_dir.name, hash_string(f"ent-{text}") + ".html" - ) - ent_output_path.open("w", encoding="utf-8").write(ent_out) - - self.logger.report_media( - "Dependencies Plot", text, local_path=dep_output_path - ) - self.logger.report_media("Entities Plot", text, local_path=ent_output_path) - - return resp - - @staticmethod - def _build_llm_df( - base_df: pd.DataFrame, base_df_fields: Sequence, rename_map: Mapping - ) -> pd.DataFrame: - base_df_fields = [field for field in base_df_fields if field in base_df] - rename_map = { - map_entry_k: map_entry_v - for map_entry_k, map_entry_v in rename_map.items() - if map_entry_k in base_df_fields - } - llm_df = base_df[base_df_fields].dropna(axis=1) - if rename_map: - llm_df = llm_df.rename(rename_map, axis=1) - return llm_df - - def _create_session_analysis_df(self) -> Any: - """Create a dataframe with all the information from the session.""" - pd = import_pandas() - on_llm_end_records_df = pd.DataFrame(self.on_llm_end_records) - - llm_input_prompts_df = ClearMLCallbackHandler._build_llm_df( - base_df=on_llm_end_records_df, - base_df_fields=["step", "prompts"] - + (["name"] if "name" in on_llm_end_records_df else ["id"]), - rename_map={"step": "prompt_step"}, - ) - complexity_metrics_columns = [] - visualizations_columns: List = [] - - if self.complexity_metrics: - complexity_metrics_columns = [ - "flesch_reading_ease", - "flesch_kincaid_grade", - "smog_index", - "coleman_liau_index", - "automated_readability_index", - "dale_chall_readability_score", - "difficult_words", - "linsear_write_formula", - "gunning_fog", - "text_standard", - "fernandez_huerta", - "szigriszt_pazos", - "gutierrez_polini", - "crawford", - "gulpease_index", - "osman", - ] - - llm_outputs_df = ClearMLCallbackHandler._build_llm_df( - on_llm_end_records_df, - [ - "step", - "text", - "token_usage_total_tokens", - "token_usage_prompt_tokens", - "token_usage_completion_tokens", - ] - + complexity_metrics_columns - + visualizations_columns, - {"step": "output_step", "text": "output"}, - ) - session_analysis_df = pd.concat([llm_input_prompts_df, llm_outputs_df], axis=1) - return session_analysis_df - - def flush_tracker( - self, - name: Optional[str] = None, - langchain_asset: Any = None, - finish: bool = False, - ) -> None: - """Flush the tracker and setup the session. - - Everything after this will be a new table. - - Args: - name: Name of the performed session so far so it is identifiable - langchain_asset: The langchain asset to save. - finish: Whether to finish the run. - - Returns: - None - """ - pd = import_pandas() - clearml = import_clearml() - - # Log the action records - self.logger.report_table( - "Action Records", name, table_plot=pd.DataFrame(self.action_records) - ) - - # Session analysis - session_analysis_df = self._create_session_analysis_df() - self.logger.report_table( - "Session Analysis", name, table_plot=session_analysis_df - ) - - if self.stream_logs: - self.logger.report_text( - { - "action_records": pd.DataFrame(self.action_records), - "session_analysis": session_analysis_df, - } - ) - - if langchain_asset: - langchain_asset_path = Path(self.temp_dir.name, "model.json") - try: - langchain_asset.save(langchain_asset_path) - # Create output model and connect it to the task - output_model = clearml.OutputModel( - task=self.task, config_text=load_json(langchain_asset_path) - ) - output_model.update_weights( - weights_filename=str(langchain_asset_path), - auto_delete_file=False, - target_filename=name, - ) - except ValueError: - langchain_asset.save_agent(langchain_asset_path) - output_model = clearml.OutputModel( - task=self.task, config_text=load_json(langchain_asset_path) - ) - output_model.update_weights( - weights_filename=str(langchain_asset_path), - auto_delete_file=False, - target_filename=name, - ) - except NotImplementedError as e: - print("Could not save model.") - print(repr(e)) - pass - - # Cleanup after adding everything to ClearML - self.task.flush(wait_for_uploads=True) - self.temp_dir.cleanup() - self.temp_dir = tempfile.TemporaryDirectory() - self.reset_callback_meta() - - if finish: - self.task.close() +__all__ = ["import_clearml", "ClearMLCallbackHandler"] diff --git a/libs/langchain/langchain/callbacks/comet_ml_callback.py b/libs/langchain/langchain/callbacks/comet_ml_callback.py index fc28474e1ca..85534c1de61 100644 --- a/libs/langchain/langchain/callbacks/comet_ml_callback.py +++ b/libs/langchain/langchain/callbacks/comet_ml_callback.py @@ -1,645 +1,17 @@ -import tempfile -from copy import deepcopy -from pathlib import Path -from typing import Any, Callable, Dict, List, Optional, Sequence - -from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.outputs import Generation, LLMResult - -import langchain -from langchain.callbacks.base import BaseCallbackHandler -from langchain.callbacks.utils import ( - BaseMetadataCallbackHandler, - flatten_dict, - import_pandas, - import_spacy, - import_textstat, +from langchain_community.callbacks.comet_ml_callback import ( + LANGCHAIN_MODEL_NAME, + CometCallbackHandler, + _fetch_text_complexity_metrics, + _get_experiment, + _summarize_metrics_for_generated_outputs, + import_comet_ml, ) -LANGCHAIN_MODEL_NAME = "langchain-model" - - -def import_comet_ml() -> Any: - """Import comet_ml and raise an error if it is not installed.""" - try: - import comet_ml # noqa: F401 - except ImportError: - raise ImportError( - "To use the comet_ml callback manager you need to have the " - "`comet_ml` python package installed. Please install it with" - " `pip install comet_ml`" - ) - return comet_ml - - -def _get_experiment( - workspace: Optional[str] = None, project_name: Optional[str] = None -) -> Any: - comet_ml = import_comet_ml() - - experiment = comet_ml.Experiment( # type: ignore - workspace=workspace, - project_name=project_name, - ) - - return experiment - - -def _fetch_text_complexity_metrics(text: str) -> dict: - textstat = import_textstat() - text_complexity_metrics = { - "flesch_reading_ease": textstat.flesch_reading_ease(text), - "flesch_kincaid_grade": textstat.flesch_kincaid_grade(text), - "smog_index": textstat.smog_index(text), - "coleman_liau_index": textstat.coleman_liau_index(text), - "automated_readability_index": textstat.automated_readability_index(text), - "dale_chall_readability_score": textstat.dale_chall_readability_score(text), - "difficult_words": textstat.difficult_words(text), - "linsear_write_formula": textstat.linsear_write_formula(text), - "gunning_fog": textstat.gunning_fog(text), - "text_standard": textstat.text_standard(text), - "fernandez_huerta": textstat.fernandez_huerta(text), - "szigriszt_pazos": textstat.szigriszt_pazos(text), - "gutierrez_polini": textstat.gutierrez_polini(text), - "crawford": textstat.crawford(text), - "gulpease_index": textstat.gulpease_index(text), - "osman": textstat.osman(text), - } - return text_complexity_metrics - - -def _summarize_metrics_for_generated_outputs(metrics: Sequence) -> dict: - pd = import_pandas() - metrics_df = pd.DataFrame(metrics) - metrics_summary = metrics_df.describe() - - return metrics_summary.to_dict() - - -class CometCallbackHandler(BaseMetadataCallbackHandler, BaseCallbackHandler): - """Callback Handler that logs to Comet. - - Parameters: - job_type (str): The type of comet_ml task such as "inference", - "testing" or "qc" - project_name (str): The comet_ml project name - tags (list): Tags to add to the task - task_name (str): Name of the comet_ml task - visualize (bool): Whether to visualize the run. - complexity_metrics (bool): Whether to log complexity metrics - stream_logs (bool): Whether to stream callback actions to Comet - - This handler will utilize the associated callback method and formats - the input of each callback function with metadata regarding the state of LLM run, - and adds the response to the list of records for both the {method}_records and - action. It then logs the response to Comet. - """ - - def __init__( - self, - task_type: Optional[str] = "inference", - workspace: Optional[str] = None, - project_name: Optional[str] = None, - tags: Optional[Sequence] = None, - name: Optional[str] = None, - visualizations: Optional[List[str]] = None, - complexity_metrics: bool = False, - custom_metrics: Optional[Callable] = None, - stream_logs: bool = True, - ) -> None: - """Initialize callback handler.""" - - self.comet_ml = import_comet_ml() - super().__init__() - - self.task_type = task_type - self.workspace = workspace - self.project_name = project_name - self.tags = tags - self.visualizations = visualizations - self.complexity_metrics = complexity_metrics - self.custom_metrics = custom_metrics - self.stream_logs = stream_logs - self.temp_dir = tempfile.TemporaryDirectory() - - self.experiment = _get_experiment(workspace, project_name) - self.experiment.log_other("Created from", "langchain") - if tags: - self.experiment.add_tags(tags) - self.name = name - if self.name: - self.experiment.set_name(self.name) - - warning = ( - "The comet_ml callback is currently in beta and is subject to change " - "based on updates to `langchain`. Please report any issues to " - "https://github.com/comet-ml/issue-tracking/issues with the tag " - "`langchain`." - ) - self.comet_ml.LOGGER.warning(warning) - - self.callback_columns: list = [] - self.action_records: list = [] - self.complexity_metrics = complexity_metrics - if self.visualizations: - spacy = import_spacy() - self.nlp = spacy.load("en_core_web_sm") - else: - self.nlp = None - - def _init_resp(self) -> Dict: - return {k: None for k in self.callback_columns} - - def on_llm_start( - self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any - ) -> None: - """Run when LLM starts.""" - self.step += 1 - self.llm_starts += 1 - self.starts += 1 - - metadata = self._init_resp() - metadata.update({"action": "on_llm_start"}) - metadata.update(flatten_dict(serialized)) - metadata.update(self.get_custom_callback_meta()) - - for prompt in prompts: - prompt_resp = deepcopy(metadata) - prompt_resp["prompts"] = prompt - self.on_llm_start_records.append(prompt_resp) - self.action_records.append(prompt_resp) - - if self.stream_logs: - self._log_stream(prompt, metadata, self.step) - - def on_llm_new_token(self, token: str, **kwargs: Any) -> None: - """Run when LLM generates a new token.""" - self.step += 1 - self.llm_streams += 1 - - resp = self._init_resp() - resp.update({"action": "on_llm_new_token", "token": token}) - resp.update(self.get_custom_callback_meta()) - - self.action_records.append(resp) - - def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None: - """Run when LLM ends running.""" - self.step += 1 - self.llm_ends += 1 - self.ends += 1 - - metadata = self._init_resp() - metadata.update({"action": "on_llm_end"}) - metadata.update(flatten_dict(response.llm_output or {})) - metadata.update(self.get_custom_callback_meta()) - - output_complexity_metrics = [] - output_custom_metrics = [] - - for prompt_idx, generations in enumerate(response.generations): - for gen_idx, generation in enumerate(generations): - text = generation.text - - generation_resp = deepcopy(metadata) - generation_resp.update(flatten_dict(generation.dict())) - - complexity_metrics = self._get_complexity_metrics(text) - if complexity_metrics: - output_complexity_metrics.append(complexity_metrics) - generation_resp.update(complexity_metrics) - - custom_metrics = self._get_custom_metrics( - generation, prompt_idx, gen_idx - ) - if custom_metrics: - output_custom_metrics.append(custom_metrics) - generation_resp.update(custom_metrics) - - if self.stream_logs: - self._log_stream(text, metadata, self.step) - - self.action_records.append(generation_resp) - self.on_llm_end_records.append(generation_resp) - - self._log_text_metrics(output_complexity_metrics, step=self.step) - self._log_text_metrics(output_custom_metrics, step=self.step) - - def on_llm_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when LLM errors.""" - self.step += 1 - self.errors += 1 - - def on_chain_start( - self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any - ) -> None: - """Run when chain starts running.""" - self.step += 1 - self.chain_starts += 1 - self.starts += 1 - - resp = self._init_resp() - resp.update({"action": "on_chain_start"}) - resp.update(flatten_dict(serialized)) - resp.update(self.get_custom_callback_meta()) - - for chain_input_key, chain_input_val in inputs.items(): - if isinstance(chain_input_val, str): - input_resp = deepcopy(resp) - if self.stream_logs: - self._log_stream(chain_input_val, resp, self.step) - input_resp.update({chain_input_key: chain_input_val}) - self.action_records.append(input_resp) - - else: - self.comet_ml.LOGGER.warning( - f"Unexpected data format provided! " - f"Input Value for {chain_input_key} will not be logged" - ) - - def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - """Run when chain ends running.""" - self.step += 1 - self.chain_ends += 1 - self.ends += 1 - - resp = self._init_resp() - resp.update({"action": "on_chain_end"}) - resp.update(self.get_custom_callback_meta()) - - for chain_output_key, chain_output_val in outputs.items(): - if isinstance(chain_output_val, str): - output_resp = deepcopy(resp) - if self.stream_logs: - self._log_stream(chain_output_val, resp, self.step) - output_resp.update({chain_output_key: chain_output_val}) - self.action_records.append(output_resp) - else: - self.comet_ml.LOGGER.warning( - f"Unexpected data format provided! " - f"Output Value for {chain_output_key} will not be logged" - ) - - def on_chain_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when chain errors.""" - self.step += 1 - self.errors += 1 - - def on_tool_start( - self, serialized: Dict[str, Any], input_str: str, **kwargs: Any - ) -> None: - """Run when tool starts running.""" - self.step += 1 - self.tool_starts += 1 - self.starts += 1 - - resp = self._init_resp() - resp.update({"action": "on_tool_start"}) - resp.update(flatten_dict(serialized)) - resp.update(self.get_custom_callback_meta()) - if self.stream_logs: - self._log_stream(input_str, resp, self.step) - - resp.update({"input_str": input_str}) - self.action_records.append(resp) - - def on_tool_end(self, output: str, **kwargs: Any) -> None: - """Run when tool ends running.""" - self.step += 1 - self.tool_ends += 1 - self.ends += 1 - - resp = self._init_resp() - resp.update({"action": "on_tool_end"}) - resp.update(self.get_custom_callback_meta()) - if self.stream_logs: - self._log_stream(output, resp, self.step) - - resp.update({"output": output}) - self.action_records.append(resp) - - def on_tool_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when tool errors.""" - self.step += 1 - self.errors += 1 - - def on_text(self, text: str, **kwargs: Any) -> None: - """ - Run when agent is ending. - """ - self.step += 1 - self.text_ctr += 1 - - resp = self._init_resp() - resp.update({"action": "on_text"}) - resp.update(self.get_custom_callback_meta()) - if self.stream_logs: - self._log_stream(text, resp, self.step) - - resp.update({"text": text}) - self.action_records.append(resp) - - def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> None: - """Run when agent ends running.""" - self.step += 1 - self.agent_ends += 1 - self.ends += 1 - - resp = self._init_resp() - output = finish.return_values["output"] - log = finish.log - - resp.update({"action": "on_agent_finish", "log": log}) - resp.update(self.get_custom_callback_meta()) - if self.stream_logs: - self._log_stream(output, resp, self.step) - - resp.update({"output": output}) - self.action_records.append(resp) - - def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any: - """Run on agent action.""" - self.step += 1 - self.tool_starts += 1 - self.starts += 1 - - tool = action.tool - tool_input = str(action.tool_input) - log = action.log - - resp = self._init_resp() - resp.update({"action": "on_agent_action", "log": log, "tool": tool}) - resp.update(self.get_custom_callback_meta()) - if self.stream_logs: - self._log_stream(tool_input, resp, self.step) - - resp.update({"tool_input": tool_input}) - self.action_records.append(resp) - - def _get_complexity_metrics(self, text: str) -> dict: - """Compute text complexity metrics using textstat. - - Parameters: - text (str): The text to analyze. - - Returns: - (dict): A dictionary containing the complexity metrics. - """ - resp = {} - if self.complexity_metrics: - text_complexity_metrics = _fetch_text_complexity_metrics(text) - resp.update(text_complexity_metrics) - - return resp - - def _get_custom_metrics( - self, generation: Generation, prompt_idx: int, gen_idx: int - ) -> dict: - """Compute Custom Metrics for an LLM Generated Output - - Args: - generation (LLMResult): Output generation from an LLM - prompt_idx (int): List index of the input prompt - gen_idx (int): List index of the generated output - - Returns: - dict: A dictionary containing the custom metrics. - """ - - resp = {} - if self.custom_metrics: - custom_metrics = self.custom_metrics(generation, prompt_idx, gen_idx) - resp.update(custom_metrics) - - return resp - - def flush_tracker( - self, - langchain_asset: Any = None, - task_type: Optional[str] = "inference", - workspace: Optional[str] = None, - project_name: Optional[str] = "comet-langchain-demo", - tags: Optional[Sequence] = None, - name: Optional[str] = None, - visualizations: Optional[List[str]] = None, - complexity_metrics: bool = False, - custom_metrics: Optional[Callable] = None, - finish: bool = False, - reset: bool = False, - ) -> None: - """Flush the tracker and setup the session. - - Everything after this will be a new table. - - Args: - name: Name of the performed session so far so it is identifiable - langchain_asset: The langchain asset to save. - finish: Whether to finish the run. - - Returns: - None - """ - self._log_session(langchain_asset) - - if langchain_asset: - try: - self._log_model(langchain_asset) - except Exception: - self.comet_ml.LOGGER.error( - "Failed to export agent or LLM to Comet", - exc_info=True, - extra={"show_traceback": True}, - ) - - if finish: - self.experiment.end() - - if reset: - self._reset( - task_type, - workspace, - project_name, - tags, - name, - visualizations, - complexity_metrics, - custom_metrics, - ) - - def _log_stream(self, prompt: str, metadata: dict, step: int) -> None: - self.experiment.log_text(prompt, metadata=metadata, step=step) - - def _log_model(self, langchain_asset: Any) -> None: - model_parameters = self._get_llm_parameters(langchain_asset) - self.experiment.log_parameters(model_parameters, prefix="model") - - langchain_asset_path = Path(self.temp_dir.name, "model.json") - model_name = self.name if self.name else LANGCHAIN_MODEL_NAME - - try: - if hasattr(langchain_asset, "save"): - langchain_asset.save(langchain_asset_path) - self.experiment.log_model(model_name, str(langchain_asset_path)) - except (ValueError, AttributeError, NotImplementedError) as e: - if hasattr(langchain_asset, "save_agent"): - langchain_asset.save_agent(langchain_asset_path) - self.experiment.log_model(model_name, str(langchain_asset_path)) - else: - self.comet_ml.LOGGER.error( - f"{e}" - " Could not save Langchain Asset " - f"for {langchain_asset.__class__.__name__}" - ) - - def _log_session(self, langchain_asset: Optional[Any] = None) -> None: - try: - llm_session_df = self._create_session_analysis_dataframe(langchain_asset) - # Log the cleaned dataframe as a table - self.experiment.log_table("langchain-llm-session.csv", llm_session_df) - except Exception: - self.comet_ml.LOGGER.warning( - "Failed to log session data to Comet", - exc_info=True, - extra={"show_traceback": True}, - ) - - try: - metadata = {"langchain_version": str(langchain.__version__)} - # Log the langchain low-level records as a JSON file directly - self.experiment.log_asset_data( - self.action_records, "langchain-action_records.json", metadata=metadata - ) - except Exception: - self.comet_ml.LOGGER.warning( - "Failed to log session data to Comet", - exc_info=True, - extra={"show_traceback": True}, - ) - - try: - self._log_visualizations(llm_session_df) - except Exception: - self.comet_ml.LOGGER.warning( - "Failed to log visualizations to Comet", - exc_info=True, - extra={"show_traceback": True}, - ) - - def _log_text_metrics(self, metrics: Sequence[dict], step: int) -> None: - if not metrics: - return - - metrics_summary = _summarize_metrics_for_generated_outputs(metrics) - for key, value in metrics_summary.items(): - self.experiment.log_metrics(value, prefix=key, step=step) - - def _log_visualizations(self, session_df: Any) -> None: - if not (self.visualizations and self.nlp): - return - - spacy = import_spacy() - - prompts = session_df["prompts"].tolist() - outputs = session_df["text"].tolist() - - for idx, (prompt, output) in enumerate(zip(prompts, outputs)): - doc = self.nlp(output) - sentence_spans = list(doc.sents) - - for visualization in self.visualizations: - try: - html = spacy.displacy.render( - sentence_spans, - style=visualization, - options={"compact": True}, - jupyter=False, - page=True, - ) - self.experiment.log_asset_data( - html, - name=f"langchain-viz-{visualization}-{idx}.html", - metadata={"prompt": prompt}, - step=idx, - ) - except Exception as e: - self.comet_ml.LOGGER.warning( - e, exc_info=True, extra={"show_traceback": True} - ) - - return - - def _reset( - self, - task_type: Optional[str] = None, - workspace: Optional[str] = None, - project_name: Optional[str] = None, - tags: Optional[Sequence] = None, - name: Optional[str] = None, - visualizations: Optional[List[str]] = None, - complexity_metrics: bool = False, - custom_metrics: Optional[Callable] = None, - ) -> None: - _task_type = task_type if task_type else self.task_type - _workspace = workspace if workspace else self.workspace - _project_name = project_name if project_name else self.project_name - _tags = tags if tags else self.tags - _name = name if name else self.name - _visualizations = visualizations if visualizations else self.visualizations - _complexity_metrics = ( - complexity_metrics if complexity_metrics else self.complexity_metrics - ) - _custom_metrics = custom_metrics if custom_metrics else self.custom_metrics - - self.__init__( # type: ignore - task_type=_task_type, - workspace=_workspace, - project_name=_project_name, - tags=_tags, - name=_name, - visualizations=_visualizations, - complexity_metrics=_complexity_metrics, - custom_metrics=_custom_metrics, - ) - - self.reset_callback_meta() - self.temp_dir = tempfile.TemporaryDirectory() - - def _create_session_analysis_dataframe(self, langchain_asset: Any = None) -> dict: - pd = import_pandas() - - llm_parameters = self._get_llm_parameters(langchain_asset) - num_generations_per_prompt = llm_parameters.get("n", 1) - - llm_start_records_df = pd.DataFrame(self.on_llm_start_records) - # Repeat each input row based on the number of outputs generated per prompt - llm_start_records_df = llm_start_records_df.loc[ - llm_start_records_df.index.repeat(num_generations_per_prompt) - ].reset_index(drop=True) - llm_end_records_df = pd.DataFrame(self.on_llm_end_records) - - llm_session_df = pd.merge( - llm_start_records_df, - llm_end_records_df, - left_index=True, - right_index=True, - suffixes=["_llm_start", "_llm_end"], - ) - - return llm_session_df - - def _get_llm_parameters(self, langchain_asset: Any = None) -> dict: - if not langchain_asset: - return {} - try: - if hasattr(langchain_asset, "agent"): - llm_parameters = langchain_asset.agent.llm_chain.llm.dict() - elif hasattr(langchain_asset, "llm_chain"): - llm_parameters = langchain_asset.llm_chain.llm.dict() - elif hasattr(langchain_asset, "llm"): - llm_parameters = langchain_asset.llm.dict() - else: - llm_parameters = langchain_asset.dict() - except Exception: - return {} - - return llm_parameters +__all__ = [ + "LANGCHAIN_MODEL_NAME", + "import_comet_ml", + "_get_experiment", + "_fetch_text_complexity_metrics", + "_summarize_metrics_for_generated_outputs", + "CometCallbackHandler", +] diff --git a/libs/langchain/langchain/callbacks/confident_callback.py b/libs/langchain/langchain/callbacks/confident_callback.py index 6d0dbf89248..48236ed500e 100644 --- a/libs/langchain/langchain/callbacks/confident_callback.py +++ b/libs/langchain/langchain/callbacks/confident_callback.py @@ -1,183 +1,3 @@ -# flake8: noqa -import os -import warnings -from typing import Any, Dict, List, Optional, Union +from langchain_community.callbacks.confident_callback import DeepEvalCallbackHandler -from langchain.callbacks.base import BaseCallbackHandler -from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.outputs import LLMResult - - -class DeepEvalCallbackHandler(BaseCallbackHandler): - """Callback Handler that logs into deepeval. - - Args: - implementation_name: name of the `implementation` in deepeval - metrics: A list of metrics - - Raises: - ImportError: if the `deepeval` package is not installed. - - Examples: - >>> from langchain.llms import OpenAI - >>> from langchain.callbacks import DeepEvalCallbackHandler - >>> from deepeval.metrics import AnswerRelevancy - >>> metric = AnswerRelevancy(minimum_score=0.3) - >>> deepeval_callback = DeepEvalCallbackHandler( - ... implementation_name="exampleImplementation", - ... metrics=[metric], - ... ) - >>> llm = OpenAI( - ... temperature=0, - ... callbacks=[deepeval_callback], - ... verbose=True, - ... openai_api_key="API_KEY_HERE", - ... ) - >>> llm.generate([ - ... "What is the best evaluation tool out there? (no bias at all)", - ... ]) - "Deepeval, no doubt about it." - """ - - REPO_URL: str = "https://github.com/confident-ai/deepeval" - ISSUES_URL: str = f"{REPO_URL}/issues" - BLOG_URL: str = "https://docs.confident-ai.com" # noqa: E501 - - def __init__( - self, - metrics: List[Any], - implementation_name: Optional[str] = None, - ) -> None: - """Initializes the `deepevalCallbackHandler`. - - Args: - implementation_name: Name of the implementation you want. - metrics: What metrics do you want to track? - - Raises: - ImportError: if the `deepeval` package is not installed. - ConnectionError: if the connection to deepeval fails. - """ - - super().__init__() - - # Import deepeval (not via `import_deepeval` to keep hints in IDEs) - try: - import deepeval # ignore: F401,I001 - except ImportError: - raise ImportError( - """To use the deepeval callback manager you need to have the - `deepeval` Python package installed. Please install it with - `pip install deepeval`""" - ) - - if os.path.exists(".deepeval"): - warnings.warn( - """You are currently not logging anything to the dashboard, we - recommend using `deepeval login`.""" - ) - - # Set the deepeval variables - self.implementation_name = implementation_name - self.metrics = metrics - - warnings.warn( - ( - "The `DeepEvalCallbackHandler` is currently in beta and is subject to" - " change based on updates to `langchain`. Please report any issues to" - f" {self.ISSUES_URL} as an `integration` issue." - ), - ) - - def on_llm_start( - self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any - ) -> None: - """Store the prompts""" - self.prompts = prompts - - def on_llm_new_token(self, token: str, **kwargs: Any) -> None: - """Do nothing when a new token is generated.""" - pass - - def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None: - """Log records to deepeval when an LLM ends.""" - from deepeval.metrics.answer_relevancy import AnswerRelevancy - from deepeval.metrics.bias_classifier import UnBiasedMetric - from deepeval.metrics.metric import Metric - from deepeval.metrics.toxic_classifier import NonToxicMetric - - for metric in self.metrics: - for i, generation in enumerate(response.generations): - # Here, we only measure the first generation's output - output = generation[0].text - query = self.prompts[i] - if isinstance(metric, AnswerRelevancy): - result = metric.measure( - output=output, - query=query, - ) - print(f"Answer Relevancy: {result}") - elif isinstance(metric, UnBiasedMetric): - score = metric.measure(output) - print(f"Bias Score: {score}") - elif isinstance(metric, NonToxicMetric): - score = metric.measure(output) - print(f"Toxic Score: {score}") - else: - raise ValueError( - f"""Metric {metric.__name__} is not supported by deepeval - callbacks.""" - ) - - def on_llm_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing when LLM outputs an error.""" - pass - - def on_chain_start( - self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any - ) -> None: - """Do nothing when chain starts""" - pass - - def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - """Do nothing when chain ends.""" - pass - - def on_chain_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing when LLM chain outputs an error.""" - pass - - def on_tool_start( - self, - serialized: Dict[str, Any], - input_str: str, - **kwargs: Any, - ) -> None: - """Do nothing when tool starts.""" - pass - - def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any: - """Do nothing when agent takes a specific action.""" - pass - - def on_tool_end( - self, - output: str, - observation_prefix: Optional[str] = None, - llm_prefix: Optional[str] = None, - **kwargs: Any, - ) -> None: - """Do nothing when tool ends.""" - pass - - def on_tool_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing when tool outputs an error.""" - pass - - def on_text(self, text: str, **kwargs: Any) -> None: - """Do nothing""" - pass - - def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> None: - """Do nothing""" - pass +__all__ = ["DeepEvalCallbackHandler"] diff --git a/libs/langchain/langchain/callbacks/context_callback.py b/libs/langchain/langchain/callbacks/context_callback.py index e1e87ea9cbf..0734a750bf5 100644 --- a/libs/langchain/langchain/callbacks/context_callback.py +++ b/libs/langchain/langchain/callbacks/context_callback.py @@ -1,195 +1,6 @@ -"""Callback handler for Context AI""" -import os -from typing import Any, Dict, List -from uuid import UUID +from langchain_community.callbacks.context_callback import ( + ContextCallbackHandler, + import_context, +) -from langchain_core.messages import BaseMessage -from langchain_core.outputs import LLMResult - -from langchain.callbacks.base import BaseCallbackHandler - - -def import_context() -> Any: - """Import the `getcontext` package.""" - try: - import getcontext # noqa: F401 - from getcontext.generated.models import ( - Conversation, - Message, - MessageRole, - Rating, - ) - from getcontext.token import Credential # noqa: F401 - except ImportError: - raise ImportError( - "To use the context callback manager you need to have the " - "`getcontext` python package installed (version >=0.3.0). " - "Please install it with `pip install --upgrade python-context`" - ) - return getcontext, Credential, Conversation, Message, MessageRole, Rating - - -class ContextCallbackHandler(BaseCallbackHandler): - """Callback Handler that records transcripts to the Context service. - - (https://context.ai). - - Keyword Args: - token (optional): The token with which to authenticate requests to Context. - Visit https://with.context.ai/settings to generate a token. - If not provided, the value of the `CONTEXT_TOKEN` environment - variable will be used. - - Raises: - ImportError: if the `context-python` package is not installed. - - Chat Example: - >>> from langchain.llms import ChatOpenAI - >>> from langchain.callbacks import ContextCallbackHandler - >>> context_callback = ContextCallbackHandler( - ... token="", - ... ) - >>> chat = ChatOpenAI( - ... temperature=0, - ... headers={"user_id": "123"}, - ... callbacks=[context_callback], - ... openai_api_key="API_KEY_HERE", - ... ) - >>> messages = [ - ... SystemMessage(content="You translate English to French."), - ... HumanMessage(content="I love programming with LangChain."), - ... ] - >>> chat(messages) - - Chain Example: - >>> from langchain.chains import LLMChain - >>> from langchain.chat_models import ChatOpenAI - >>> from langchain.callbacks import ContextCallbackHandler - >>> context_callback = ContextCallbackHandler( - ... token="", - ... ) - >>> human_message_prompt = HumanMessagePromptTemplate( - ... prompt=PromptTemplate( - ... template="What is a good name for a company that makes {product}?", - ... input_variables=["product"], - ... ), - ... ) - >>> chat_prompt_template = ChatPromptTemplate.from_messages( - ... [human_message_prompt] - ... ) - >>> callback = ContextCallbackHandler(token) - >>> # Note: the same callback object must be shared between the - ... LLM and the chain. - >>> chat = ChatOpenAI(temperature=0.9, callbacks=[callback]) - >>> chain = LLMChain( - ... llm=chat, - ... prompt=chat_prompt_template, - ... callbacks=[callback] - ... ) - >>> chain.run("colorful socks") - """ - - def __init__(self, token: str = "", verbose: bool = False, **kwargs: Any) -> None: - ( - self.context, - self.credential, - self.conversation_model, - self.message_model, - self.message_role_model, - self.rating_model, - ) = import_context() - - token = token or os.environ.get("CONTEXT_TOKEN") or "" - - self.client = self.context.ContextAPI(credential=self.credential(token)) - - self.chain_run_id = None - - self.llm_model = None - - self.messages: List[Any] = [] - self.metadata: Dict[str, str] = {} - - def on_chat_model_start( - self, - serialized: Dict[str, Any], - messages: List[List[BaseMessage]], - *, - run_id: UUID, - **kwargs: Any, - ) -> Any: - """Run when the chat model is started.""" - llm_model = kwargs.get("invocation_params", {}).get("model", None) - if llm_model is not None: - self.metadata["model"] = llm_model - - if len(messages) == 0: - return - - for message in messages[0]: - role = self.message_role_model.SYSTEM - if message.type == "human": - role = self.message_role_model.USER - elif message.type == "system": - role = self.message_role_model.SYSTEM - elif message.type == "ai": - role = self.message_role_model.ASSISTANT - - self.messages.append( - self.message_model( - message=message.content, - role=role, - ) - ) - - def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None: - """Run when LLM ends.""" - if len(response.generations) == 0 or len(response.generations[0]) == 0: - return - - if not self.chain_run_id: - generation = response.generations[0][0] - self.messages.append( - self.message_model( - message=generation.text, - role=self.message_role_model.ASSISTANT, - ) - ) - - self._log_conversation() - - def on_chain_start( - self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any - ) -> None: - """Run when chain starts.""" - self.chain_run_id = kwargs.get("run_id", None) - - def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - """Run when chain ends.""" - self.messages.append( - self.message_model( - message=outputs["text"], - role=self.message_role_model.ASSISTANT, - ) - ) - - self._log_conversation() - - self.chain_run_id = None - - def _log_conversation(self) -> None: - """Log the conversation to the context API.""" - if len(self.messages) == 0: - return - - self.client.log.conversation_upsert( - body={ - "conversation": self.conversation_model( - messages=self.messages, - metadata=self.metadata, - ) - } - ) - - self.messages = [] - self.metadata = {} +__all__ = ["import_context", "ContextCallbackHandler"] diff --git a/libs/langchain/langchain/callbacks/file.py b/libs/langchain/langchain/callbacks/file.py index 9768a9f0316..5102ffa92bc 100644 --- a/libs/langchain/langchain/callbacks/file.py +++ b/libs/langchain/langchain/callbacks/file.py @@ -1,70 +1,3 @@ -"""Callback Handler that writes to a file.""" -from typing import Any, Dict, Optional, TextIO, cast +from langchain_community.callbacks.file import FileCallbackHandler -from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.utils.input import print_text - -from langchain.callbacks.base import BaseCallbackHandler - - -class FileCallbackHandler(BaseCallbackHandler): - """Callback Handler that writes to a file.""" - - def __init__( - self, filename: str, mode: str = "a", color: Optional[str] = None - ) -> None: - """Initialize callback handler.""" - self.file = cast(TextIO, open(filename, mode, encoding="utf-8")) - self.color = color - - def __del__(self) -> None: - """Destructor to cleanup when done.""" - self.file.close() - - def on_chain_start( - self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any - ) -> None: - """Print out that we are entering a chain.""" - class_name = serialized.get("name", serialized.get("id", [""])[-1]) - print_text( - f"\n\n\033[1m> Entering new {class_name} chain...\033[0m", - end="\n", - file=self.file, - ) - - def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - """Print out that we finished a chain.""" - print_text("\n\033[1m> Finished chain.\033[0m", end="\n", file=self.file) - - def on_agent_action( - self, action: AgentAction, color: Optional[str] = None, **kwargs: Any - ) -> Any: - """Run on agent action.""" - print_text(action.log, color=color or self.color, file=self.file) - - def on_tool_end( - self, - output: str, - color: Optional[str] = None, - observation_prefix: Optional[str] = None, - llm_prefix: Optional[str] = None, - **kwargs: Any, - ) -> None: - """If not the final action, print out observation.""" - if observation_prefix is not None: - print_text(f"\n{observation_prefix}", file=self.file) - print_text(output, color=color or self.color, file=self.file) - if llm_prefix is not None: - print_text(f"\n{llm_prefix}", file=self.file) - - def on_text( - self, text: str, color: Optional[str] = None, end: str = "", **kwargs: Any - ) -> None: - """Run when agent ends.""" - print_text(text, color=color or self.color, end=end, file=self.file) - - def on_agent_finish( - self, finish: AgentFinish, color: Optional[str] = None, **kwargs: Any - ) -> None: - """Run on agent end.""" - print_text(finish.log, color=color or self.color, end="\n", file=self.file) +__all__ = ["FileCallbackHandler"] diff --git a/libs/langchain/langchain/callbacks/flyte_callback.py b/libs/langchain/langchain/callbacks/flyte_callback.py index a09603b693c..8d21ba860a8 100644 --- a/libs/langchain/langchain/callbacks/flyte_callback.py +++ b/libs/langchain/langchain/callbacks/flyte_callback.py @@ -1,371 +1,7 @@ -"""FlyteKit callback handler.""" -from __future__ import annotations - -import logging -from copy import deepcopy -from typing import TYPE_CHECKING, Any, Dict, List, Tuple - -from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.outputs import LLMResult - -from langchain.callbacks.base import BaseCallbackHandler -from langchain.callbacks.utils import ( - BaseMetadataCallbackHandler, - flatten_dict, - import_pandas, - import_spacy, - import_textstat, +from langchain_community.callbacks.flyte_callback import ( + FlyteCallbackHandler, + analyze_text, + import_flytekit, ) -if TYPE_CHECKING: - import flytekit - from flytekitplugins.deck import renderer - -logger = logging.getLogger(__name__) - - -def import_flytekit() -> Tuple[flytekit, renderer]: - """Import flytekit and flytekitplugins-deck-standard.""" - try: - import flytekit # noqa: F401 - from flytekitplugins.deck import renderer # noqa: F401 - except ImportError: - raise ImportError( - "To use the flyte callback manager you need" - "to have the `flytekit` and `flytekitplugins-deck-standard`" - "packages installed. Please install them with `pip install flytekit`" - "and `pip install flytekitplugins-deck-standard`." - ) - return flytekit, renderer - - -def analyze_text( - text: str, - nlp: Any = None, - textstat: Any = None, -) -> dict: - """Analyze text using textstat and spacy. - - Parameters: - text (str): The text to analyze. - nlp (spacy.lang): The spacy language model to use for visualization. - - Returns: - (dict): A dictionary containing the complexity metrics and visualization - files serialized to HTML string. - """ - resp: Dict[str, Any] = {} - if textstat is not None: - text_complexity_metrics = { - "flesch_reading_ease": textstat.flesch_reading_ease(text), - "flesch_kincaid_grade": textstat.flesch_kincaid_grade(text), - "smog_index": textstat.smog_index(text), - "coleman_liau_index": textstat.coleman_liau_index(text), - "automated_readability_index": textstat.automated_readability_index(text), - "dale_chall_readability_score": textstat.dale_chall_readability_score(text), - "difficult_words": textstat.difficult_words(text), - "linsear_write_formula": textstat.linsear_write_formula(text), - "gunning_fog": textstat.gunning_fog(text), - "fernandez_huerta": textstat.fernandez_huerta(text), - "szigriszt_pazos": textstat.szigriszt_pazos(text), - "gutierrez_polini": textstat.gutierrez_polini(text), - "crawford": textstat.crawford(text), - "gulpease_index": textstat.gulpease_index(text), - "osman": textstat.osman(text), - } - resp.update({"text_complexity_metrics": text_complexity_metrics}) - resp.update(text_complexity_metrics) - - if nlp is not None: - spacy = import_spacy() - doc = nlp(text) - dep_out = spacy.displacy.render( # type: ignore - doc, style="dep", jupyter=False, page=True - ) - ent_out = spacy.displacy.render( # type: ignore - doc, style="ent", jupyter=False, page=True - ) - text_visualizations = { - "dependency_tree": dep_out, - "entities": ent_out, - } - resp.update(text_visualizations) - - return resp - - -class FlyteCallbackHandler(BaseMetadataCallbackHandler, BaseCallbackHandler): - """This callback handler that is used within a Flyte task.""" - - def __init__(self) -> None: - """Initialize callback handler.""" - flytekit, renderer = import_flytekit() - self.pandas = import_pandas() - - self.textstat = None - try: - self.textstat = import_textstat() - except ImportError: - logger.warning( - "Textstat library is not installed. \ - It may result in the inability to log \ - certain metrics that can be captured with Textstat." - ) - - spacy = None - try: - spacy = import_spacy() - except ImportError: - logger.warning( - "Spacy library is not installed. \ - It may result in the inability to log \ - certain metrics that can be captured with Spacy." - ) - - super().__init__() - - self.nlp = None - if spacy: - try: - self.nlp = spacy.load("en_core_web_sm") - except OSError: - logger.warning( - "FlyteCallbackHandler uses spacy's en_core_web_sm model" - " for certain metrics. To download," - " run the following command in your terminal:" - " `python -m spacy download en_core_web_sm`" - ) - - self.table_renderer = renderer.TableRenderer - self.markdown_renderer = renderer.MarkdownRenderer - - self.deck = flytekit.Deck( - "LangChain Metrics", - self.markdown_renderer().to_html("## LangChain Metrics"), - ) - - def on_llm_start( - self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any - ) -> None: - """Run when LLM starts.""" - - self.step += 1 - self.llm_starts += 1 - self.starts += 1 - - resp: Dict[str, Any] = {} - resp.update({"action": "on_llm_start"}) - resp.update(flatten_dict(serialized)) - resp.update(self.get_custom_callback_meta()) - - prompt_responses = [] - for prompt in prompts: - prompt_responses.append(prompt) - - resp.update({"prompts": prompt_responses}) - - self.deck.append(self.markdown_renderer().to_html("### LLM Start")) - self.deck.append( - self.table_renderer().to_html(self.pandas.DataFrame([resp])) + "\n" - ) - - def on_llm_new_token(self, token: str, **kwargs: Any) -> None: - """Run when LLM generates a new token.""" - - def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None: - """Run when LLM ends running.""" - self.step += 1 - self.llm_ends += 1 - self.ends += 1 - - resp: Dict[str, Any] = {} - resp.update({"action": "on_llm_end"}) - resp.update(flatten_dict(response.llm_output or {})) - resp.update(self.get_custom_callback_meta()) - - self.deck.append(self.markdown_renderer().to_html("### LLM End")) - self.deck.append(self.table_renderer().to_html(self.pandas.DataFrame([resp]))) - - for generations in response.generations: - for generation in generations: - generation_resp = deepcopy(resp) - generation_resp.update(flatten_dict(generation.dict())) - if self.nlp or self.textstat: - generation_resp.update( - analyze_text( - generation.text, nlp=self.nlp, textstat=self.textstat - ) - ) - - complexity_metrics: Dict[str, float] = generation_resp.pop( - "text_complexity_metrics" - ) # type: ignore # noqa: E501 - self.deck.append( - self.markdown_renderer().to_html("#### Text Complexity Metrics") - ) - self.deck.append( - self.table_renderer().to_html( - self.pandas.DataFrame([complexity_metrics]) - ) - + "\n" - ) - - dependency_tree = generation_resp["dependency_tree"] - self.deck.append( - self.markdown_renderer().to_html("#### Dependency Tree") - ) - self.deck.append(dependency_tree) - - entities = generation_resp["entities"] - self.deck.append(self.markdown_renderer().to_html("#### Entities")) - self.deck.append(entities) - else: - self.deck.append( - self.markdown_renderer().to_html("#### Generated Response") - ) - self.deck.append(self.markdown_renderer().to_html(generation.text)) - - def on_llm_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when LLM errors.""" - self.step += 1 - self.errors += 1 - - def on_chain_start( - self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any - ) -> None: - """Run when chain starts running.""" - self.step += 1 - self.chain_starts += 1 - self.starts += 1 - - resp: Dict[str, Any] = {} - resp.update({"action": "on_chain_start"}) - resp.update(flatten_dict(serialized)) - resp.update(self.get_custom_callback_meta()) - - chain_input = ",".join([f"{k}={v}" for k, v in inputs.items()]) - input_resp = deepcopy(resp) - input_resp["inputs"] = chain_input - - self.deck.append(self.markdown_renderer().to_html("### Chain Start")) - self.deck.append( - self.table_renderer().to_html(self.pandas.DataFrame([input_resp])) + "\n" - ) - - def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - """Run when chain ends running.""" - self.step += 1 - self.chain_ends += 1 - self.ends += 1 - - resp: Dict[str, Any] = {} - chain_output = ",".join([f"{k}={v}" for k, v in outputs.items()]) - resp.update({"action": "on_chain_end", "outputs": chain_output}) - resp.update(self.get_custom_callback_meta()) - - self.deck.append(self.markdown_renderer().to_html("### Chain End")) - self.deck.append( - self.table_renderer().to_html(self.pandas.DataFrame([resp])) + "\n" - ) - - def on_chain_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when chain errors.""" - self.step += 1 - self.errors += 1 - - def on_tool_start( - self, serialized: Dict[str, Any], input_str: str, **kwargs: Any - ) -> None: - """Run when tool starts running.""" - self.step += 1 - self.tool_starts += 1 - self.starts += 1 - - resp: Dict[str, Any] = {} - resp.update({"action": "on_tool_start", "input_str": input_str}) - resp.update(flatten_dict(serialized)) - resp.update(self.get_custom_callback_meta()) - - self.deck.append(self.markdown_renderer().to_html("### Tool Start")) - self.deck.append( - self.table_renderer().to_html(self.pandas.DataFrame([resp])) + "\n" - ) - - def on_tool_end(self, output: str, **kwargs: Any) -> None: - """Run when tool ends running.""" - self.step += 1 - self.tool_ends += 1 - self.ends += 1 - - resp: Dict[str, Any] = {} - resp.update({"action": "on_tool_end", "output": output}) - resp.update(self.get_custom_callback_meta()) - - self.deck.append(self.markdown_renderer().to_html("### Tool End")) - self.deck.append( - self.table_renderer().to_html(self.pandas.DataFrame([resp])) + "\n" - ) - - def on_tool_error(self, error: BaseException, **kwargs: Any) -> None: - """Run when tool errors.""" - self.step += 1 - self.errors += 1 - - def on_text(self, text: str, **kwargs: Any) -> None: - """ - Run when agent is ending. - """ - self.step += 1 - self.text_ctr += 1 - - resp: Dict[str, Any] = {} - resp.update({"action": "on_text", "text": text}) - resp.update(self.get_custom_callback_meta()) - - self.deck.append(self.markdown_renderer().to_html("### On Text")) - self.deck.append( - self.table_renderer().to_html(self.pandas.DataFrame([resp])) + "\n" - ) - - def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> None: - """Run when agent ends running.""" - self.step += 1 - self.agent_ends += 1 - self.ends += 1 - - resp: Dict[str, Any] = {} - resp.update( - { - "action": "on_agent_finish", - "output": finish.return_values["output"], - "log": finish.log, - } - ) - resp.update(self.get_custom_callback_meta()) - - self.deck.append(self.markdown_renderer().to_html("### Agent Finish")) - self.deck.append( - self.table_renderer().to_html(self.pandas.DataFrame([resp])) + "\n" - ) - - def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any: - """Run on agent action.""" - self.step += 1 - self.tool_starts += 1 - self.starts += 1 - - resp: Dict[str, Any] = {} - resp.update( - { - "action": "on_agent_action", - "tool": action.tool, - "tool_input": action.tool_input, - "log": action.log, - } - ) - resp.update(self.get_custom_callback_meta()) - - self.deck.append(self.markdown_renderer().to_html("### Agent Action")) - self.deck.append( - self.table_renderer().to_html(self.pandas.DataFrame([resp])) + "\n" - ) +__all__ = ["import_flytekit", "analyze_text", "FlyteCallbackHandler"] diff --git a/libs/langchain/langchain/callbacks/human.py b/libs/langchain/langchain/callbacks/human.py index d4b1db039e0..4302bec9456 100644 --- a/libs/langchain/langchain/callbacks/human.py +++ b/libs/langchain/langchain/callbacks/human.py @@ -1,88 +1,15 @@ -from typing import Any, Awaitable, Callable, Dict, Optional -from uuid import UUID +from langchain_community.callbacks.human import ( + AsyncHumanApprovalCallbackHandler, + HumanApprovalCallbackHandler, + HumanRejectedException, + _default_approve, + _default_true, +) -from langchain.callbacks.base import AsyncCallbackHandler, BaseCallbackHandler - - -def _default_approve(_input: str) -> bool: - msg = ( - "Do you approve of the following input? " - "Anything except 'Y'/'Yes' (case-insensitive) will be treated as a no." - ) - msg += "\n\n" + _input + "\n" - resp = input(msg) - return resp.lower() in ("yes", "y") - - -async def _adefault_approve(_input: str) -> bool: - msg = ( - "Do you approve of the following input? " - "Anything except 'Y'/'Yes' (case-insensitive) will be treated as a no." - ) - msg += "\n\n" + _input + "\n" - resp = input(msg) - return resp.lower() in ("yes", "y") - - -def _default_true(_: Dict[str, Any]) -> bool: - return True - - -class HumanRejectedException(Exception): - """Exception to raise when a person manually review and rejects a value.""" - - -class HumanApprovalCallbackHandler(BaseCallbackHandler): - """Callback for manually validating values.""" - - raise_error: bool = True - - def __init__( - self, - approve: Callable[[Any], bool] = _default_approve, - should_check: Callable[[Dict[str, Any]], bool] = _default_true, - ): - self._approve = approve - self._should_check = should_check - - def on_tool_start( - self, - serialized: Dict[str, Any], - input_str: str, - *, - run_id: UUID, - parent_run_id: Optional[UUID] = None, - **kwargs: Any, - ) -> Any: - if self._should_check(serialized) and not self._approve(input_str): - raise HumanRejectedException( - f"Inputs {input_str} to tool {serialized} were rejected." - ) - - -class AsyncHumanApprovalCallbackHandler(AsyncCallbackHandler): - """Asynchronous callback for manually validating values.""" - - raise_error: bool = True - - def __init__( - self, - approve: Callable[[Any], Awaitable[bool]] = _adefault_approve, - should_check: Callable[[Dict[str, Any]], bool] = _default_true, - ): - self._approve = approve - self._should_check = should_check - - async def on_tool_start( - self, - serialized: Dict[str, Any], - input_str: str, - *, - run_id: UUID, - parent_run_id: Optional[UUID] = None, - **kwargs: Any, - ) -> Any: - if self._should_check(serialized) and not await self._approve(input_str): - raise HumanRejectedException( - f"Inputs {input_str} to tool {serialized} were rejected." - ) +__all__ = [ + "_default_approve", + "_default_true", + "HumanRejectedException", + "HumanApprovalCallbackHandler", + "AsyncHumanApprovalCallbackHandler", +] diff --git a/libs/langchain/langchain/callbacks/infino_callback.py b/libs/langchain/langchain/callbacks/infino_callback.py index 926f3819820..6303b2b6c0c 100644 --- a/libs/langchain/langchain/callbacks/infino_callback.py +++ b/libs/langchain/langchain/callbacks/infino_callback.py @@ -1,267 +1,13 @@ -import time -from typing import Any, Dict, List, Optional, cast +from langchain_community.callbacks.infino_callback import ( + InfinoCallbackHandler, + get_num_tokens, + import_infino, + import_tiktoken, +) -from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.messages import BaseMessage -from langchain_core.outputs import LLMResult - -from langchain.callbacks.base import BaseCallbackHandler - - -def import_infino() -> Any: - """Import the infino client.""" - try: - from infinopy import InfinoClient - except ImportError: - raise ImportError( - "To use the Infino callbacks manager you need to have the" - " `infinopy` python package installed." - "Please install it with `pip install infinopy`" - ) - return InfinoClient() - - -def import_tiktoken() -> Any: - """Import tiktoken for counting tokens for OpenAI models.""" - try: - import tiktoken - except ImportError: - raise ImportError( - "To use the ChatOpenAI model with Infino callback manager, you need to " - "have the `tiktoken` python package installed." - "Please install it with `pip install tiktoken`" - ) - return tiktoken - - -def get_num_tokens(string: str, openai_model_name: str) -> int: - """Calculate num tokens for OpenAI with tiktoken package. - - Official documentation: https://github.com/openai/openai-cookbook/blob/main - /examples/How_to_count_tokens_with_tiktoken.ipynb - """ - tiktoken = import_tiktoken() - - encoding = tiktoken.encoding_for_model(openai_model_name) - num_tokens = len(encoding.encode(string)) - return num_tokens - - -class InfinoCallbackHandler(BaseCallbackHandler): - """Callback Handler that logs to Infino.""" - - def __init__( - self, - model_id: Optional[str] = None, - model_version: Optional[str] = None, - verbose: bool = False, - ) -> None: - # Set Infino client - self.client = import_infino() - self.model_id = model_id - self.model_version = model_version - self.verbose = verbose - self.is_chat_openai_model = False - self.chat_openai_model_name = "gpt-3.5-turbo" - - def _send_to_infino( - self, - key: str, - value: Any, - is_ts: bool = True, - ) -> None: - """Send the key-value to Infino. - - Parameters: - key (str): the key to send to Infino. - value (Any): the value to send to Infino. - is_ts (bool): if True, the value is part of a time series, else it - is sent as a log message. - """ - payload = { - "date": int(time.time()), - key: value, - "labels": { - "model_id": self.model_id, - "model_version": self.model_version, - }, - } - if self.verbose: - print(f"Tracking {key} with Infino: {payload}") - - # Append to Infino time series only if is_ts is True, otherwise - # append to Infino log. - if is_ts: - self.client.append_ts(payload) - else: - self.client.append_log(payload) - - def on_llm_start( - self, - serialized: Dict[str, Any], - prompts: List[str], - **kwargs: Any, - ) -> None: - """Log the prompts to Infino, and set start time and error flag.""" - for prompt in prompts: - self._send_to_infino("prompt", prompt, is_ts=False) - - # Set the error flag to indicate no error (this will get overridden - # in on_llm_error if an error occurs). - self.error = 0 - - # Set the start time (so that we can calculate the request - # duration in on_llm_end). - self.start_time = time.time() - - def on_llm_new_token(self, token: str, **kwargs: Any) -> None: - """Do nothing when a new token is generated.""" - pass - - def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None: - """Log the latency, error, token usage, and response to Infino.""" - # Calculate and track the request latency. - self.end_time = time.time() - duration = self.end_time - self.start_time - self._send_to_infino("latency", duration) - - # Track success or error flag. - self._send_to_infino("error", self.error) - - # Track prompt response. - for generations in response.generations: - for generation in generations: - self._send_to_infino("prompt_response", generation.text, is_ts=False) - - # Track token usage (for non-chat models). - if (response.llm_output is not None) and isinstance(response.llm_output, Dict): - token_usage = response.llm_output["token_usage"] - if token_usage is not None: - prompt_tokens = token_usage["prompt_tokens"] - total_tokens = token_usage["total_tokens"] - completion_tokens = token_usage["completion_tokens"] - self._send_to_infino("prompt_tokens", prompt_tokens) - self._send_to_infino("total_tokens", total_tokens) - self._send_to_infino("completion_tokens", completion_tokens) - - # Track completion token usage (for openai chat models). - if self.is_chat_openai_model: - messages = " ".join( - generation.message.content # type: ignore[attr-defined] - for generation in generations - ) - completion_tokens = get_num_tokens( - messages, openai_model_name=self.chat_openai_model_name - ) - self._send_to_infino("completion_tokens", completion_tokens) - - def on_llm_error(self, error: BaseException, **kwargs: Any) -> None: - """Set the error flag.""" - self.error = 1 - - def on_chain_start( - self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any - ) -> None: - """Do nothing when LLM chain starts.""" - pass - - def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None: - """Do nothing when LLM chain ends.""" - pass - - def on_chain_error(self, error: BaseException, **kwargs: Any) -> None: - """Need to log the error.""" - pass - - def on_tool_start( - self, - serialized: Dict[str, Any], - input_str: str, - **kwargs: Any, - ) -> None: - """Do nothing when tool starts.""" - pass - - def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any: - """Do nothing when agent takes a specific action.""" - pass - - def on_tool_end( - self, - output: str, - observation_prefix: Optional[str] = None, - llm_prefix: Optional[str] = None, - **kwargs: Any, - ) -> None: - """Do nothing when tool ends.""" - pass - - def on_tool_error(self, error: BaseException, **kwargs: Any) -> None: - """Do nothing when tool outputs an error.""" - pass - - def on_text(self, text: str, **kwargs: Any) -> None: - """Do nothing.""" - pass - - def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> None: - """Do nothing.""" - pass - - def on_chat_model_start( - self, - serialized: Dict[str, Any], - messages: List[List[BaseMessage]], - **kwargs: Any, - ) -> None: - """Run when LLM starts running.""" - - # Currently, for chat models, we only support input prompts for ChatOpenAI. - # Check if this model is a ChatOpenAI model. - values = serialized.get("id") - if values: - for value in values: - if value == "ChatOpenAI": - self.is_chat_openai_model = True - break - - # Track prompt tokens for ChatOpenAI model. - if self.is_chat_openai_model: - invocation_params = kwargs.get("invocation_params") - if invocation_params: - model_name = invocation_params.get("model_name") - if model_name: - self.chat_openai_model_name = model_name - prompt_tokens = 0 - for message_list in messages: - message_string = " ".join( - cast(str, msg.content) for msg in message_list - ) - num_tokens = get_num_tokens( - message_string, - openai_model_name=self.chat_openai_model_name, - ) - prompt_tokens += num_tokens - - self._send_to_infino("prompt_tokens", prompt_tokens) - - if self.verbose: - print( - f"on_chat_model_start: is_chat_openai_model= \ - {self.is_chat_openai_model}, \ - chat_openai_model_name={self.chat_openai_model_name}" - ) - - # Send the prompt to infino - prompt = " ".join( - cast(str, msg.content) for sublist in messages for msg in sublist - ) - self._send_to_infino("prompt", prompt, is_ts=False) - - # Set the error flag to indicate no error (this will get overridden - # in on_llm_error if an error occurs). - self.error = 0 - - # Set the start time (so that we can calculate the request - # duration in on_llm_end). - self.start_time = time.time() +__all__ = [ + "import_infino", + "import_tiktoken", + "get_num_tokens", + "InfinoCallbackHandler", +] diff --git a/libs/langchain/langchain/callbacks/labelstudio_callback.py b/libs/langchain/langchain/callbacks/labelstudio_callback.py index e651be06888..5790dff396d 100644 --- a/libs/langchain/langchain/callbacks/labelstudio_callback.py +++ b/libs/langchain/langchain/callbacks/labelstudio_callback.py @@ -1,391 +1,7 @@ -import os -import warnings -from datetime import datetime -from enum import Enum -from typing import Any, Dict, List, Optional, Tuple, Union -from uuid import UUID +from langchain_community.callbacks.labelstudio_callback import ( + LabelStudioCallbackHandler, + LabelStudioMode, + get_default_label_configs, +) -from langchain_core.agents import AgentAction, AgentFinish -from langchain_core.messages import BaseMessage, ChatMessage -from langchain_core.outputs import Generation, LLMResult - -from langchain.callbacks.base import BaseCallbackHandler - - -class LabelStudioMode(Enum): - """Label Studio mode enumerator.""" - - PROMPT = "prompt" - CHAT = "chat" - - -def get_default_label_configs( - mode: Union[str, LabelStudioMode] -) -> Tuple[str, LabelStudioMode]: - """Get default Label Studio configs for the given mode. - - Parameters: - mode: Label Studio mode ("prompt" or "chat") - - Returns: Tuple of Label Studio config and mode - """ - _default_label_configs = { - LabelStudioMode.PROMPT.value: """ - - - - - - -