Skip to content

Commit

Permalink
Merge branch 'v0.3rc' into v0.3/dev_releases
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme committed Sep 5, 2024
2 parents f3b12f8 + 5bbd536 commit 4200876
Show file tree
Hide file tree
Showing 589 changed files with 2,530 additions and 2,418 deletions.
3 changes: 1 addition & 2 deletions libs/community/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ integration_tests:
poetry run pytest $(TEST_FILE)

test_watch:
poetry run ptw --disable-socket --allow-unix-socket --snapshot-update --now . -- -vv -x tests/unit_tests
poetry run ptw --disable-socket --allow-unix-socket --snapshot-update --now . -- -vv tests/unit_tests

check_imports: $(shell find langchain_community -name '*.py')
poetry run python ./scripts/check_imports.py $^
Expand All @@ -45,7 +45,6 @@ lint_tests: PYTHON_FILES=tests
lint_tests: MYPY_CACHE=.mypy_cache_test

lint lint_diff lint_package lint_tests:
./scripts/check_pydantic.sh .
./scripts/lint_imports.sh .
./scripts/check_pickle.sh .
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff check $(PYTHON_FILES)
Expand Down
2 changes: 1 addition & 1 deletion libs/community/langchain_community/adapters/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
SystemMessage,
ToolMessage,
)
from langchain_core.pydantic_v1 import BaseModel
from pydantic import BaseModel
from typing_extensions import Literal


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

from typing import TYPE_CHECKING, List, Literal, Optional
from typing import TYPE_CHECKING, Any, List, Literal, Optional

from langchain_core.pydantic_v1 import root_validator
from langchain_core.tools import BaseTool
from langchain_core.tools.base import BaseToolkit
from pydantic import ConfigDict, model_validator

from langchain_community.tools.ainetwork.app import AINAppOps
from langchain_community.tools.ainetwork.owner import AINOwnerOps
Expand Down Expand Up @@ -36,8 +36,9 @@ class AINetworkToolkit(BaseToolkit):
network: Optional[Literal["mainnet", "testnet"]] = "testnet"
interface: Optional[Ain] = None

@root_validator(pre=True)
def set_interface(cls, values: dict) -> dict:
@model_validator(mode="before")
@classmethod
def set_interface(cls, values: dict) -> Any:
"""Set the interface if not provided.
If the interface is not provided, attempt to authenticate with the
Expand All @@ -53,9 +54,10 @@ def set_interface(cls, values: dict) -> dict:
values["interface"] = authenticate(network=values.get("network", "testnet"))
return values

class Config:
arbitrary_types_allowed = True
validate_all = True
model_config = ConfigDict(
arbitrary_types_allowed=True,
validate_default=True,
)

def get_tools(self) -> List[BaseTool]:
"""Get the tools in the toolkit."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from typing import TYPE_CHECKING, List, Optional

from langchain_core.language_models import BaseLanguageModel
from langchain_core.pydantic_v1 import Field
from langchain_core.tools import BaseTool
from langchain_core.tools.base import BaseToolkit
from pydantic import ConfigDict, Field

from langchain_community.tools.amadeus.closest_airport import AmadeusClosestAirport
from langchain_community.tools.amadeus.flight_search import AmadeusFlightSearch
Expand All @@ -26,8 +26,9 @@ class AmadeusToolkit(BaseToolkit):
client: Client = Field(default_factory=authenticate)
llm: Optional[BaseLanguageModel] = Field(default=None)

class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(
arbitrary_types_allowed=True,
)

def get_tools(self) -> List[BaseTool]:
"""Get the tools in the toolkit."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import List

from langchain_core.pydantic_v1 import Field
from langchain_core.tools import BaseTool
from langchain_core.tools.base import BaseToolkit
from pydantic import ConfigDict, Field

from langchain_community.tools.cassandra_database.tool import (
GetSchemaCassandraDatabaseTool,
Expand All @@ -24,8 +24,9 @@ class CassandraDatabaseToolkit(BaseToolkit):

db: CassandraDatabase = Field(exclude=True)

class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(
arbitrary_types_allowed=True,
)

def get_tools(self) -> List[BaseTool]:
"""Get the tools in the toolkit."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import List
from typing import Any, List

from langchain_core.pydantic_v1 import root_validator
from langchain_core.tools import BaseTool
from langchain_core.tools.base import BaseToolkit
from pydantic import model_validator

from langchain_community.tools.connery import ConneryService

