initial commit
This commit is contained in:
424
venv/Lib/site-packages/langchain_classic/__init__.py
Normal file
424
venv/Lib/site-packages/langchain_classic/__init__.py
Normal file
@@ -0,0 +1,424 @@
|
||||
"""Main entrypoint into package."""
|
||||
|
||||
import warnings
|
||||
from importlib import metadata
|
||||
from typing import Any
|
||||
|
||||
from langchain_core._api.deprecation import surface_langchain_deprecation_warnings
|
||||
|
||||
try:
|
||||
__version__ = metadata.version(__package__)
|
||||
except metadata.PackageNotFoundError:
|
||||
# Case where package metadata is not available.
|
||||
__version__ = ""
|
||||
del metadata # optional, avoids polluting the results of dir(__package__)
|
||||
|
||||
|
||||
def _warn_on_import(name: str, replacement: str | None = None) -> None:
|
||||
"""Warn on import of deprecated module."""
|
||||
from langchain_classic._api.interactive_env import is_interactive_env
|
||||
|
||||
if is_interactive_env():
|
||||
# No warnings for interactive environments.
|
||||
# This is done to avoid polluting the output of interactive environments
|
||||
# where users rely on auto-complete and may trigger this warning
|
||||
# even if they are not using any deprecated modules
|
||||
return
|
||||
|
||||
if replacement:
|
||||
warnings.warn(
|
||||
f"Importing {name} from langchain root module is no longer supported. "
|
||||
f"Please use {replacement} instead.",
|
||||
stacklevel=3,
|
||||
)
|
||||
else:
|
||||
warnings.warn(
|
||||
f"Importing {name} from langchain root module is no longer supported.",
|
||||
stacklevel=3,
|
||||
)
|
||||
|
||||
|
||||
# Surfaces Deprecation and Pending Deprecation warnings from langchain_classic.
|
||||
surface_langchain_deprecation_warnings()
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
if name == "MRKLChain":
|
||||
from langchain_classic.agents import MRKLChain
|
||||
|
||||
_warn_on_import(name, replacement="langchain_classic.agents.MRKLChain")
|
||||
|
||||
return MRKLChain
|
||||
if name == "ReActChain":
|
||||
from langchain_classic.agents import ReActChain
|
||||
|
||||
_warn_on_import(name, replacement="langchain_classic.agents.ReActChain")
|
||||
|
||||
return ReActChain
|
||||
if name == "SelfAskWithSearchChain":
|
||||
from langchain_classic.agents import SelfAskWithSearchChain
|
||||
|
||||
_warn_on_import(
|
||||
name, replacement="langchain_classic.agents.SelfAskWithSearchChain"
|
||||
)
|
||||
|
||||
return SelfAskWithSearchChain
|
||||
if name == "ConversationChain":
|
||||
from langchain_classic.chains import ConversationChain
|
||||
|
||||
_warn_on_import(name, replacement="langchain_classic.chains.ConversationChain")
|
||||
|
||||
return ConversationChain
|
||||
if name == "LLMBashChain":
|
||||
msg = (
|
||||
"This module has been moved to langchain-experimental. "
|
||||
"For more details: "
|
||||
"https://github.com/langchain-ai/langchain/discussions/11352."
|
||||
"To access this code, install it with `pip install langchain-experimental`."
|
||||
"`from langchain_experimental.llm_bash.base "
|
||||
"import LLMBashChain`"
|
||||
)
|
||||
raise ImportError(msg)
|
||||
|
||||
if name == "LLMChain":
|
||||
from langchain_classic.chains import LLMChain
|
||||
|
||||
_warn_on_import(name, replacement="langchain_classic.chains.LLMChain")
|
||||
|
||||
return LLMChain
|
||||
if name == "LLMCheckerChain":
|
||||
from langchain_classic.chains import LLMCheckerChain
|
||||
|
||||
_warn_on_import(name, replacement="langchain_classic.chains.LLMCheckerChain")
|
||||
|
||||
return LLMCheckerChain
|
||||
if name == "LLMMathChain":
|
||||
from langchain_classic.chains import LLMMathChain
|
||||
|
||||
_warn_on_import(name, replacement="langchain_classic.chains.LLMMathChain")
|
||||
|
||||
return LLMMathChain
|
||||
if name == "QAWithSourcesChain":
|
||||
from langchain_classic.chains import QAWithSourcesChain
|
||||
|
||||
_warn_on_import(name, replacement="langchain_classic.chains.QAWithSourcesChain")
|
||||
|
||||
return QAWithSourcesChain
|
||||
if name == "VectorDBQA":
|
||||
from langchain_classic.chains import VectorDBQA
|
||||
|
||||
_warn_on_import(name, replacement="langchain_classic.chains.VectorDBQA")
|
||||
|
||||
return VectorDBQA
|
||||
if name == "VectorDBQAWithSourcesChain":
|
||||
from langchain_classic.chains import VectorDBQAWithSourcesChain
|
||||
|
||||
_warn_on_import(
|
||||
name, replacement="langchain_classic.chains.VectorDBQAWithSourcesChain"
|
||||
)
|
||||
|
||||
return VectorDBQAWithSourcesChain
|
||||
if name == "InMemoryDocstore":
|
||||
from langchain_community.docstore import InMemoryDocstore
|
||||
|
||||
_warn_on_import(name, replacement="langchain_classic.docstore.InMemoryDocstore")
|
||||
|
||||
return InMemoryDocstore
|
||||
if name == "Wikipedia":
|
||||
from langchain_community.docstore import Wikipedia
|
||||
|
||||
_warn_on_import(name, replacement="langchain_classic.docstore.Wikipedia")
|
||||
|
||||
return Wikipedia
|
||||
if name == "Anthropic":
|
||||
from langchain_community.llms import Anthropic
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.Anthropic")
|
||||
|
||||
return Anthropic
|
||||
if name == "Banana":
|
||||
from langchain_community.llms import Banana
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.Banana")
|
||||
|
||||
return Banana
|
||||
if name == "CerebriumAI":
|
||||
from langchain_community.llms import CerebriumAI
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.CerebriumAI")
|
||||
|
||||
return CerebriumAI
|
||||
if name == "Cohere":
|
||||
from langchain_community.llms import Cohere
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.Cohere")
|
||||
|
||||
return Cohere
|
||||
if name == "ForefrontAI":
|
||||
from langchain_community.llms import ForefrontAI
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.ForefrontAI")
|
||||
|
||||
return ForefrontAI
|
||||
if name == "GooseAI":
|
||||
from langchain_community.llms import GooseAI
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.GooseAI")
|
||||
|
||||
return GooseAI
|
||||
if name == "HuggingFaceHub":
|
||||
from langchain_community.llms import HuggingFaceHub
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.HuggingFaceHub")
|
||||
|
||||
return HuggingFaceHub
|
||||
if name == "HuggingFaceTextGenInference":
|
||||
from langchain_community.llms import HuggingFaceTextGenInference
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.llms.HuggingFaceTextGenInference",
|
||||
)
|
||||
|
||||
return HuggingFaceTextGenInference
|
||||
if name == "LlamaCpp":
|
||||
from langchain_community.llms import LlamaCpp
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.LlamaCpp")
|
||||
|
||||
return LlamaCpp
|
||||
if name == "Modal":
|
||||
from langchain_community.llms import Modal
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.Modal")
|
||||
|
||||
return Modal
|
||||
if name == "OpenAI":
|
||||
from langchain_community.llms import OpenAI
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.OpenAI")
|
||||
|
||||
return OpenAI
|
||||
if name == "Petals":
|
||||
from langchain_community.llms import Petals
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.Petals")
|
||||
|
||||
return Petals
|
||||
if name == "PipelineAI":
|
||||
from langchain_community.llms import PipelineAI
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.PipelineAI")
|
||||
|
||||
return PipelineAI
|
||||
if name == "SagemakerEndpoint":
|
||||
from langchain_community.llms import SagemakerEndpoint
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.SagemakerEndpoint")
|
||||
|
||||
return SagemakerEndpoint
|
||||
if name == "StochasticAI":
|
||||
from langchain_community.llms import StochasticAI
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.StochasticAI")
|
||||
|
||||
return StochasticAI
|
||||
if name == "Writer":
|
||||
from langchain_community.llms import Writer
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.llms.Writer")
|
||||
|
||||
return Writer
|
||||
if name == "HuggingFacePipeline":
|
||||
from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.llms.huggingface_pipeline.HuggingFacePipeline",
|
||||
)
|
||||
|
||||
return HuggingFacePipeline
|
||||
if name == "FewShotPromptTemplate":
|
||||
from langchain_core.prompts import FewShotPromptTemplate
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_core.prompts.FewShotPromptTemplate",
|
||||
)
|
||||
|
||||
return FewShotPromptTemplate
|
||||
if name == "Prompt":
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
|
||||
_warn_on_import(name, replacement="langchain_core.prompts.PromptTemplate")
|
||||
|
||||
# it's renamed as prompt template anyways
|
||||
# this is just for backwards compat
|
||||
return PromptTemplate
|
||||
if name == "PromptTemplate":
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
|
||||
_warn_on_import(name, replacement="langchain_core.prompts.PromptTemplate")
|
||||
|
||||
return PromptTemplate
|
||||
if name == "BasePromptTemplate":
|
||||
from langchain_core.prompts import BasePromptTemplate
|
||||
|
||||
_warn_on_import(name, replacement="langchain_core.prompts.BasePromptTemplate")
|
||||
|
||||
return BasePromptTemplate
|
||||
if name == "ArxivAPIWrapper":
|
||||
from langchain_community.utilities import ArxivAPIWrapper
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.utilities.ArxivAPIWrapper",
|
||||
)
|
||||
|
||||
return ArxivAPIWrapper
|
||||
if name == "GoldenQueryAPIWrapper":
|
||||
from langchain_community.utilities import GoldenQueryAPIWrapper
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.utilities.GoldenQueryAPIWrapper",
|
||||
)
|
||||
|
||||
return GoldenQueryAPIWrapper
|
||||
if name == "GoogleSearchAPIWrapper":
|
||||
from langchain_community.utilities import GoogleSearchAPIWrapper
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.utilities.GoogleSearchAPIWrapper",
|
||||
)
|
||||
|
||||
return GoogleSearchAPIWrapper
|
||||
if name == "GoogleSerperAPIWrapper":
|
||||
from langchain_community.utilities import GoogleSerperAPIWrapper
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.utilities.GoogleSerperAPIWrapper",
|
||||
)
|
||||
|
||||
return GoogleSerperAPIWrapper
|
||||
if name == "PowerBIDataset":
|
||||
from langchain_community.utilities import PowerBIDataset
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.utilities.PowerBIDataset",
|
||||
)
|
||||
|
||||
return PowerBIDataset
|
||||
if name == "SearxSearchWrapper":
|
||||
from langchain_community.utilities import SearxSearchWrapper
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.utilities.SearxSearchWrapper",
|
||||
)
|
||||
|
||||
return SearxSearchWrapper
|
||||
if name == "WikipediaAPIWrapper":
|
||||
from langchain_community.utilities import WikipediaAPIWrapper
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.utilities.WikipediaAPIWrapper",
|
||||
)
|
||||
|
||||
return WikipediaAPIWrapper
|
||||
if name == "WolframAlphaAPIWrapper":
|
||||
from langchain_community.utilities import WolframAlphaAPIWrapper
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.utilities.WolframAlphaAPIWrapper",
|
||||
)
|
||||
|
||||
return WolframAlphaAPIWrapper
|
||||
if name == "SQLDatabase":
|
||||
from langchain_community.utilities import SQLDatabase
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.utilities.SQLDatabase")
|
||||
|
||||
return SQLDatabase
|
||||
if name == "FAISS":
|
||||
from langchain_community.vectorstores import FAISS
|
||||
|
||||
_warn_on_import(name, replacement="langchain_community.vectorstores.FAISS")
|
||||
|
||||
return FAISS
|
||||
if name == "ElasticVectorSearch":
|
||||
from langchain_community.vectorstores import ElasticVectorSearch
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.vectorstores.ElasticVectorSearch",
|
||||
)
|
||||
|
||||
return ElasticVectorSearch
|
||||
# For backwards compatibility
|
||||
if name in {"SerpAPIChain", "SerpAPIWrapper"}:
|
||||
from langchain_community.utilities import SerpAPIWrapper
|
||||
|
||||
_warn_on_import(
|
||||
name,
|
||||
replacement="langchain_community.utilities.SerpAPIWrapper",
|
||||
)
|
||||
|
||||
return SerpAPIWrapper
|
||||
msg = f"Could not find: {name}"
|
||||
raise AttributeError(msg)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"FAISS",
|
||||
"Anthropic",
|
||||
"ArxivAPIWrapper",
|
||||
"Banana",
|
||||
"BasePromptTemplate",
|
||||
"CerebriumAI",
|
||||
"Cohere",
|
||||
"ConversationChain",
|
||||
"ElasticVectorSearch",
|
||||
"FewShotPromptTemplate",
|
||||
"ForefrontAI",
|
||||
"GoldenQueryAPIWrapper",
|
||||
"GoogleSearchAPIWrapper",
|
||||
"GoogleSerperAPIWrapper",
|
||||
"GooseAI",
|
||||
"HuggingFaceHub",
|
||||
"HuggingFacePipeline",
|
||||
"HuggingFaceTextGenInference",
|
||||
"InMemoryDocstore",
|
||||
"LLMChain",
|
||||
"LLMCheckerChain",
|
||||
"LLMMathChain",
|
||||
"LlamaCpp",
|
||||
"MRKLChain",
|
||||
"Modal",
|
||||
"OpenAI",
|
||||
"Petals",
|
||||
"PipelineAI",
|
||||
"PowerBIDataset",
|
||||
"Prompt",
|
||||
"PromptTemplate",
|
||||
"QAWithSourcesChain",
|
||||
"ReActChain",
|
||||
"SQLDatabase",
|
||||
"SagemakerEndpoint",
|
||||
"SearxSearchWrapper",
|
||||
"SelfAskWithSearchChain",
|
||||
"SerpAPIChain",
|
||||
"SerpAPIWrapper",
|
||||
"StochasticAI",
|
||||
"VectorDBQA",
|
||||
"VectorDBQAWithSourcesChain",
|
||||
"Wikipedia",
|
||||
"WikipediaAPIWrapper",
|
||||
"WolframAlphaAPIWrapper",
|
||||
"Writer",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
28
venv/Lib/site-packages/langchain_classic/_api/__init__.py
Normal file
28
venv/Lib/site-packages/langchain_classic/_api/__init__.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Helper functions for managing the LangChain API.
|
||||
|
||||
This module is only relevant for LangChain developers, not for users.
|
||||
|
||||
!!! warning
|
||||
|
||||
This module and its submodules are for internal use only. Do not use them in your
|
||||
own code. We may change the API at any time with no warning.
|
||||
|
||||
"""
|
||||
|
||||
from langchain_classic._api.deprecation import (
|
||||
LangChainDeprecationWarning,
|
||||
deprecated,
|
||||
suppress_langchain_deprecation_warning,
|
||||
surface_langchain_deprecation_warnings,
|
||||
warn_deprecated,
|
||||
)
|
||||
from langchain_classic._api.module_import import create_importer
|
||||
|
||||
__all__ = [
|
||||
"LangChainDeprecationWarning",
|
||||
"create_importer",
|
||||
"deprecated",
|
||||
"suppress_langchain_deprecation_warning",
|
||||
"surface_langchain_deprecation_warnings",
|
||||
"warn_deprecated",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
33
venv/Lib/site-packages/langchain_classic/_api/deprecation.py
Normal file
33
venv/Lib/site-packages/langchain_classic/_api/deprecation.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from langchain_core._api.deprecation import (
|
||||
LangChainDeprecationWarning,
|
||||
LangChainPendingDeprecationWarning,
|
||||
deprecated,
|
||||
suppress_langchain_deprecation_warning,
|
||||
surface_langchain_deprecation_warnings,
|
||||
warn_deprecated,
|
||||
)
|
||||
|
||||
# TODO: this is old, fix
|
||||
AGENT_DEPRECATION_WARNING = (
|
||||
"LangChain agents will continue to be supported, but it is recommended for new "
|
||||
"use cases to be built with LangGraph. LangGraph offers a more flexible and "
|
||||
"full-featured framework for building agents, including support for "
|
||||
"tool-calling, persistence of state, and human-in-the-loop workflows. For "
|
||||
"details, refer to the "
|
||||
"[LangGraph documentation](https://langchain-ai.github.io/langgraph/)"
|
||||
" as well as guides for "
|
||||
"[Migrating from AgentExecutor](https://python.langchain.com/docs/how_to/migrate_agent/)"
|
||||
" and LangGraph's "
|
||||
"[Pre-built ReAct agent](https://langchain-ai.github.io/langgraph/how-tos/create-react-agent/)."
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"AGENT_DEPRECATION_WARNING",
|
||||
"LangChainDeprecationWarning",
|
||||
"LangChainPendingDeprecationWarning",
|
||||
"deprecated",
|
||||
"suppress_langchain_deprecation_warning",
|
||||
"surface_langchain_deprecation_warnings",
|
||||
"warn_deprecated",
|
||||
]
|
||||
@@ -0,0 +1,5 @@
|
||||
def is_interactive_env() -> bool:
|
||||
"""Determine if running within IPython or Jupyter."""
|
||||
import sys
|
||||
|
||||
return hasattr(sys, "ps2")
|
||||
156
venv/Lib/site-packages/langchain_classic/_api/module_import.py
Normal file
156
venv/Lib/site-packages/langchain_classic/_api/module_import.py
Normal file
@@ -0,0 +1,156 @@
|
||||
import importlib
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
from langchain_core._api import internal, warn_deprecated
|
||||
|
||||
from langchain_classic._api.interactive_env import is_interactive_env
|
||||
|
||||
ALLOWED_TOP_LEVEL_PKGS = {
|
||||
"langchain_community",
|
||||
"langchain_core",
|
||||
"langchain_classic",
|
||||
}
|
||||
|
||||
|
||||
def create_importer(
|
||||
package: str,
|
||||
*,
|
||||
module_lookup: dict[str, str] | None = None,
|
||||
deprecated_lookups: dict[str, str] | None = None,
|
||||
fallback_module: str | None = None,
|
||||
) -> Callable[[str], Any]:
|
||||
"""Create a function that helps retrieve objects from their new locations.
|
||||
|
||||
The goal of this function is to help users transition from deprecated
|
||||
imports to new imports.
|
||||
|
||||
The function will raise deprecation warning on loops using
|
||||
`deprecated_lookups` or `fallback_module`.
|
||||
|
||||
Module lookups will import without deprecation warnings (used to speed
|
||||
up imports from large namespaces like llms or chat models).
|
||||
|
||||
This function should ideally only be used with deprecated imports not with
|
||||
existing imports that are valid, as in addition to raising deprecation warnings
|
||||
the dynamic imports can create other issues for developers (e.g.,
|
||||
loss of type information, IDE support for going to definition etc).
|
||||
|
||||
Args:
|
||||
package: Current package. Use `__package__`
|
||||
module_lookup: Maps name of object to the module where it is defined.
|
||||
e.g.,
|
||||
```json
|
||||
{
|
||||
"MyDocumentLoader": (
|
||||
"langchain_community.document_loaders.my_document_loader"
|
||||
)
|
||||
}
|
||||
```
|
||||
deprecated_lookups: Same as module look up, but will raise
|
||||
deprecation warnings.
|
||||
fallback_module: Module to import from if the object is not found in
|
||||
`module_lookup` or if `module_lookup` is not provided.
|
||||
|
||||
Returns:
|
||||
A function that imports objects from the specified modules.
|
||||
"""
|
||||
all_module_lookup = {**(deprecated_lookups or {}), **(module_lookup or {})}
|
||||
|
||||
def import_by_name(name: str) -> Any:
|
||||
"""Import stores from `langchain_community`."""
|
||||
# If not in interactive env, raise warning.
|
||||
if all_module_lookup and name in all_module_lookup:
|
||||
new_module = all_module_lookup[name]
|
||||
if new_module.split(".")[0] not in ALLOWED_TOP_LEVEL_PKGS:
|
||||
msg = (
|
||||
f"Importing from {new_module} is not allowed. "
|
||||
f"Allowed top-level packages are: {ALLOWED_TOP_LEVEL_PKGS}"
|
||||
)
|
||||
raise AssertionError(msg)
|
||||
|
||||
try:
|
||||
module = importlib.import_module(new_module)
|
||||
except ModuleNotFoundError as e:
|
||||
if new_module.startswith("langchain_community"):
|
||||
msg = (
|
||||
f"Module {new_module} not found. "
|
||||
"Please install langchain-community to access this module. "
|
||||
"You can install it using `pip install -U langchain-community`"
|
||||
)
|
||||
raise ModuleNotFoundError(msg) from e
|
||||
raise
|
||||
|
||||
try:
|
||||
result = getattr(module, name)
|
||||
if (
|
||||
not is_interactive_env()
|
||||
and deprecated_lookups
|
||||
and name in deprecated_lookups
|
||||
# Depth 3:
|
||||
# -> internal.py
|
||||
# |-> module_import.py
|
||||
# |-> Module in langchain that uses this function
|
||||
# |-> [calling code] whose frame we want to inspect.
|
||||
and not internal.is_caller_internal(depth=3)
|
||||
):
|
||||
warn_deprecated(
|
||||
since="0.1",
|
||||
pending=False,
|
||||
removal="1.0",
|
||||
message=(
|
||||
f"Importing {name} from {package} is deprecated. "
|
||||
f"Please replace deprecated imports:\n\n"
|
||||
f">> from {package} import {name}\n\n"
|
||||
"with new imports of:\n\n"
|
||||
f">> from {new_module} import {name}\n"
|
||||
"You can use the langchain cli to **automatically** "
|
||||
"upgrade many imports. Please see documentation here "
|
||||
"<https://python.langchain.com/docs/versions/v0_2/>"
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
msg = f"module {new_module} has no attribute {name}"
|
||||
raise AttributeError(msg) from e
|
||||
|
||||
return result
|
||||
|
||||
if fallback_module:
|
||||
try:
|
||||
module = importlib.import_module(fallback_module)
|
||||
result = getattr(module, name)
|
||||
if (
|
||||
not is_interactive_env()
|
||||
# Depth 3:
|
||||
# internal.py
|
||||
# |-> module_import.py
|
||||
# |->Module in langchain that uses this function
|
||||
# |-> [calling code] whose frame we want to inspect.
|
||||
and not internal.is_caller_internal(depth=3)
|
||||
):
|
||||
warn_deprecated(
|
||||
since="0.1",
|
||||
pending=False,
|
||||
removal="1.0",
|
||||
message=(
|
||||
f"Importing {name} from {package} is deprecated. "
|
||||
f"Please replace deprecated imports:\n\n"
|
||||
f">> from {package} import {name}\n\n"
|
||||
"with new imports of:\n\n"
|
||||
f">> from {fallback_module} import {name}\n"
|
||||
"You can use the langchain cli to **automatically** "
|
||||
"upgrade many imports. Please see documentation here "
|
||||
"<https://python.langchain.com/docs/versions/v0_2/>"
|
||||
),
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
msg = f"module {fallback_module} has no attribute {name}"
|
||||
raise AttributeError(msg) from e
|
||||
|
||||
return result
|
||||
|
||||
msg = f"module {package} has no attribute {name}"
|
||||
raise AttributeError(msg)
|
||||
|
||||
return import_by_name
|
||||
3
venv/Lib/site-packages/langchain_classic/_api/path.py
Normal file
3
venv/Lib/site-packages/langchain_classic/_api/path.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from langchain_core._api.path import as_import_path, get_relative_path
|
||||
|
||||
__all__ = ["as_import_path", "get_relative_path"]
|
||||
Binary file not shown.
Binary file not shown.
63
venv/Lib/site-packages/langchain_classic/adapters/openai.py
Normal file
63
venv/Lib/site-packages/langchain_classic/adapters/openai.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.adapters.openai import (
|
||||
Chat,
|
||||
ChatCompletion,
|
||||
ChatCompletionChunk,
|
||||
ChatCompletions,
|
||||
Choice,
|
||||
ChoiceChunk,
|
||||
Completions,
|
||||
IndexableBaseModel,
|
||||
chat,
|
||||
convert_dict_to_message,
|
||||
convert_message_to_dict,
|
||||
convert_messages_for_finetuning,
|
||||
convert_openai_messages,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
MODULE_LOOKUP = {
|
||||
"IndexableBaseModel": "langchain_community.adapters.openai",
|
||||
"Choice": "langchain_community.adapters.openai",
|
||||
"ChatCompletions": "langchain_community.adapters.openai",
|
||||
"ChoiceChunk": "langchain_community.adapters.openai",
|
||||
"ChatCompletionChunk": "langchain_community.adapters.openai",
|
||||
"convert_dict_to_message": "langchain_community.adapters.openai",
|
||||
"convert_message_to_dict": "langchain_community.adapters.openai",
|
||||
"convert_openai_messages": "langchain_community.adapters.openai",
|
||||
"ChatCompletion": "langchain_community.adapters.openai",
|
||||
"convert_messages_for_finetuning": "langchain_community.adapters.openai",
|
||||
"Completions": "langchain_community.adapters.openai",
|
||||
"Chat": "langchain_community.adapters.openai",
|
||||
"chat": "langchain_community.adapters.openai",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__file__, deprecated_lookups=MODULE_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"Chat",
|
||||
"ChatCompletion",
|
||||
"ChatCompletionChunk",
|
||||
"ChatCompletions",
|
||||
"Choice",
|
||||
"ChoiceChunk",
|
||||
"Completions",
|
||||
"IndexableBaseModel",
|
||||
"chat",
|
||||
"convert_dict_to_message",
|
||||
"convert_message_to_dict",
|
||||
"convert_messages_for_finetuning",
|
||||
"convert_openai_messages",
|
||||
]
|
||||
164
venv/Lib/site-packages/langchain_classic/agents/__init__.py
Normal file
164
venv/Lib/site-packages/langchain_classic/agents/__init__.py
Normal file
@@ -0,0 +1,164 @@
|
||||
"""**Agent** is a class that uses an LLM to choose a sequence of actions to take.
|
||||
|
||||
In Chains, a sequence of actions is hardcoded. In Agents,
|
||||
a language model is used as a reasoning engine to determine which actions
|
||||
to take and in which order.
|
||||
|
||||
Agents select and use **Tools** and **Toolkits** for actions.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_core._api.path import as_import_path
|
||||
from langchain_core.tools import Tool
|
||||
from langchain_core.tools.convert import tool
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
from langchain_classic.agents.agent import (
|
||||
Agent,
|
||||
AgentExecutor,
|
||||
AgentOutputParser,
|
||||
BaseMultiActionAgent,
|
||||
BaseSingleActionAgent,
|
||||
LLMSingleActionAgent,
|
||||
)
|
||||
from langchain_classic.agents.agent_iterator import AgentExecutorIterator
|
||||
from langchain_classic.agents.agent_toolkits.vectorstore.base import (
|
||||
create_vectorstore_agent,
|
||||
create_vectorstore_router_agent,
|
||||
)
|
||||
from langchain_classic.agents.agent_types import AgentType
|
||||
from langchain_classic.agents.conversational.base import ConversationalAgent
|
||||
from langchain_classic.agents.conversational_chat.base import ConversationalChatAgent
|
||||
from langchain_classic.agents.initialize import initialize_agent
|
||||
from langchain_classic.agents.json_chat.base import create_json_chat_agent
|
||||
from langchain_classic.agents.loading import load_agent
|
||||
from langchain_classic.agents.mrkl.base import MRKLChain, ZeroShotAgent
|
||||
from langchain_classic.agents.openai_functions_agent.base import (
|
||||
OpenAIFunctionsAgent,
|
||||
create_openai_functions_agent,
|
||||
)
|
||||
from langchain_classic.agents.openai_functions_multi_agent.base import (
|
||||
OpenAIMultiFunctionsAgent,
|
||||
)
|
||||
from langchain_classic.agents.openai_tools.base import create_openai_tools_agent
|
||||
from langchain_classic.agents.react.agent import create_react_agent
|
||||
from langchain_classic.agents.react.base import ReActChain, ReActTextWorldAgent
|
||||
from langchain_classic.agents.self_ask_with_search.base import (
|
||||
SelfAskWithSearchChain,
|
||||
create_self_ask_with_search_agent,
|
||||
)
|
||||
from langchain_classic.agents.structured_chat.base import (
|
||||
StructuredChatAgent,
|
||||
create_structured_chat_agent,
|
||||
)
|
||||
from langchain_classic.agents.tool_calling_agent.base import create_tool_calling_agent
|
||||
from langchain_classic.agents.xml.base import XMLAgent, create_xml_agent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.json.base import create_json_agent
|
||||
from langchain_community.agent_toolkits.load_tools import (
|
||||
get_all_tool_names,
|
||||
load_huggingface_tool,
|
||||
load_tools,
|
||||
)
|
||||
from langchain_community.agent_toolkits.openapi.base import create_openapi_agent
|
||||
from langchain_community.agent_toolkits.powerbi.base import create_pbi_agent
|
||||
from langchain_community.agent_toolkits.powerbi.chat_base import (
|
||||
create_pbi_chat_agent,
|
||||
)
|
||||
from langchain_community.agent_toolkits.spark_sql.base import create_spark_sql_agent
|
||||
from langchain_community.agent_toolkits.sql.base import create_sql_agent
|
||||
|
||||
DEPRECATED_CODE = [
|
||||
"create_csv_agent",
|
||||
"create_pandas_dataframe_agent",
|
||||
"create_spark_dataframe_agent",
|
||||
"create_xorbits_agent",
|
||||
]
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"create_json_agent": "langchain_community.agent_toolkits.json.base",
|
||||
"create_openapi_agent": "langchain_community.agent_toolkits.openapi.base",
|
||||
"create_pbi_agent": "langchain_community.agent_toolkits.powerbi.base",
|
||||
"create_pbi_chat_agent": "langchain_community.agent_toolkits.powerbi.chat_base",
|
||||
"create_spark_sql_agent": "langchain_community.agent_toolkits.spark_sql.base",
|
||||
"create_sql_agent": "langchain_community.agent_toolkits.sql.base",
|
||||
"load_tools": "langchain_community.agent_toolkits.load_tools",
|
||||
"load_huggingface_tool": "langchain_community.agent_toolkits.load_tools",
|
||||
"get_all_tool_names": "langchain_community.agent_toolkits.load_tools",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Get attr name."""
|
||||
if name in DEPRECATED_CODE:
|
||||
# Get directory of langchain package
|
||||
here = Path(__file__).parents[1]
|
||||
relative_path = as_import_path(
|
||||
Path(__file__).parent,
|
||||
suffix=name,
|
||||
relative_to=here,
|
||||
)
|
||||
old_path = "langchain_classic." + relative_path
|
||||
new_path = "langchain_experimental." + relative_path
|
||||
msg = (
|
||||
f"{name} has been moved to langchain_experimental. "
|
||||
"See https://github.com/langchain-ai/langchain/discussions/11680"
|
||||
"for more information.\n"
|
||||
f"Please update your import statement from: `{old_path}` to `{new_path}`."
|
||||
)
|
||||
raise ImportError(msg)
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"Agent",
|
||||
"AgentExecutor",
|
||||
"AgentExecutorIterator",
|
||||
"AgentOutputParser",
|
||||
"AgentType",
|
||||
"BaseMultiActionAgent",
|
||||
"BaseSingleActionAgent",
|
||||
"ConversationalAgent",
|
||||
"ConversationalChatAgent",
|
||||
"LLMSingleActionAgent",
|
||||
"MRKLChain",
|
||||
"OpenAIFunctionsAgent",
|
||||
"OpenAIMultiFunctionsAgent",
|
||||
"ReActChain",
|
||||
"ReActTextWorldAgent",
|
||||
"SelfAskWithSearchChain",
|
||||
"StructuredChatAgent",
|
||||
"Tool",
|
||||
"XMLAgent",
|
||||
"ZeroShotAgent",
|
||||
"create_json_agent",
|
||||
"create_json_chat_agent",
|
||||
"create_openai_functions_agent",
|
||||
"create_openai_tools_agent",
|
||||
"create_openapi_agent",
|
||||
"create_pbi_agent",
|
||||
"create_pbi_chat_agent",
|
||||
"create_react_agent",
|
||||
"create_self_ask_with_search_agent",
|
||||
"create_spark_sql_agent",
|
||||
"create_sql_agent",
|
||||
"create_structured_chat_agent",
|
||||
"create_tool_calling_agent",
|
||||
"create_vectorstore_agent",
|
||||
"create_vectorstore_router_agent",
|
||||
"create_xml_agent",
|
||||
"get_all_tool_names",
|
||||
"initialize_agent",
|
||||
"load_agent",
|
||||
"load_huggingface_tool",
|
||||
"load_tools",
|
||||
"tool",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1792
venv/Lib/site-packages/langchain_classic/agents/agent.py
Normal file
1792
venv/Lib/site-packages/langchain_classic/agents/agent.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,432 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import time
|
||||
from collections.abc import AsyncIterator, Iterator
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
)
|
||||
from uuid import UUID
|
||||
|
||||
from langchain_core.agents import (
|
||||
AgentAction,
|
||||
AgentFinish,
|
||||
AgentStep,
|
||||
)
|
||||
from langchain_core.callbacks import (
|
||||
AsyncCallbackManager,
|
||||
AsyncCallbackManagerForChainRun,
|
||||
CallbackManager,
|
||||
CallbackManagerForChainRun,
|
||||
Callbacks,
|
||||
)
|
||||
from langchain_core.load.dump import dumpd
|
||||
from langchain_core.outputs import RunInfo
|
||||
from langchain_core.runnables.utils import AddableDict
|
||||
from langchain_core.tools import BaseTool
|
||||
from langchain_core.utils.input import get_color_mapping
|
||||
|
||||
from langchain_classic.schema import RUN_KEY
|
||||
from langchain_classic.utilities.asyncio import asyncio_timeout
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_classic.agents.agent import AgentExecutor, NextStepOutput
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AgentExecutorIterator:
|
||||
"""Iterator for AgentExecutor."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
agent_executor: AgentExecutor,
|
||||
inputs: Any,
|
||||
callbacks: Callbacks = None,
|
||||
*,
|
||||
tags: list[str] | None = None,
|
||||
metadata: dict[str, Any] | None = None,
|
||||
run_name: str | None = None,
|
||||
run_id: UUID | None = None,
|
||||
include_run_info: bool = False,
|
||||
yield_actions: bool = False,
|
||||
):
|
||||
"""Initialize the `AgentExecutorIterator`.
|
||||
|
||||
Initialize the `AgentExecutorIterator` with the given `AgentExecutor`,
|
||||
inputs, and optional callbacks.
|
||||
|
||||
Args:
|
||||
agent_executor: The `AgentExecutor` to iterate over.
|
||||
inputs: The inputs to the `AgentExecutor`.
|
||||
callbacks: The callbacks to use during iteration.
|
||||
tags: The tags to use during iteration.
|
||||
metadata: The metadata to use during iteration.
|
||||
run_name: The name of the run.
|
||||
run_id: The ID of the run.
|
||||
include_run_info: Whether to include run info in the output.
|
||||
yield_actions: Whether to yield actions as they are generated.
|
||||
"""
|
||||
self._agent_executor = agent_executor
|
||||
self.inputs = inputs
|
||||
self.callbacks = callbacks
|
||||
self.tags = tags
|
||||
self.metadata = metadata
|
||||
self.run_name = run_name
|
||||
self.run_id = run_id
|
||||
self.include_run_info = include_run_info
|
||||
self.yield_actions = yield_actions
|
||||
self.reset()
|
||||
|
||||
_inputs: dict[str, str]
|
||||
callbacks: Callbacks
|
||||
tags: list[str] | None
|
||||
metadata: dict[str, Any] | None
|
||||
run_name: str | None
|
||||
run_id: UUID | None
|
||||
include_run_info: bool
|
||||
yield_actions: bool
|
||||
|
||||
@property
|
||||
def inputs(self) -> dict[str, str]:
|
||||
"""The inputs to the `AgentExecutor`."""
|
||||
return self._inputs
|
||||
|
||||
@inputs.setter
|
||||
def inputs(self, inputs: Any) -> None:
|
||||
self._inputs = self.agent_executor.prep_inputs(inputs)
|
||||
|
||||
@property
|
||||
def agent_executor(self) -> AgentExecutor:
|
||||
"""The `AgentExecutor` to iterate over."""
|
||||
return self._agent_executor
|
||||
|
||||
@agent_executor.setter
|
||||
def agent_executor(self, agent_executor: AgentExecutor) -> None:
|
||||
self._agent_executor = agent_executor
|
||||
# force re-prep inputs in case agent_executor's prep_inputs fn changed
|
||||
self.inputs = self.inputs
|
||||
|
||||
@property
|
||||
def name_to_tool_map(self) -> dict[str, BaseTool]:
|
||||
"""A mapping of tool names to tools."""
|
||||
return {tool.name: tool for tool in self.agent_executor.tools}
|
||||
|
||||
@property
|
||||
def color_mapping(self) -> dict[str, str]:
|
||||
"""A mapping of tool names to colors."""
|
||||
return get_color_mapping(
|
||||
[tool.name for tool in self.agent_executor.tools],
|
||||
excluded_colors=["green", "red"],
|
||||
)
|
||||
|
||||
def reset(self) -> None:
|
||||
"""Reset the iterator to its initial state.
|
||||
|
||||
Reset the iterator to its initial state, clearing intermediate steps,
|
||||
iterations, and time elapsed.
|
||||
"""
|
||||
logger.debug("(Re)setting AgentExecutorIterator to fresh state")
|
||||
self.intermediate_steps: list[tuple[AgentAction, str]] = []
|
||||
self.iterations = 0
|
||||
# maybe better to start these on the first __anext__ call?
|
||||
self.time_elapsed = 0.0
|
||||
self.start_time = time.time()
|
||||
|
||||
def update_iterations(self) -> None:
|
||||
"""Increment the number of iterations and update the time elapsed."""
|
||||
self.iterations += 1
|
||||
self.time_elapsed = time.time() - self.start_time
|
||||
logger.debug(
|
||||
"Agent Iterations: %s (%.2fs elapsed)",
|
||||
self.iterations,
|
||||
self.time_elapsed,
|
||||
)
|
||||
|
||||
def make_final_outputs(
|
||||
self,
|
||||
outputs: dict[str, Any],
|
||||
run_manager: CallbackManagerForChainRun | AsyncCallbackManagerForChainRun,
|
||||
) -> AddableDict:
|
||||
"""Make final outputs for the iterator.
|
||||
|
||||
Args:
|
||||
outputs: The outputs from the agent executor.
|
||||
run_manager: The run manager to use for callbacks.
|
||||
"""
|
||||
# have access to intermediate steps by design in iterator,
|
||||
# so return only outputs may as well always be true.
|
||||
|
||||
prepared_outputs = AddableDict(
|
||||
self.agent_executor.prep_outputs(
|
||||
self.inputs,
|
||||
outputs,
|
||||
return_only_outputs=True,
|
||||
),
|
||||
)
|
||||
if self.include_run_info:
|
||||
prepared_outputs[RUN_KEY] = RunInfo(run_id=run_manager.run_id)
|
||||
return prepared_outputs
|
||||
|
||||
def __iter__(self: AgentExecutorIterator) -> Iterator[AddableDict]:
|
||||
"""Create an async iterator for the `AgentExecutor`."""
|
||||
logger.debug("Initialising AgentExecutorIterator")
|
||||
self.reset()
|
||||
callback_manager = CallbackManager.configure(
|
||||
self.callbacks,
|
||||
self.agent_executor.callbacks,
|
||||
self.agent_executor.verbose,
|
||||
self.tags,
|
||||
self.agent_executor.tags,
|
||||
self.metadata,
|
||||
self.agent_executor.metadata,
|
||||
)
|
||||
run_manager = callback_manager.on_chain_start(
|
||||
dumpd(self.agent_executor),
|
||||
self.inputs,
|
||||
self.run_id,
|
||||
name=self.run_name,
|
||||
)
|
||||
try:
|
||||
while self.agent_executor._should_continue( # noqa: SLF001
|
||||
self.iterations,
|
||||
self.time_elapsed,
|
||||
):
|
||||
# take the next step: this plans next action, executes it,
|
||||
# yielding action and observation as they are generated
|
||||
next_step_seq: NextStepOutput = []
|
||||
for chunk in self.agent_executor._iter_next_step( # noqa: SLF001
|
||||
self.name_to_tool_map,
|
||||
self.color_mapping,
|
||||
self.inputs,
|
||||
self.intermediate_steps,
|
||||
run_manager,
|
||||
):
|
||||
next_step_seq.append(chunk)
|
||||
# if we're yielding actions, yield them as they come
|
||||
# do not yield AgentFinish, which will be handled below
|
||||
if self.yield_actions:
|
||||
if isinstance(chunk, AgentAction):
|
||||
yield AddableDict(actions=[chunk], messages=chunk.messages)
|
||||
elif isinstance(chunk, AgentStep):
|
||||
yield AddableDict(steps=[chunk], messages=chunk.messages)
|
||||
|
||||
# convert iterator output to format handled by _process_next_step_output
|
||||
next_step = self.agent_executor._consume_next_step(next_step_seq) # noqa: SLF001
|
||||
# update iterations and time elapsed
|
||||
self.update_iterations()
|
||||
# decide if this is the final output
|
||||
output = self._process_next_step_output(next_step, run_manager)
|
||||
is_final = "intermediate_step" not in output
|
||||
# yield the final output always
|
||||
# for backwards compat, yield int. output if not yielding actions
|
||||
if not self.yield_actions or is_final:
|
||||
yield output
|
||||
# if final output reached, stop iteration
|
||||
if is_final:
|
||||
return
|
||||
except BaseException as e:
|
||||
run_manager.on_chain_error(e)
|
||||
raise
|
||||
|
||||
# if we got here means we exhausted iterations or time
|
||||
yield self._stop(run_manager)
|
||||
|
||||
async def __aiter__(self) -> AsyncIterator[AddableDict]:
|
||||
"""Create an async iterator for the `AgentExecutor`.
|
||||
|
||||
N.B. __aiter__ must be a normal method, so need to initialize async run manager
|
||||
on first __anext__ call where we can await it.
|
||||
"""
|
||||
logger.debug("Initialising AgentExecutorIterator (async)")
|
||||
self.reset()
|
||||
callback_manager = AsyncCallbackManager.configure(
|
||||
self.callbacks,
|
||||
self.agent_executor.callbacks,
|
||||
self.agent_executor.verbose,
|
||||
self.tags,
|
||||
self.agent_executor.tags,
|
||||
self.metadata,
|
||||
self.agent_executor.metadata,
|
||||
)
|
||||
run_manager = await callback_manager.on_chain_start(
|
||||
dumpd(self.agent_executor),
|
||||
self.inputs,
|
||||
self.run_id,
|
||||
name=self.run_name,
|
||||
)
|
||||
try:
|
||||
async with asyncio_timeout(self.agent_executor.max_execution_time):
|
||||
while self.agent_executor._should_continue( # noqa: SLF001
|
||||
self.iterations,
|
||||
self.time_elapsed,
|
||||
):
|
||||
# take the next step: this plans next action, executes it,
|
||||
# yielding action and observation as they are generated
|
||||
next_step_seq: NextStepOutput = []
|
||||
async for chunk in self.agent_executor._aiter_next_step( # noqa: SLF001
|
||||
self.name_to_tool_map,
|
||||
self.color_mapping,
|
||||
self.inputs,
|
||||
self.intermediate_steps,
|
||||
run_manager,
|
||||
):
|
||||
next_step_seq.append(chunk)
|
||||
# if we're yielding actions, yield them as they come
|
||||
# do not yield AgentFinish, which will be handled below
|
||||
if self.yield_actions:
|
||||
if isinstance(chunk, AgentAction):
|
||||
yield AddableDict(
|
||||
actions=[chunk],
|
||||
messages=chunk.messages,
|
||||
)
|
||||
elif isinstance(chunk, AgentStep):
|
||||
yield AddableDict(
|
||||
steps=[chunk],
|
||||
messages=chunk.messages,
|
||||
)
|
||||
|
||||
# convert iterator output to format handled by _process_next_step
|
||||
next_step = self.agent_executor._consume_next_step(next_step_seq) # noqa: SLF001
|
||||
# update iterations and time elapsed
|
||||
self.update_iterations()
|
||||
# decide if this is the final output
|
||||
output = await self._aprocess_next_step_output(
|
||||
next_step,
|
||||
run_manager,
|
||||
)
|
||||
is_final = "intermediate_step" not in output
|
||||
# yield the final output always
|
||||
# for backwards compat, yield int. output if not yielding actions
|
||||
if not self.yield_actions or is_final:
|
||||
yield output
|
||||
# if final output reached, stop iteration
|
||||
if is_final:
|
||||
return
|
||||
except (TimeoutError, asyncio.TimeoutError):
|
||||
yield await self._astop(run_manager)
|
||||
return
|
||||
except BaseException as e:
|
||||
await run_manager.on_chain_error(e)
|
||||
raise
|
||||
|
||||
# if we got here means we exhausted iterations or time
|
||||
yield await self._astop(run_manager)
|
||||
|
||||
def _process_next_step_output(
|
||||
self,
|
||||
next_step_output: AgentFinish | list[tuple[AgentAction, str]],
|
||||
run_manager: CallbackManagerForChainRun,
|
||||
) -> AddableDict:
|
||||
"""Process the output of the next step.
|
||||
|
||||
Process the output of the next step,
|
||||
handling AgentFinish and tool return cases.
|
||||
"""
|
||||
logger.debug("Processing output of Agent loop step")
|
||||
if isinstance(next_step_output, AgentFinish):
|
||||
logger.debug(
|
||||
"Hit AgentFinish: _return -> on_chain_end -> run final output logic",
|
||||
)
|
||||
return self._return(next_step_output, run_manager=run_manager)
|
||||
|
||||
self.intermediate_steps.extend(next_step_output)
|
||||
logger.debug("Updated intermediate_steps with step output")
|
||||
|
||||
# Check for tool return
|
||||
if len(next_step_output) == 1:
|
||||
next_step_action = next_step_output[0]
|
||||
tool_return = self.agent_executor._get_tool_return(next_step_action) # noqa: SLF001
|
||||
if tool_return is not None:
|
||||
return self._return(tool_return, run_manager=run_manager)
|
||||
|
||||
return AddableDict(intermediate_step=next_step_output)
|
||||
|
||||
async def _aprocess_next_step_output(
|
||||
self,
|
||||
next_step_output: AgentFinish | list[tuple[AgentAction, str]],
|
||||
run_manager: AsyncCallbackManagerForChainRun,
|
||||
) -> AddableDict:
|
||||
"""Process the output of the next async step.
|
||||
|
||||
Process the output of the next async step,
|
||||
handling AgentFinish and tool return cases.
|
||||
"""
|
||||
logger.debug("Processing output of async Agent loop step")
|
||||
if isinstance(next_step_output, AgentFinish):
|
||||
logger.debug(
|
||||
"Hit AgentFinish: _areturn -> on_chain_end -> run final output logic",
|
||||
)
|
||||
return await self._areturn(next_step_output, run_manager=run_manager)
|
||||
|
||||
self.intermediate_steps.extend(next_step_output)
|
||||
logger.debug("Updated intermediate_steps with step output")
|
||||
|
||||
# Check for tool return
|
||||
if len(next_step_output) == 1:
|
||||
next_step_action = next_step_output[0]
|
||||
tool_return = self.agent_executor._get_tool_return(next_step_action) # noqa: SLF001
|
||||
if tool_return is not None:
|
||||
return await self._areturn(tool_return, run_manager=run_manager)
|
||||
|
||||
return AddableDict(intermediate_step=next_step_output)
|
||||
|
||||
def _stop(self, run_manager: CallbackManagerForChainRun) -> AddableDict:
|
||||
"""Stop the iterator.
|
||||
|
||||
Stop the iterator and raise a StopIteration exception with the stopped response.
|
||||
"""
|
||||
logger.warning("Stopping agent prematurely due to triggering stop condition")
|
||||
# this manually constructs agent finish with output key
|
||||
output = self.agent_executor._action_agent.return_stopped_response( # noqa: SLF001
|
||||
self.agent_executor.early_stopping_method,
|
||||
self.intermediate_steps,
|
||||
**self.inputs,
|
||||
)
|
||||
return self._return(output, run_manager=run_manager)
|
||||
|
||||
async def _astop(self, run_manager: AsyncCallbackManagerForChainRun) -> AddableDict:
|
||||
"""Stop the async iterator.
|
||||
|
||||
Stop the async iterator and raise a StopAsyncIteration exception with
|
||||
the stopped response.
|
||||
"""
|
||||
logger.warning("Stopping agent prematurely due to triggering stop condition")
|
||||
output = self.agent_executor._action_agent.return_stopped_response( # noqa: SLF001
|
||||
self.agent_executor.early_stopping_method,
|
||||
self.intermediate_steps,
|
||||
**self.inputs,
|
||||
)
|
||||
return await self._areturn(output, run_manager=run_manager)
|
||||
|
||||
def _return(
|
||||
self,
|
||||
output: AgentFinish,
|
||||
run_manager: CallbackManagerForChainRun,
|
||||
) -> AddableDict:
|
||||
"""Return the final output of the iterator."""
|
||||
returned_output = self.agent_executor._return( # noqa: SLF001
|
||||
output,
|
||||
self.intermediate_steps,
|
||||
run_manager=run_manager,
|
||||
)
|
||||
returned_output["messages"] = output.messages
|
||||
run_manager.on_chain_end(returned_output)
|
||||
return self.make_final_outputs(returned_output, run_manager)
|
||||
|
||||
async def _areturn(
|
||||
self,
|
||||
output: AgentFinish,
|
||||
run_manager: AsyncCallbackManagerForChainRun,
|
||||
) -> AddableDict:
|
||||
"""Return the final output of the async iterator."""
|
||||
returned_output = await self.agent_executor._areturn( # noqa: SLF001
|
||||
output,
|
||||
self.intermediate_steps,
|
||||
run_manager=run_manager,
|
||||
)
|
||||
returned_output["messages"] = output.messages
|
||||
await run_manager.on_chain_end(returned_output)
|
||||
return self.make_final_outputs(returned_output, run_manager)
|
||||
@@ -0,0 +1,167 @@
|
||||
"""Agent toolkits contain integrations with various resources and services.
|
||||
|
||||
LangChain has a large ecosystem of integrations with various external resources
|
||||
like local and remote file systems, APIs and databases.
|
||||
|
||||
These integrations allow developers to create versatile applications that combine the
|
||||
power of LLMs with the ability to access, interact with and manipulate external
|
||||
resources.
|
||||
|
||||
When developing an application, developers should inspect the capabilities and
|
||||
permissions of the tools that underlie the given agent toolkit, and determine
|
||||
whether permissions of the given toolkit are appropriate for the application.
|
||||
|
||||
See https://docs.langchain.com/oss/python/security-policy for more information.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_core._api.path import as_import_path
|
||||
from langchain_core.tools.retriever import create_retriever_tool
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
from langchain_classic.agents.agent_toolkits.conversational_retrieval.openai_functions import ( # noqa: E501
|
||||
create_conversational_retrieval_agent,
|
||||
)
|
||||
from langchain_classic.agents.agent_toolkits.vectorstore.base import (
|
||||
create_vectorstore_agent,
|
||||
create_vectorstore_router_agent,
|
||||
)
|
||||
from langchain_classic.agents.agent_toolkits.vectorstore.toolkit import (
|
||||
VectorStoreInfo,
|
||||
VectorStoreRouterToolkit,
|
||||
VectorStoreToolkit,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.ainetwork.toolkit import AINetworkToolkit
|
||||
from langchain_community.agent_toolkits.amadeus.toolkit import AmadeusToolkit
|
||||
from langchain_community.agent_toolkits.azure_cognitive_services import (
|
||||
AzureCognitiveServicesToolkit,
|
||||
)
|
||||
from langchain_community.agent_toolkits.file_management.toolkit import (
|
||||
FileManagementToolkit,
|
||||
)
|
||||
from langchain_community.agent_toolkits.gmail.toolkit import GmailToolkit
|
||||
from langchain_community.agent_toolkits.jira.toolkit import JiraToolkit
|
||||
from langchain_community.agent_toolkits.json.base import create_json_agent
|
||||
from langchain_community.agent_toolkits.json.toolkit import JsonToolkit
|
||||
from langchain_community.agent_toolkits.multion.toolkit import MultionToolkit
|
||||
from langchain_community.agent_toolkits.nasa.toolkit import NasaToolkit
|
||||
from langchain_community.agent_toolkits.nla.toolkit import NLAToolkit
|
||||
from langchain_community.agent_toolkits.office365.toolkit import O365Toolkit
|
||||
from langchain_community.agent_toolkits.openapi.base import create_openapi_agent
|
||||
from langchain_community.agent_toolkits.openapi.toolkit import OpenAPIToolkit
|
||||
from langchain_community.agent_toolkits.playwright.toolkit import (
|
||||
PlayWrightBrowserToolkit,
|
||||
)
|
||||
from langchain_community.agent_toolkits.powerbi.base import create_pbi_agent
|
||||
from langchain_community.agent_toolkits.powerbi.chat_base import (
|
||||
create_pbi_chat_agent,
|
||||
)
|
||||
from langchain_community.agent_toolkits.powerbi.toolkit import PowerBIToolkit
|
||||
from langchain_community.agent_toolkits.slack.toolkit import SlackToolkit
|
||||
from langchain_community.agent_toolkits.spark_sql.base import create_spark_sql_agent
|
||||
from langchain_community.agent_toolkits.spark_sql.toolkit import SparkSQLToolkit
|
||||
from langchain_community.agent_toolkits.sql.base import create_sql_agent
|
||||
from langchain_community.agent_toolkits.sql.toolkit import SQLDatabaseToolkit
|
||||
from langchain_community.agent_toolkits.steam.toolkit import SteamToolkit
|
||||
from langchain_community.agent_toolkits.zapier.toolkit import ZapierToolkit
|
||||
|
||||
DEPRECATED_AGENTS = [
|
||||
"create_csv_agent",
|
||||
"create_pandas_dataframe_agent",
|
||||
"create_xorbits_agent",
|
||||
"create_python_agent",
|
||||
"create_spark_dataframe_agent",
|
||||
]
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"AINetworkToolkit": "langchain_community.agent_toolkits.ainetwork.toolkit",
|
||||
"AmadeusToolkit": "langchain_community.agent_toolkits.amadeus.toolkit",
|
||||
"AzureCognitiveServicesToolkit": (
|
||||
"langchain_community.agent_toolkits.azure_cognitive_services"
|
||||
),
|
||||
"FileManagementToolkit": (
|
||||
"langchain_community.agent_toolkits.file_management.toolkit"
|
||||
),
|
||||
"GmailToolkit": "langchain_community.agent_toolkits.gmail.toolkit",
|
||||
"JiraToolkit": "langchain_community.agent_toolkits.jira.toolkit",
|
||||
"JsonToolkit": "langchain_community.agent_toolkits.json.toolkit",
|
||||
"MultionToolkit": "langchain_community.agent_toolkits.multion.toolkit",
|
||||
"NasaToolkit": "langchain_community.agent_toolkits.nasa.toolkit",
|
||||
"NLAToolkit": "langchain_community.agent_toolkits.nla.toolkit",
|
||||
"O365Toolkit": "langchain_community.agent_toolkits.office365.toolkit",
|
||||
"OpenAPIToolkit": "langchain_community.agent_toolkits.openapi.toolkit",
|
||||
"PlayWrightBrowserToolkit": "langchain_community.agent_toolkits.playwright.toolkit",
|
||||
"PowerBIToolkit": "langchain_community.agent_toolkits.powerbi.toolkit",
|
||||
"SlackToolkit": "langchain_community.agent_toolkits.slack.toolkit",
|
||||
"SteamToolkit": "langchain_community.agent_toolkits.steam.toolkit",
|
||||
"SQLDatabaseToolkit": "langchain_community.agent_toolkits.sql.toolkit",
|
||||
"SparkSQLToolkit": "langchain_community.agent_toolkits.spark_sql.toolkit",
|
||||
"ZapierToolkit": "langchain_community.agent_toolkits.zapier.toolkit",
|
||||
"create_json_agent": "langchain_community.agent_toolkits.json.base",
|
||||
"create_openapi_agent": "langchain_community.agent_toolkits.openapi.base",
|
||||
"create_pbi_agent": "langchain_community.agent_toolkits.powerbi.base",
|
||||
"create_pbi_chat_agent": "langchain_community.agent_toolkits.powerbi.chat_base",
|
||||
"create_spark_sql_agent": "langchain_community.agent_toolkits.spark_sql.base",
|
||||
"create_sql_agent": "langchain_community.agent_toolkits.sql.base",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Get attr name."""
|
||||
if name in DEPRECATED_AGENTS:
|
||||
relative_path = as_import_path(Path(__file__).parent, suffix=name)
|
||||
old_path = "langchain_classic." + relative_path
|
||||
new_path = "langchain_experimental." + relative_path
|
||||
msg = (
|
||||
f"{name} has been moved to langchain_experimental. "
|
||||
"See https://github.com/langchain-ai/langchain/discussions/11680"
|
||||
"for more information.\n"
|
||||
f"Please update your import statement from: `{old_path}` to `{new_path}`."
|
||||
)
|
||||
raise ImportError(msg)
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"AINetworkToolkit",
|
||||
"AmadeusToolkit",
|
||||
"AzureCognitiveServicesToolkit",
|
||||
"FileManagementToolkit",
|
||||
"GmailToolkit",
|
||||
"JiraToolkit",
|
||||
"JsonToolkit",
|
||||
"MultionToolkit",
|
||||
"NLAToolkit",
|
||||
"NasaToolkit",
|
||||
"O365Toolkit",
|
||||
"OpenAPIToolkit",
|
||||
"PlayWrightBrowserToolkit",
|
||||
"PowerBIToolkit",
|
||||
"SQLDatabaseToolkit",
|
||||
"SlackToolkit",
|
||||
"SparkSQLToolkit",
|
||||
"SteamToolkit",
|
||||
"VectorStoreInfo",
|
||||
"VectorStoreRouterToolkit",
|
||||
"VectorStoreToolkit",
|
||||
"ZapierToolkit",
|
||||
"create_conversational_retrieval_agent",
|
||||
"create_json_agent",
|
||||
"create_openapi_agent",
|
||||
"create_pbi_agent",
|
||||
"create_pbi_chat_agent",
|
||||
"create_retriever_tool",
|
||||
"create_spark_sql_agent",
|
||||
"create_sql_agent",
|
||||
"create_vectorstore_agent",
|
||||
"create_vectorstore_router_agent",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
"""AINetwork toolkit."""
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.ainetwork.toolkit import AINetworkToolkit
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"AINetworkToolkit": "langchain_community.agent_toolkits.ainetwork.toolkit",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"AINetworkToolkit",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.amadeus.toolkit import AmadeusToolkit
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"AmadeusToolkit": "langchain_community.agent_toolkits.amadeus.toolkit",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = ["AmadeusToolkit"]
|
||||
@@ -0,0 +1,29 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.azure_cognitive_services import (
|
||||
AzureCognitiveServicesToolkit,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"AzureCognitiveServicesToolkit": (
|
||||
"langchain_community.agent_toolkits.azure_cognitive_services"
|
||||
),
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"AzureCognitiveServicesToolkit",
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
from langchain_core.tools import BaseToolkit
|
||||
|
||||
__all__ = ["BaseToolkit"]
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.clickup.toolkit import ClickupToolkit
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"ClickupToolkit": "langchain_community.agent_toolkits.clickup.toolkit",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"ClickupToolkit",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,85 @@
|
||||
from typing import Any
|
||||
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.messages import SystemMessage
|
||||
from langchain_core.prompts.chat import MessagesPlaceholder
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
from langchain_classic.agents.agent import AgentExecutor
|
||||
from langchain_classic.agents.openai_functions_agent.agent_token_buffer_memory import (
|
||||
AgentTokenBufferMemory,
|
||||
)
|
||||
from langchain_classic.agents.openai_functions_agent.base import OpenAIFunctionsAgent
|
||||
from langchain_classic.base_memory import BaseMemory
|
||||
from langchain_classic.memory.token_buffer import ConversationTokenBufferMemory
|
||||
|
||||
|
||||
def _get_default_system_message() -> SystemMessage:
|
||||
return SystemMessage(
|
||||
content=(
|
||||
"Do your best to answer the questions. "
|
||||
"Feel free to use any tools available to look up "
|
||||
"relevant information, only if necessary"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def create_conversational_retrieval_agent(
|
||||
llm: BaseLanguageModel,
|
||||
tools: list[BaseTool],
|
||||
remember_intermediate_steps: bool = True, # noqa: FBT001,FBT002
|
||||
memory_key: str = "chat_history",
|
||||
system_message: SystemMessage | None = None,
|
||||
verbose: bool = False, # noqa: FBT001,FBT002
|
||||
max_token_limit: int = 2000,
|
||||
**kwargs: Any,
|
||||
) -> AgentExecutor:
|
||||
"""A convenience method for creating a conversational retrieval agent.
|
||||
|
||||
Args:
|
||||
llm: The language model to use, should be `ChatOpenAI`
|
||||
tools: A list of tools the agent has access to
|
||||
remember_intermediate_steps: Whether the agent should remember intermediate
|
||||
steps or not. Intermediate steps refer to prior action/observation
|
||||
pairs from previous questions. The benefit of remembering these is if
|
||||
there is relevant information in there, the agent can use it to answer
|
||||
follow up questions. The downside is it will take up more tokens.
|
||||
memory_key: The name of the memory key in the prompt.
|
||||
system_message: The system message to use. By default, a basic one will
|
||||
be used.
|
||||
verbose: Whether or not the final AgentExecutor should be verbose or not.
|
||||
max_token_limit: The max number of tokens to keep around in memory.
|
||||
**kwargs: Additional keyword arguments to pass to the `AgentExecutor`.
|
||||
|
||||
Returns:
|
||||
An agent executor initialized appropriately
|
||||
"""
|
||||
if remember_intermediate_steps:
|
||||
memory: BaseMemory = AgentTokenBufferMemory(
|
||||
memory_key=memory_key,
|
||||
llm=llm,
|
||||
max_token_limit=max_token_limit,
|
||||
)
|
||||
else:
|
||||
memory = ConversationTokenBufferMemory(
|
||||
memory_key=memory_key,
|
||||
return_messages=True,
|
||||
output_key="output",
|
||||
llm=llm,
|
||||
max_token_limit=max_token_limit,
|
||||
)
|
||||
|
||||
_system_message = system_message or _get_default_system_message()
|
||||
prompt = OpenAIFunctionsAgent.create_prompt(
|
||||
system_message=_system_message,
|
||||
extra_prompt_messages=[MessagesPlaceholder(variable_name=memory_key)],
|
||||
)
|
||||
agent = OpenAIFunctionsAgent(llm=llm, tools=tools, prompt=prompt)
|
||||
return AgentExecutor(
|
||||
agent=agent,
|
||||
tools=tools,
|
||||
memory=memory,
|
||||
verbose=verbose,
|
||||
return_intermediate_steps=remember_intermediate_steps,
|
||||
**kwargs,
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
from langchain_classic.tools.retriever import create_retriever_tool
|
||||
|
||||
__all__ = ["create_retriever_tool"]
|
||||
@@ -0,0 +1,20 @@
|
||||
from typing import Any
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Get attr name."""
|
||||
if name == "create_csv_agent":
|
||||
msg = (
|
||||
"This agent has been moved to langchain_experimental. "
|
||||
"This agent relies on python REPL tool under the hood, so to use it "
|
||||
"safely please sandbox the python REPL. "
|
||||
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md "
|
||||
"and https://github.com/langchain-ai/langchain/discussions/11680"
|
||||
"To keep using this code as is, install langchain_experimental and "
|
||||
"update your import statement from:\n "
|
||||
f"`langchain_classic.agents.agent_toolkits.csv.{name}` to "
|
||||
f"`langchain_experimental.agents.agent_toolkits.{name}`."
|
||||
)
|
||||
raise ImportError(msg)
|
||||
msg = f"{name} does not exist"
|
||||
raise AttributeError(msg)
|
||||
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
"""Local file management toolkit."""
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.file_management.toolkit import (
|
||||
FileManagementToolkit,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"FileManagementToolkit": (
|
||||
"langchain_community.agent_toolkits.file_management.toolkit"
|
||||
),
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"FileManagementToolkit",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,29 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.file_management.toolkit import (
|
||||
FileManagementToolkit,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"FileManagementToolkit": (
|
||||
"langchain_community.agent_toolkits.file_management.toolkit"
|
||||
),
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"FileManagementToolkit",
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
"""GitHub Toolkit."""
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,69 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.github.toolkit import (
|
||||
BranchName,
|
||||
CommentOnIssue,
|
||||
CreateFile,
|
||||
CreatePR,
|
||||
CreateReviewRequest,
|
||||
DeleteFile,
|
||||
DirectoryPath,
|
||||
GetIssue,
|
||||
GetPR,
|
||||
GitHubToolkit,
|
||||
NoInput,
|
||||
ReadFile,
|
||||
SearchCode,
|
||||
SearchIssuesAndPRs,
|
||||
UpdateFile,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"NoInput": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"GetIssue": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"CommentOnIssue": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"GetPR": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"CreatePR": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"CreateFile": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"ReadFile": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"UpdateFile": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"DeleteFile": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"DirectoryPath": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"BranchName": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"SearchCode": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"CreateReviewRequest": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"SearchIssuesAndPRs": "langchain_community.agent_toolkits.github.toolkit",
|
||||
"GitHubToolkit": "langchain_community.agent_toolkits.github.toolkit",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"BranchName",
|
||||
"CommentOnIssue",
|
||||
"CreateFile",
|
||||
"CreatePR",
|
||||
"CreateReviewRequest",
|
||||
"DeleteFile",
|
||||
"DirectoryPath",
|
||||
"GetIssue",
|
||||
"GetPR",
|
||||
"GitHubToolkit",
|
||||
"NoInput",
|
||||
"ReadFile",
|
||||
"SearchCode",
|
||||
"SearchIssuesAndPRs",
|
||||
"UpdateFile",
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
"""GitLab Toolkit."""
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.gitlab.toolkit import GitLabToolkit
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"GitLabToolkit": "langchain_community.agent_toolkits.gitlab.toolkit",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"GitLabToolkit",
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
"""Gmail toolkit."""
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.gmail.toolkit import GmailToolkit
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {"GmailToolkit": "langchain_community.agent_toolkits.gmail.toolkit"}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"GmailToolkit",
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
"""Jira Toolkit."""
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.jira.toolkit import JiraToolkit
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {"JiraToolkit": "langchain_community.agent_toolkits.jira.toolkit"}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"JiraToolkit",
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
"""Json agent."""
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.json.base import create_json_agent
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"create_json_agent": "langchain_community.agent_toolkits.json.base",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"create_json_agent",
|
||||
]
|
||||
@@ -0,0 +1,24 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.json.prompt import JSON_PREFIX, JSON_SUFFIX
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"JSON_PREFIX": "langchain_community.agent_toolkits.json.prompt",
|
||||
"JSON_SUFFIX": "langchain_community.agent_toolkits.json.prompt",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = ["JSON_PREFIX", "JSON_SUFFIX"]
|
||||
@@ -0,0 +1,23 @@
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_classic._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.json.toolkit import JsonToolkit
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {"JsonToolkit": "langchain_community.agent_toolkits.json.toolkit"}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"JsonToolkit",
|
||||
]
|
||||
@@ -0,0 +1 @@
|
||||
"""MultiOn Toolkit."""
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user