mirror of
https://github.com/hwchase17/langchain.git
synced 2026-04-04 11:25:11 +00:00
Added missed docstrings. Formatted docstrings to the consistent form. --------- Co-authored-by: ccurme <chester.curme@gmail.com>
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, List
|
|
|
|
from langchain_core.pydantic_v1 import Field
|
|
from langchain_core.tools import BaseToolkit
|
|
|
|
from langchain_community.tools import BaseTool
|
|
from langchain_community.tools.gmail.create_draft import GmailCreateDraft
|
|
from langchain_community.tools.gmail.get_message import GmailGetMessage
|
|
from langchain_community.tools.gmail.get_thread import GmailGetThread
|
|
from langchain_community.tools.gmail.search import GmailSearch
|
|
from langchain_community.tools.gmail.send_message import GmailSendMessage
|
|
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
|
|
|
|
|
|
SCOPES = ["https://mail.google.com/"]
|
|
|
|
|
|
class GmailToolkit(BaseToolkit):
|
|
"""Toolkit for interacting with Gmail.
|
|
|
|
*Security Note*: This toolkit contains tools that can read and modify
|
|
the state of a service; e.g., by reading, creating, updating, deleting
|
|
data associated with this service.
|
|
|
|
For example, this toolkit can be used to send emails on behalf of the
|
|
associated account.
|
|
|
|
See https://python.langchain.com/docs/security for more information.
|
|
|
|
Parameters:
|
|
api_resource: Optional. The Google API resource. Default is None.
|
|
"""
|
|
|
|
api_resource: Resource = Field(default_factory=build_resource_service)
|
|
|
|
class Config:
|
|
"""Pydantic config."""
|
|
|
|
arbitrary_types_allowed = True
|
|
|
|
def get_tools(self) -> List[BaseTool]:
|
|
"""Get the tools in the toolkit."""
|
|
return [
|
|
GmailCreateDraft(api_resource=self.api_resource),
|
|
GmailSendMessage(api_resource=self.api_resource),
|
|
GmailSearch(api_resource=self.api_resource),
|
|
GmailGetMessage(api_resource=self.api_resource),
|
|
GmailGetThread(api_resource=self.api_resource),
|
|
]
|