forked from aritrasen87/LLM_RAG_Model_Deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
61 lines (46 loc) · 1.15 KB
/
api.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
56
57
58
59
60
61
# pip install fastapi uvicorn
from fastapi import FastAPI
import uvicorn
import os
from dotenv import load_dotenv
from enum import Enum
from pydantic import BaseModel
load_dotenv()
app = FastAPI()
# @app.get("/hello")
# async def hello():
# return 'Hello World'
@app.get("/hello/{name}")
async def hello(name:str):
return f"Hello {name} "
models = {
'LLMs' : ['OpenAI', 'Mistral'],
'NLP' : ['Bert', 'RoBerta'],
'ML' : ['Xgboost', 'Catboost']
}
# @app.get("/get_models/{usecase}")
# async def get_items(usecase:str):
# return models.get(usecase)
### Validation:
class AvailableModel(str, Enum):
LLMs = "LLMs"
NLP = "NLP"
ML = "ML"
@app.get("/get_models/{usecase}")
async def get_items(usecase: AvailableModel):
return models.get(usecase)
class Item(BaseModel):
name: str
description: str | None = None
price: float
tax: float | None = None
@app.post("/items/")
async def create_item(item: Item):
return item
if __name__ == "__main__":
# mounting at the root path
uvicorn.run(
app="api:app",
host=os.getenv("UVICORN_HOST"),
port=int(os.getenv("UVICORN_PORT"))
)