-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
40 lines (33 loc) · 1.05 KB
/
api.py
File metadata and controls
40 lines (33 loc) · 1.05 KB
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
from http.client import HTTPException
from fastapi import FastAPI
from private_keys import PATH_TO_MODELS_DIR
from components.custom_model import CustomModel
app = FastAPI()
model:CustomModel=None
@app.get("/")
def home():
return {"message": "Hello from FastAPI"}
@app.post("/initModel")
def initModel():
global model
model_name = "Hermes-2-Pro-Mistral-7B.Q4_0.gguf"
try:
model = CustomModel(PATH_TO_MODELS_DIR, model_name)
return {"status": "Model "+model_name+" loaded successfully"}
except FileNotFoundError:
raise HTTPException(status_code=404, detail="Model not found")
@app.post("/delModel")
def del_model():
global model
if model is None:
return {"status": "Model not initialized"}
del model
model = None
return {"status": "Model deleted successfully"}
@app.get("/getResponse")
def getResponse(user_prompt:str):
global model
if model is None:
return {"status": "Model not initialized"}
response=model.generate_response(user_prompt)
return {"response": response}