Spaces:
Sleeping
Sleeping
MAsad789565
commited on
Commit
•
bb23eff
1
Parent(s):
e1afdc5
Update apis/search_api.py
Browse files- apis/search_api.py +23 -3
apis/search_api.py
CHANGED
@@ -3,12 +3,12 @@ import os
|
|
3 |
import sys
|
4 |
import uvicorn
|
5 |
|
6 |
-
from fastapi import FastAPI
|
7 |
-
from fastapi.
|
|
|
8 |
from pydantic import BaseModel, Field
|
9 |
from typing import Union
|
10 |
from sse_starlette.sse import EventSourceResponse, ServerSentEvent
|
11 |
-
from utils.logger import logger
|
12 |
from networks.google_searcher import GoogleSearcher
|
13 |
from networks.webpage_fetcher import BatchWebpageFetcher
|
14 |
from documents.query_results_extractor import QueryResultsExtractor
|
@@ -25,6 +25,7 @@ class SearchAPIApp:
|
|
25 |
version="1.0",
|
26 |
)
|
27 |
self.setup_routes()
|
|
|
28 |
|
29 |
class QueriesToSearchResultsPostItem(BaseModel):
|
30 |
queries: list = Field(
|
@@ -134,6 +135,25 @@ class SearchAPIApp:
|
|
134 |
summary="Search queries, and extract contents from results",
|
135 |
)(self.queries_to_search_results)
|
136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
class ArgParser(argparse.ArgumentParser):
|
139 |
def __init__(self, *args, **kwargs):
|
|
|
3 |
import sys
|
4 |
import uvicorn
|
5 |
|
6 |
+
from fastapi import FastAPI
|
7 |
+
from fastapi.middleware.cors import CORSMiddleware
|
8 |
+
from starlette.middleware.base import BaseHTTPMiddleware
|
9 |
from pydantic import BaseModel, Field
|
10 |
from typing import Union
|
11 |
from sse_starlette.sse import EventSourceResponse, ServerSentEvent
|
|
|
12 |
from networks.google_searcher import GoogleSearcher
|
13 |
from networks.webpage_fetcher import BatchWebpageFetcher
|
14 |
from documents.query_results_extractor import QueryResultsExtractor
|
|
|
25 |
version="1.0",
|
26 |
)
|
27 |
self.setup_routes()
|
28 |
+
self.setup_middleware()
|
29 |
|
30 |
class QueriesToSearchResultsPostItem(BaseModel):
|
31 |
queries: list = Field(
|
|
|
135 |
summary="Search queries, and extract contents from results",
|
136 |
)(self.queries_to_search_results)
|
137 |
|
138 |
+
def setup_middleware(self):
|
139 |
+
self.app.add_middleware(
|
140 |
+
CORSMiddleware,
|
141 |
+
allow_origins=["*"],
|
142 |
+
allow_credentials=True,
|
143 |
+
allow_methods=["*"],
|
144 |
+
allow_headers=["*"],
|
145 |
+
)
|
146 |
+
|
147 |
+
class NoCacheMiddleware(BaseHTTPMiddleware):
|
148 |
+
async def dispatch(self, request, call_next):
|
149 |
+
response = await call_next(request)
|
150 |
+
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
|
151 |
+
response.headers['Pragma'] = 'no-cache'
|
152 |
+
response.headers['Expires'] = '0'
|
153 |
+
return response
|
154 |
+
|
155 |
+
self.app.add_middleware(NoCacheMiddleware)
|
156 |
+
|
157 |
|
158 |
class ArgParser(argparse.ArgumentParser):
|
159 |
def __init__(self, *args, **kwargs):
|