import uvicorn import globals from rephrase.rephrase_text import rephraseText, rephraseText_withStream from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import StreamingResponse from models.rephraseparam import rephraseparam app = FastAPI() app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) #TODO: add logging for exception and openai call backs @app.get("/cmsai/isconfigkeyavailable") def isConfigKeyAvailable(): SECRET_KEY = globals.OPENAI_API_KEY if SECRET_KEY != "" and len(SECRET_KEY.strip()) > 0: return "API KEY IS CONFIGURED" else: return "API KEY IS NOT CONFIGURED" @app.post("/cmsai/summarizetext") async def summarizetext(param:rephraseparam): text_summary = rephraseText(param) return text_summary @app.post("/cmsai/summarizetextwithstreaming") async def summarizetext_stream(param:rephraseparam): summary_inChunks = rephraseText_withStream(param) return StreamingResponse(summary_inChunks, media_type= "text/plain") if __name__ == "__main__": uvicorn.run(app= app)