-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (36 loc) · 1.21 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
from inference import InferenceModel
from fastapi import FastAPI, Request
from fastapi.responses import StreamingResponse
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
# MODEL_PATH = 'models/mistral-7b-instruct-v0.2.Q2_K.gguf'
# MODEL_PATH = 'models/mistral-7b-instruct-v0.2.Q4_K_M.gguf'
# MODEL_PATH = 'models/mistral-7b-instruct-v0.2.Q5_K_S.gguf'
MODEL_PATH = 'models/42dot_LLM-SFT-1.3B_Q4_K_M.gguf'
# MODEL_PATH = 'models/42dot_LLM-SFT-1.3B.gguf'
inference_model = InferenceModel(
model_path=MODEL_PATH,
# template_path="template2.txt",
)
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/")
def index(request: Request):
return templates.TemplateResponse(
request=request, name="index.html", context={"id": id}
)
@app.post("/")
def run_model(question: str):
return StreamingResponse(
inference_model(question),
media_type="text/plain",
)