File size: 1,201 Bytes
f0c8e2c
 
91601ea
f0c8e2c
 
fecebcb
f0c8e2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fecebcb
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import uvicorn
from fastapi import FastAPI, Request
from .utils import QASearcher

app = FastAPI()
qa_search = QASearcher()

@app.post("/set_context")
async def set_context(data: Request):
    """
    Fastapi POST method that sets the QA context for search.

    Args:
      data(`dict`): Two fields required 'questions' (`list` of `str`)
        and 'answers' (`list` of `str`)
    """
    data = await data.json()

    qa_search.set_context_qa(data["questions"], data["answers"])
    return {"message": "Search context set"}


@app.post("/get_answer")
async def get_answer(data: Request):
    """
    Fastapi POST method that gets the best question and answer
    in the set context.

    Args:
      data(`dict`): One field required 'questions' (`list` of `str`)

    Returns:
      A `dict` containing the original question ('orig_q'), the most similar
      question in the context ('best_q') and the associated answer ('best_a').
    """
    data = await data.json()

    response = qa_search.get_answers(data["questions"], batch=1)
    return response


# # initialises the QA model and starts the uvicorn app
# if __name__ == "__main__":
    
#     uvicorn.run(app, host="0.0.0.0", port=8000)