mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-08-26 16:55:38 -04:00
d3ec00b566
Co-authored-by: Nuno Campos <nuno@boringbits.io> Co-authored-by: Davis Chase <130488702+dev2049@users.noreply.github.com> Co-authored-by: Zander Chase <130414180+vowelparrot@users.noreply.github.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
"""Tool for the Google search API."""
|
|
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from langchain.callbacks.manager import (
|
|
AsyncCallbackManagerForToolRun,
|
|
CallbackManagerForToolRun,
|
|
)
|
|
from langchain.tools.base import BaseTool
|
|
from langchain.utilities.google_places_api import GooglePlacesAPIWrapper
|
|
|
|
|
|
class GooglePlacesSchema(BaseModel):
|
|
query: str = Field(..., description="Query for goole maps")
|
|
|
|
|
|
class GooglePlacesTool(BaseTool):
|
|
"""Tool that adds the capability to query the Google places API."""
|
|
|
|
name = "Google Places"
|
|
description = (
|
|
"A wrapper around Google Places. "
|
|
"Useful for when you need to validate or "
|
|
"discover addressed from ambiguous text. "
|
|
"Input should be a search query."
|
|
)
|
|
api_wrapper: GooglePlacesAPIWrapper = Field(default_factory=GooglePlacesAPIWrapper)
|
|
|
|
def _run(
|
|
self,
|
|
query: str,
|
|
run_manager: Optional[CallbackManagerForToolRun] = None,
|
|
) -> str:
|
|
"""Use the tool."""
|
|
return self.api_wrapper.run(query)
|
|
|
|
async def _arun(
|
|
self,
|
|
query: str,
|
|
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
|
) -> str:
|
|
"""Use the tool asynchronously."""
|
|
raise NotImplementedError("GooglePlacesRun does not support async")
|