mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 23:29:21 +00:00
Signed-off-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com> Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Dan O'Donovan <dan.odonovan@gmail.com> Co-authored-by: Tom Daniel Grande <tomdgrande@gmail.com> Co-authored-by: Grande <Tom.Daniel.Grande@statsbygg.no> Co-authored-by: Bagatur <baskaryan@gmail.com> Co-authored-by: ccurme <chester.curme@gmail.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com> Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com> Co-authored-by: ZhangShenao <15201440436@163.com> Co-authored-by: Friso H. Kingma <fhkingma@gmail.com> Co-authored-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Nuno Campos <nuno@langchain.dev> Co-authored-by: Morgante Pell <morgantep@google.com>
39 lines
1013 B
Python
39 lines
1013 B
Python
"""Base class for Gmail tools."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from langchain_core.tools import BaseTool
|
|
from pydantic import Field
|
|
|
|
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
|
|
|
|
|
|
class GmailBaseTool(BaseTool):
|
|
"""Base class for Gmail tools."""
|
|
|
|
api_resource: Resource = Field(default_factory=build_resource_service)
|
|
|
|
@classmethod
|
|
def from_api_resource(cls, api_resource: Resource) -> "GmailBaseTool":
|
|
"""Create a tool from an api resource.
|
|
|
|
Args:
|
|
api_resource: The api resource to use.
|
|
|
|
Returns:
|
|
A tool.
|
|
"""
|
|
return cls(service=api_resource) # type: ignore[call-arg]
|