cjber commited on
Commit
eed0e46
·
1 Parent(s): 9099bff

adjust api to allow react frontend

Browse files
Files changed (1) hide show
  1. src/search_api/api.py +11 -10
src/search_api/api.py CHANGED
@@ -2,11 +2,19 @@ from typing import Union
2
  from uuid import UUID, uuid4
3
 
4
  from fastapi import FastAPI
 
5
  from langchain_core.documents import Document
6
 
7
  from src.model.model import generate, search
8
 
9
  app = FastAPI()
 
 
 
 
 
 
 
10
  document_store = {}
11
  query_mapping = {}
12
 
@@ -36,13 +44,6 @@ async def explain(thread_id: UUID, docid: int) -> dict:
36
  )
37
  query = query_mapping[thread_id]
38
  out = generate(query=query, document=document, thread_id=thread_id)
39
- generation = out["generation"]
40
-
41
- return {
42
- "generation": generation,
43
- "metadata": {
44
- "thread_id": thread_id,
45
- "query": query,
46
- "related_dataset": doc_dict,
47
- },
48
- }
 
2
  from uuid import UUID, uuid4
3
 
4
  from fastapi import FastAPI
5
+ from fastapi.middleware.cors import CORSMiddleware
6
  from langchain_core.documents import Document
7
 
8
  from src.model.model import generate, search
9
 
10
  app = FastAPI()
11
+ app.add_middleware(
12
+ CORSMiddleware,
13
+ allow_origins=["*"],
14
+ allow_credentials=True,
15
+ allow_methods=["*"],
16
+ allow_headers=["*"],
17
+ )
18
  document_store = {}
19
  query_mapping = {}
20
 
 
44
  )
45
  query = query_mapping[thread_id]
46
  out = generate(query=query, document=document, thread_id=thread_id)
47
+ out["document"] = doc_dict
48
+
49
+ return out