File size: 1,089 Bytes
ae4e1e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
561db8a
ae4e1e8
 
 
 
 
 
 
 
 
 
 
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
import uvicorn
from fastapi import FastAPI

from api.config import Config
from api.question_answering import QAModel
from api.logger import logger


config = Config()
app = FastAPI()
qa_model = QAModel(
    llm_model_id=config.question_answering_model_id,
    embedding_model_id=config.embedding_model_id,
    index_repo_id=config.index_repo_id,
    use_docs_for_context=config.use_docs_for_context,
    add_sources_to_response=config.add_sources_to_response,
    use_messages_for_context=config.use_messages_in_context,
    num_relevant_docs=config.num_relevant_docs,
    debug=config.debug
)


@app.get("/")
def get_answer(question: str, messgages_context: str):
    logger.info(
        f"Received request with question: {question}" \
        f"and context: {messgages_context}"
    )
    response = qa_model.get_response(
        question=question,
        messages_context=messgages_context
    )
    return {
        "answer": response.get_answer(),
        "sources": response.get_sources_as_text()
    }


if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)