-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (41 loc) · 1.29 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
import os
from fastapi import FastAPI, Request, Response
from starlette.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from backend.core import run_llm
# from dotenv import load_dotenv
# load_dotenv()
app = FastAPI()
templates = Jinja2Templates(directory="templates")
# Define a static directory to serve static files
app.mount("/static", StaticFiles(directory="static"), name="static")
def root_dir():
return os.path.abspath(os.path.dirname(__file__))
def get_file(filename):
try:
src = os.path.join(root_dir(), filename)
return open(src).read()
except IOError as exc:
return str(exc)
@app.get('/')
async def metrics():
content = get_file('templates/index.html')
return Response(content, media_type="text/html")
@app.get('/{prompt}')
async def index(prompt: str):
result = run_llm(query=prompt)
print(result)
return result
# @app.get("/train-model")
# async def train_model():
# result = ingestion()
# if result:
# return {
# "status": 200,
# "message": "****** Added to Pinecone vectorstore vectors"
# }
#
# return {
# "status": 101,
# "message": "something happen with ingestion vectorization"
# }