跳到内容

Yelp

YelpToolSpec #

基类: BaseToolSpec

Yelp 工具规范。

源代码位于 llama-index-integrations/tools/llama-index-tools-yelp/llama_index/tools/yelp/base.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class YelpToolSpec(BaseToolSpec):
    """Yelp tool spec."""

    # TODO add disclaimer
    spec_functions = ["business_search", "business_reviews"]

    def __init__(self, api_key: str, client_id: str) -> Document:
        """Initialize with parameters."""
        from yelpapi import YelpAPI

        self.client = YelpAPI(api_key)

    def business_search(self, location: str, term: str, radius: Optional[int] = None):
        """
        Make a query to Yelp to find businesses given a location to search.

        Args:
            Businesses returned in the response may not be strictly within the specified location.
            term (str): Search term, e.g. "food" or "restaurants", The term may also be the business's name, such as "Starbucks"
            radius (int): A suggested search radius in meters. This field is used as a suggestion to the search. The actual search radius may be lower than the suggested radius in dense urban areas, and higher in regions of less business density.


        """
        response = self.client.search_query(location=location, term=term)
        return [Document(text=str(response))]

    def business_reviews(self, id: str):
        """
        Make a query to Yelp to find a business using an id from business_search.

        Args:
            # The id

        """
        response = self.client.reviews_query(id=id)
        return [Document(text=str(response))]
business_search(location: str, term: str, radius: Optional[int] = None)

对 Yelp 进行查询,以查找给定搜索位置的商家。

参数

名称 类型 描述 默认值
term str

搜索词,例如“food”或“restaurants”,该词也可以是商家名称,例如“Starbucks”

必需
radius int

建议的搜索半径,单位为米。此字段用作搜索的建议。在人口稠密的市区,实际搜索半径可能低于建议半径;在商家密度较低的地区,实际搜索半径可能高于建议半径。

None
源代码位于 llama-index-integrations/tools/llama-index-tools-yelp/llama_index/tools/yelp/base.py
42
43
44
45
46
47
48
49
50
51
52
53
54
def business_search(self, location: str, term: str, radius: Optional[int] = None):
    """
    Make a query to Yelp to find businesses given a location to search.

    Args:
        Businesses returned in the response may not be strictly within the specified location.
        term (str): Search term, e.g. "food" or "restaurants", The term may also be the business's name, such as "Starbucks"
        radius (int): A suggested search radius in meters. This field is used as a suggestion to the search. The actual search radius may be lower than the suggested radius in dense urban areas, and higher in regions of less business density.


    """
    response = self.client.search_query(location=location, term=term)
    return [Document(text=str(response))]

business_reviews #

business_reviews(id: str)

对 Yelp 进行查询,使用 business_search 返回的 ID 查找商家。

源代码位于 llama-index-integrations/tools/llama-index-tools-yelp/llama_index/tools/yelp/base.py
56
57
58
59
60
61
62
63
64
65
def business_reviews(self, id: str):
    """
    Make a query to Yelp to find a business using an id from business_search.

    Args:
        # The id

    """
    response = self.client.reviews_query(id=id)
    return [Document(text=str(response))]