Spaces:
Sleeping
Sleeping
| from agno.tools import tool | |
| from .product_search import AmazonProductSearch, FilterModel, ProductItem | |
| from .config import settings | |
| from typing import Optional | |
| import json | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| def fetch_products( | |
| query: str, | |
| limit: int = settings.SEARCH_LIMIT, | |
| filters: Optional[FilterModel] = None, | |
| ) -> list[dict]: | |
| """ | |
| Fetch products from Amazon based on query and filters | |
| Args: | |
| query (str): Search query | |
| limit (int, optional): Number of products to return. Must be between 2-10. Defaults to 6. | |
| filters (FilterModel, optional): Filters to apply. Defaults to None. | |
| Returns: | |
| list[dict]: List of products dictionary items matching the query and filters | |
| """ | |
| limit = max(2, min(limit, 10)) # Ensure limit is between 2 and 10 | |
| product_searcher = AmazonProductSearch( | |
| rapid_api_key=settings.RAPIDAPI_KEY, rerank_model=settings.RERANKING_MODEL | |
| ) | |
| products: list[ProductItem] = product_searcher.fetch_products( | |
| query=query, | |
| filters=filters, | |
| limit=limit | |
| ) | |
| return json.dumps([product.model_dump() for product in products]) | |