Spaces:
Runtime error
Runtime error
from typing import Dict, Any | |
def generate_mongodb_query(filters: Dict[str, Any]) -> Dict[str, Any]: | |
query = {} | |
# # makeModel | |
# if filters.get('makeModel') != "NULL": | |
# query['makeModel'] = filters['makeModel'] | |
# # Model | |
# if filters.get('model') != "NULL": | |
# query['model'] = filters['model'] | |
# # Make | |
# if filters.get('make') != "NULL": | |
# query['make'] = filters['make'] | |
# # Color | |
# if filters.get('color') != "NULL": | |
# query['color'] = filters['color'] | |
# # Features | |
# if filters.get('features') != "NULL" and filters.get('features'): | |
# query['features'] = {'$all': filters['features']} | |
# price | |
if filters.get('minprice') != "NULL" or filters.get('maxprice') != "NULL": | |
price_filter = {} | |
if filters.get('minprice') != "NULL": | |
price_filter['$gte'] = filters['minprice'] | |
if filters.get('maxprice') != "NULL": | |
price_filter['$lte'] = filters['maxprice'] | |
if price_filter: | |
query['msrp'] = price_filter | |
# # Year | |
# if filters.get('minyear') != "NULL" or filters.get('maxyear') != "NULL": | |
# year_filter = {} | |
# if filters.get('minyear') != "NULL": | |
# year_filter['$gte'] = filters['minyear'] | |
# if filters.get('maxyear') != "NULL": | |
# year_filter['$lte'] = filters['maxyear'] | |
# if year_filter: | |
# query['year'] = year_filter | |
return query | |
def get_prompt(query): | |
prompt = f""" | |
You are a helpful assistant that extracts the price and features of a car from a given user query. | |
You will extract the following fields: | |
- makeModel (string datatype) | |
- minprice (int datatype) | |
- maxprice (int datatype) | |
- minyear (int datatype) | |
- maxyear (int datatype) | |
- features (list of strings) | |
- color (string datatype) | |
- make (string datatype) | |
- model (string datatype) | |
price should only be a numerical number. dont write words or text or abbreviations. Just numbers like 40000 or 50000. | |
return "NULL" in the field if it is not mentioned | |
You goal is to extract the price and features of a car from a given user query. | |
return a json only | |
example output: | |
{{ | |
"makeModel": "MINI HARDTOP 4 DOOR", | |
"price": "40000", | |
"features": ["Leather Seats", "Navigation", "Sunroof"] | |
}} | |
Here is the user query: {query} | |
""" | |
return prompt |