File size: 964 Bytes
7f92deb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a43d028
7f92deb
 
 
cf53187
7f92deb
cf53187
7f92deb
cf53187
7f92deb
 
 
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from src.TinyLLama import text_generation
from src.classmodels.inputforgeneration import InputForGeneration
import uvicorn

app = FastAPI()

origins = ["*"]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"] 
)

@app.get("/cmsai/warmuptextgenerationmodel")
def warmupGenerationModel():
    warmupModelMessage = text_generation.warmupTextGenerationModel()
    return warmupModelMessage   

@app.post("/cmsai/generatetext")
async def generateTextUsingLLama(inputSettings:InputForGeneration):
    try:       
        output = text_generation.generateText(inputSettings)
        if output is not None:
            return output
        else:
            return "error when generating text"
    except Exception as e:
        return str(e)
    
if __name__ == "__main__":
    uvicorn.run(app=app)