Expand All @@ -23,8 +23,9 @@ def get_tools(self) -> List[BaseTool]:
"""
return self.tools

@root_validator(pre=True)
def validate_attributes(cls, values: dict) -> dict:
@model_validator(mode="before")
@classmethod
def validate_attributes(cls, values: dict) -> Any:
"""
Validate the attributes of the ConneryToolkit class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

from typing import Dict, List, Optional, Type
from typing import Any, Dict, List, Optional, Type

from langchain_core.pydantic_v1 import root_validator
from langchain_core.tools import BaseTool, BaseToolkit
from langchain_core.utils.pydantic import get_fields
from pydantic import model_validator

from langchain_community.tools.file_management.copy import CopyFileTool
from langchain_community.tools.file_management.delete import DeleteFileTool
Expand Down Expand Up @@ -63,8 +63,9 @@ class FileManagementToolkit(BaseToolkit):
selected_tools: Optional[List[str]] = None
"""If provided, only provide the selected tools. Defaults to all."""

@root_validator(pre=True)
def validate_tools(cls, values: dict) -> dict:
@model_validator(mode="before")
@classmethod
def validate_tools(cls, values: dict) -> Any:
selected_tools = values.get("selected_tools") or []
for tool_name in selected_tools:
if tool_name not in _FILE_TOOLS_MAP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import List

from langchain_core.pydantic_v1 import Field
from langchain_core.tools import BaseTool
from langchain_core.tools.base import BaseToolkit
from pydantic import ConfigDict, Field

