Source code for langchain_community.tools.gmail.base

"""用于Gmail工具的基类。"""
from __future__ import annotations

from typing import TYPE_CHECKING

from langchain_core.pydantic_v1 import Field
from langchain_core.tools import BaseTool

from langchain_community.tools.gmail.utils import build_resource_service

if TYPE_CHECKING:
    # This is for linting and IDE typehints
    from googleapiclient.discovery import Resource
else:
    try:
        # We do this so pydantic can resolve the types when instantiating
        from googleapiclient.discovery import Resource
    except ImportError:
        pass


[docs]class GmailBaseTool(BaseTool): """用于Gmail工具的基类。""" api_resource: Resource = Field(default_factory=build_resource_service)
[docs] @classmethod def from_api_resource(cls, api_resource: Resource) -> "GmailBaseTool": """从api资源创建一个工具。 参数: api_resource: 要使用的api资源。 返回: 一个工具。 """ return cls(service=api_resource) # type: ignore[call-arg]