forked from Azure-Samples/openai-plugin-fastapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
26 lines (22 loc) · 802 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from fastapi import FastAPI
from routers.wellknown import wellknown
from fastapi.middleware.cors import CORSMiddleware
import json
app = FastAPI()
app.include_router(wellknown)
app.add_middleware(CORSMiddleware, allow_origins=["https://chat.openai.com"])
with open("./data/products.json", "r") as f:
products = json.load(f)
@app.get("/products", summary="Get a list of products", operation_id="getProducts")
async def get_products(query: str = None):
"""
Returns a list of products, optionally filtered by providing a query parameter.
"""
if query:
keywords = query.lower().split()
return [
product
for product in products
if all(keyword in str(product.values()).lower() for keyword in keywords)
]
return products