from langchain_community.tools.financial_datasets.balance_sheets import BalanceSheets
from langchain_community.tools.financial_datasets.cash_flow_statements import (
Expand All @@ -31,8 +31,9 @@ def __init__(self, api_wrapper: FinancialDatasetsAPIWrapper):
super().__init__()
self.api_wrapper = api_wrapper

class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(
arbitrary_types_allowed=True,
)

def get_tools(self) -> List[BaseTool]:
"""Get the tools in the toolkit."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import Dict, List

from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_core.tools import BaseTool
from langchain_core.tools.base import BaseToolkit
from pydantic import BaseModel, Field

from langchain_community.tools.github.prompt import (
COMMENT_ON_ISSUE_PROMPT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import TYPE_CHECKING, List

from langchain_core.pydantic_v1 import Field
from langchain_core.tools import BaseTool
from langchain_core.tools.base import BaseToolkit
from pydantic import ConfigDict, Field

from langchain_community.tools.gmail.create_draft import GmailCreateDraft
from langchain_community.tools.gmail.get_message import GmailGetMessage
Expand Down Expand Up @@ -117,8 +117,9 @@ class GmailToolkit(BaseToolkit):

api_resource: Resource = Field(default_factory=build_resource_service)

class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(
arbitrary_types_allowed=True,
)

def get_tools(self) -> List[BaseTool]:
"""Get the tools in the toolkit."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from langchain_core.tools import BaseTool
from langchain_core.tools.base import BaseToolkit
from pydantic import ConfigDict

from langchain_community.tools.multion.close_session import MultionCloseSession
from langchain_community.tools.multion.create_session import MultionCreateSession
Expand All @@ -25,8 +26,9 @@ class MultionToolkit(BaseToolkit):
See https://python.langchain.com/docs/security for more information.
"""

class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(
arbitrary_types_allowed=True,
)

def get_tools(self) -> List[BaseTool]:
"""Get the tools in the toolkit."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from typing import Any, List, Optional, Sequence

from langchain_core.language_models import BaseLanguageModel
from langchain_core.pydantic_v1 import Field
from langchain_core.tools import BaseTool
from langchain_core.tools.base import BaseToolkit
from pydantic import Field

from langchain_community.agent_toolkits.nla.tool import NLATool
from langchain_community.tools.openapi.utils.openapi_utils import OpenAPISpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import TYPE_CHECKING, List

from langchain_core.pydantic_v1 import Field
from langchain_core.tools import BaseTool
from langchain_core.tools.base import BaseToolkit
from pydantic import ConfigDict, Field

from langchain_community.tools.office365.create_draft_message import (
O365CreateDraftMessage,
Expand Down Expand Up @@ -40,8 +40,9 @@ class O365Toolkit(BaseToolkit):

account: Account = Field(default_factory=authenticate)

class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(
arbitrary_types_allowed=True,
)

def get_tools(self) -> List[BaseTool]:
"""Get the tools in the toolkit."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
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
from langchain_core.tools import BaseTool, Tool
from pydantic import Field

from langchain_community.agent_toolkits.openapi.planner_prompt import (
API_CONTROLLER_PROMPT,
Expand Down Expand Up @@ -69,7 +69,7 @@ class RequestsGetToolWithParsing(BaseRequestsTool, BaseTool):

name: str = "requests_get"
"""Tool name."""
description = REQUESTS_GET_TOOL_DESCRIPTION
description: str = REQUESTS_GET_TOOL_DESCRIPTION
"""Tool description."""
response_length: int = MAX_RESPONSE_LENGTH
"""Maximum length of the response to be returned."""
Expand Down Expand Up @@ -103,7 +103,7 @@ class RequestsPostToolWithParsing(BaseRequestsTool, BaseTool):

name: str = "requests_post"
"""Tool name."""
description = REQUESTS_POST_TOOL_DESCRIPTION
description: str = REQUESTS_POST_TOOL_DESCRIPTION
"""Tool description."""
response_length: int = MAX_RESPONSE_LENGTH
"""Maximum length of the response to be returned."""
Expand Down Expand Up @@ -134,7 +134,7 @@ class RequestsPatchToolWithParsing(BaseRequestsTool, BaseTool):

name: str = "requests_patch"
"""Tool name."""
description = REQUESTS_PATCH_TOOL_DESCRIPTION
description: str = REQUESTS_PATCH_TOOL_DESCRIPTION
"""Tool description."""
response_length: int = MAX_RESPONSE_LENGTH
"""Maximum length of the response to be returned."""
Expand Down Expand Up @@ -167,7 +167,7 @@ class RequestsPutToolWithParsing(BaseRequestsTool, BaseTool):

name: str = "requests_put"
"""Tool name."""
description = REQUESTS_PUT_TOOL_DESCRIPTION
description: str = REQUESTS_PUT_TOOL_DESCRIPTION
"""Tool description."""
response_length: int = MAX_RESPONSE_LENGTH
"""Maximum length of the response to be returned."""
Expand Down Expand Up @@ -198,7 +198,7 @@ class RequestsDeleteToolWithParsing(BaseRequestsTool, BaseTool):

name: str = "requests_delete"
"""The name of the tool."""
description = REQUESTS_DELETE_TOOL_DESCRIPTION
description: str = REQUESTS_DELETE_TOOL_DESCRIPTION
"""The description of the tool."""

response_length: Optional[int] = MAX_RESPONSE_LENGTH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from __future__ import annotations

from typing import TYPE_CHECKING, List, Optional, Type, cast
from typing import TYPE_CHECKING, Any, List, Optional, Type, cast

from langchain_core.pydantic_v1 import root_validator
from langchain_core.tools import BaseTool, BaseToolkit
from pydantic import ConfigDict, model_validator

from langchain_community.tools.playwright.base import (
BaseBrowserTool,
Expand Down Expand Up @@ -68,12 +68,14 @@ class PlayWrightBrowserToolkit(BaseToolkit):
sync_browser: Optional["SyncBrowser"] = None
async_browser: Optional["AsyncBrowser"] = None

class Config:
arbitrary_types_allowed = True
extra = "forbid"
model_config = ConfigDict(
arbitrary_types_allowed=True,
extra="forbid",
)

@root_validator(pre=True)
def validate_imports_and_browser_provided(cls, values: dict) -> dict:
@model_validator(mode="before")
@classmethod
def validate_imports_and_browser_provided(cls, values: dict) -> Any:
"""Check that the arguments are valid."""
lazy_import_playwright_browsers()
if values.get("async_browser") is None and values.get("sync_browser") is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
HumanMessagePromptTemplate,
SystemMessagePromptTemplate,
)
from langchain_core.pydantic_v1 import Field
from langchain_core.tools import BaseTool
from langchain_core.tools.base import BaseToolkit
from pydantic import ConfigDict, Field

from langchain_community.tools.powerbi.prompt import (
QUESTION_TO_QUERY_BASE,
Expand Down Expand Up @@ -63,8 +63,9 @@ class PowerBIToolkit(BaseToolkit):
output_token_limit: Optional[int] = None
tiktoken_model_name: Optional[str] = None

class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(
arbitrary_types_allowed=True,
)

def get_tools(self) -> List[BaseTool]:
"""Get the tools in the toolkit."""
Expand Down
Loading

0 comments on commit 4200876

Please sign in to comment.