-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
55 lines (40 loc) · 1.54 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import logging
from fastapi import FastAPI
from pydantic import BaseModel, Field
class RestAPIRequestBody(BaseModel):
input_schema: str = "basic" # for future use
summary: str = "" # for future use: let the LLM condense the message
message: str = Field(..., description="User input message")
class SourceDocument(BaseModel):
title: str | None = Field(None, description="Optional, title of the document")
external_link: str | None = Field(None, description="Optional, external https link")
content: str
class RestAPIResponseBody(BaseModel):
documents: list[SourceDocument]
app = FastAPI()
@app.post("/query", response_model=RestAPIResponseBody)
async def query(request: RestAPIRequestBody) -> RestAPIResponseBody:
# TODO: remove logging user data in production
logging.debug(request.message) # raw user input
return RestAPIResponseBody(
documents=[
SourceDocument(
title="Elizabeth",
content="Elizabeth says 'Hello World'",
external_link="https://www.example.com",
),
SourceDocument(
title="Angela",
content="Angela says 'Hallo Welt'",
external_link=None,
),
SourceDocument(
title="Carl",
content="Carl says 'Hej världen'",
external_link=None,
),
]
)
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", reload=True, port=9001, log_level="info")