Run Places search and get k number of places that exists that match.
(self, query: str)
| 14 | self.top_k_results: Optional[int] = None |
| 15 | |
| 16 | def run(self, query: str) -> str: |
| 17 | """Run Places search and get k number of places that exists that match.""" |
| 18 | search_results = self.google_map_client.places(query)["results"] |
| 19 | num_to_return = len(search_results) |
| 20 | |
| 21 | places = [] |
| 22 | |
| 23 | if num_to_return == 0: |
| 24 | return "Google Places did not find any places that match the description" |
| 25 | |
| 26 | num_to_return = ( |
| 27 | num_to_return |
| 28 | if self.top_k_results is None |
| 29 | else min(num_to_return, self.top_k_results) |
| 30 | ) |
| 31 | |
| 32 | for i in range(num_to_return): |
| 33 | result = search_results[i] |
| 34 | details = self.fetch_place_details(result["place_id"]) |
| 35 | |
| 36 | if details is not None: |
| 37 | places.append(details) |
| 38 | |
| 39 | return "\n".join([f"{i+1}. {item}" for i, item in enumerate(places)]) |
| 40 | |
| 41 | def fetch_place_details(self, place_id: str) -> Optional[str]: |
| 42 | try: |
no test coverage detected