gemini-gate / app.py
anhdt-dsai-02's picture
Update app.py
c7aad43 verified
raw
history blame
780 Bytes
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi import HTTPException
import os
import traceback
from fastapi.middleware.cors import CORSMiddleware
from gemini import complete_gemini_async
class Data(BaseModel):
prompt: str
key: str
app = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allow_headers=["*"],
)
@app.post("/gemini_gate")
async def geminiv2(data: Data):
try:
result = await complete_gemini_async(data.prompt, data.key)
return result
except Exception as e:
raise HTTPException(status_code=500, detail="An error occurred: {}".format(traceback.format_exc()))