-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
64 lines (51 loc) · 1.6 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
import llms
import images
import docs.scripts as doc
from fastapi.responses import FileResponse
from os import environ
from dotenv import load_dotenv
load_dotenv()
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class LLMRequest(BaseModel):
title: str
section: str
class wordDocRequest(BaseModel):
title : str
imageLinks : list
body : list
@app.post("/gemini")
async def gemini(body: LLMRequest):
return llms.gemini_gen(body.title, body.section)
@app.post("/gemini-alt")
async def gemini_alt(body: LLMRequest):
return llms.gemini_alt_gen(body.title, body.section)
@app.post("/mistral")
async def mistral(body: LLMRequest):
return llms.mistral_gen(body.title, body.section)
@app.post("/falcon")
async def falcon(body: LLMRequest):
return llms.falcon_gen(body.title, body.section)
@app.post("/llama")
async def falcon(body: LLMRequest):
return llms.llama_gen(body.title, body.section)
@app.get("/images/pexels")
async def pexels(location: str | None = "Goa"):
return images.get_pexels(location)
@app.get("/images/pixabay")
async def pixabay(location: str | None = "Goa"):
return images.get_pixabay(location)
@app.post("/generate")
async def generate(body : wordDocRequest):
doc_name = doc.generate_doc(body.title,body.imageLinks,body.body)
generated_doc_path = environ.get("GENERATED_DOC_PATH")
return FileResponse(path=(generated_doc_path + doc_name))