mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-30 10:23:30 +00:00
langchain[patch]: Update some agent tool kits to handle community import as optional (#21157)
A few things that were not caught by the migration script
This commit is contained in:
parent
59f10ab3e0
commit
43110daea5
@ -1,3 +1,23 @@
|
||||
from langchain_community.agent_toolkits.amadeus.toolkit import AmadeusToolkit
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain._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"]
|
||||
|
@ -1,3 +1,24 @@
|
||||
from langchain_community.agent_toolkits.json.prompt import JSON_PREFIX, JSON_SUFFIX
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain._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"]
|
||||
|
@ -1,22 +1,86 @@
|
||||
from langchain_community.agent_toolkits.openapi.planner_prompt import (
|
||||
API_CONTROLLER_PROMPT,
|
||||
API_CONTROLLER_TOOL_DESCRIPTION,
|
||||
API_CONTROLLER_TOOL_NAME,
|
||||
API_ORCHESTRATOR_PROMPT,
|
||||
API_PLANNER_PROMPT,
|
||||
API_PLANNER_TOOL_DESCRIPTION,
|
||||
API_PLANNER_TOOL_NAME,
|
||||
PARSING_DELETE_PROMPT,
|
||||
PARSING_GET_PROMPT,
|
||||
PARSING_PATCH_PROMPT,
|
||||
PARSING_POST_PROMPT,
|
||||
PARSING_PUT_PROMPT,
|
||||
REQUESTS_DELETE_TOOL_DESCRIPTION,
|
||||
REQUESTS_GET_TOOL_DESCRIPTION,
|
||||
REQUESTS_PATCH_TOOL_DESCRIPTION,
|
||||
REQUESTS_POST_TOOL_DESCRIPTION,
|
||||
REQUESTS_PUT_TOOL_DESCRIPTION,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.openapi.planner_prompt import (
|
||||
API_CONTROLLER_PROMPT,
|
||||
API_CONTROLLER_TOOL_DESCRIPTION,
|
||||
API_CONTROLLER_TOOL_NAME,
|
||||
API_ORCHESTRATOR_PROMPT,
|
||||
API_PLANNER_PROMPT,
|
||||
API_PLANNER_TOOL_DESCRIPTION,
|
||||
API_PLANNER_TOOL_NAME,
|
||||
PARSING_DELETE_PROMPT,
|
||||
PARSING_GET_PROMPT,
|
||||
PARSING_PATCH_PROMPT,
|
||||
PARSING_POST_PROMPT,
|
||||
PARSING_PUT_PROMPT,
|
||||
REQUESTS_DELETE_TOOL_DESCRIPTION,
|
||||
REQUESTS_GET_TOOL_DESCRIPTION,
|
||||
REQUESTS_PATCH_TOOL_DESCRIPTION,
|
||||
REQUESTS_POST_TOOL_DESCRIPTION,
|
||||
REQUESTS_PUT_TOOL_DESCRIPTION,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"API_CONTROLLER_PROMPT": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"API_CONTROLLER_TOOL_DESCRIPTION": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"API_CONTROLLER_TOOL_NAME": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"API_ORCHESTRATOR_PROMPT": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"API_PLANNER_PROMPT": ("langchain_community.agent_toolkits.openapi.planner_prompt"),
|
||||
"API_PLANNER_TOOL_DESCRIPTION": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"API_PLANNER_TOOL_NAME": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"PARSING_DELETE_PROMPT": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"PARSING_GET_PROMPT": ("langchain_community.agent_toolkits.openapi.planner_prompt"),
|
||||
"PARSING_PATCH_PROMPT": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"PARSING_POST_PROMPT": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"PARSING_PUT_PROMPT": ("langchain_community.agent_toolkits.openapi.planner_prompt"),
|
||||
"REQUESTS_DELETE_TOOL_DESCRIPTION": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"REQUESTS_GET_TOOL_DESCRIPTION": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"REQUESTS_PATCH_TOOL_DESCRIPTION": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"REQUESTS_POST_TOOL_DESCRIPTION": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
"REQUESTS_PUT_TOOL_DESCRIPTION": (
|
||||
"langchain_community.agent_toolkits.openapi.planner_prompt"
|
||||
),
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"API_PLANNER_PROMPT",
|
||||
|
@ -1,7 +1,29 @@
|
||||
from langchain_community.agent_toolkits.openapi.prompt import (
|
||||
DESCRIPTION,
|
||||
OPENAPI_PREFIX,
|
||||
OPENAPI_SUFFIX,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.openapi.prompt import (
|
||||
DESCRIPTION,
|
||||
OPENAPI_PREFIX,
|
||||
OPENAPI_SUFFIX,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"DESCRIPTION": "langchain_community.agent_toolkits.openapi.prompt",
|
||||
"OPENAPI_PREFIX": "langchain_community.agent_toolkits.openapi.prompt",
|
||||
"OPENAPI_SUFFIX": "langchain_community.agent_toolkits.openapi.prompt",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = ["OPENAPI_PREFIX", "OPENAPI_SUFFIX", "DESCRIPTION"]
|
||||
|
@ -1,9 +1,32 @@
|
||||
from langchain_community.agent_toolkits.powerbi.prompt import (
|
||||
POWERBI_CHAT_PREFIX,
|
||||
POWERBI_CHAT_SUFFIX,
|
||||
POWERBI_PREFIX,
|
||||
POWERBI_SUFFIX,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.powerbi.prompt import (
|
||||
POWERBI_CHAT_PREFIX,
|
||||
POWERBI_CHAT_SUFFIX,
|
||||
POWERBI_PREFIX,
|
||||
POWERBI_SUFFIX,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"POWERBI_CHAT_PREFIX": "langchain_community.agent_toolkits.powerbi.prompt",
|
||||
"POWERBI_CHAT_SUFFIX": "langchain_community.agent_toolkits.powerbi.prompt",
|
||||
"POWERBI_PREFIX": "langchain_community.agent_toolkits.powerbi.prompt",
|
||||
"POWERBI_SUFFIX": "langchain_community.agent_toolkits.powerbi.prompt",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"POWERBI_PREFIX",
|
||||
|
@ -1,3 +1,27 @@
|
||||
from langchain_community.agent_toolkits.spark_sql.prompt import SQL_PREFIX, SQL_SUFFIX
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.spark_sql.prompt import (
|
||||
SQL_PREFIX,
|
||||
SQL_SUFFIX,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"SQL_PREFIX": "langchain_community.agent_toolkits.spark_sql.prompt",
|
||||
"SQL_SUFFIX": "langchain_community.agent_toolkits.spark_sql.prompt",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = ["SQL_PREFIX", "SQL_SUFFIX"]
|
||||
|
@ -1,7 +1,29 @@
|
||||
from langchain_community.agent_toolkits.sql.prompt import (
|
||||
SQL_FUNCTIONS_SUFFIX,
|
||||
SQL_PREFIX,
|
||||
SQL_SUFFIX,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.agent_toolkits.sql.prompt import (
|
||||
SQL_FUNCTIONS_SUFFIX,
|
||||
SQL_PREFIX,
|
||||
SQL_SUFFIX,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"SQL_PREFIX": "langchain_community.agent_toolkits.sql.prompt",
|
||||
"SQL_SUFFIX": "langchain_community.agent_toolkits.sql.prompt",
|
||||
"SQL_FUNCTIONS_SUFFIX": "langchain_community.agent_toolkits.sql.prompt",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = ["SQL_PREFIX", "SQL_SUFFIX", "SQL_FUNCTIONS_SUFFIX"]
|
||||
|
@ -1,10 +1,6 @@
|
||||
"""Toolkit for interacting with a vector store."""
|
||||
from typing import List
|
||||
|
||||
from langchain_community.tools.vectorstore.tool import (
|
||||
VectorStoreQATool,
|
||||
VectorStoreQAWithSourcesTool,
|
||||
)
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.pydantic_v1 import BaseModel, Field
|
||||
from langchain_core.tools import BaseTool, BaseToolkit
|
||||
@ -37,6 +33,15 @@ class VectorStoreToolkit(BaseToolkit):
|
||||
|
||||
def get_tools(self) -> List[BaseTool]:
|
||||
"""Get the tools in the toolkit."""
|
||||
try:
|
||||
from langchain_community.tools.vectorstore.tool import (
|
||||
VectorStoreQATool,
|
||||
VectorStoreQAWithSourcesTool,
|
||||
)
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"You need to install langchain-community to use this toolkit."
|
||||
)
|
||||
description = VectorStoreQATool.get_description(
|
||||
self.vectorstore_info.name, self.vectorstore_info.description
|
||||
)
|
||||
@ -72,6 +77,14 @@ class VectorStoreRouterToolkit(BaseToolkit):
|
||||
def get_tools(self) -> List[BaseTool]:
|
||||
"""Get the tools in the toolkit."""
|
||||
tools: List[BaseTool] = []
|
||||
try:
|
||||
from langchain_community.tools.vectorstore.tool import (
|
||||
VectorStoreQATool,
|
||||
)
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"You need to install langchain-community to use this toolkit."
|
||||
)
|
||||
for vectorstore_info in self.vectorstores:
|
||||
description = VectorStoreQATool.get_description(
|
||||
vectorstore_info.name, vectorstore_info.description
|
||||
|
Loading…
Reference in New Issue
Block a user