File size: 822 Bytes
0d14ac1
cf1ac3f
 
 
 
 
 
 
883a744
 
 
cf1ac3f
 
 
 
 
 
 
 
 
 
883a744
 
cf1ac3f
883a744
6737b1f
cf1ac3f
 
 
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
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 Text(BaseModel):
    ques: str
    ans: 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("/geminiv2")
async def geminiv2(data: Text, api_key: str = Security(get_api_key)):
    try:
        result = await complete_gemini_async((data.ques, data.ans), "ahihi")
        return result
    except Exception as e:
        raise HTTPException(status_code=500, detail="An error occurred: {}".format(traceback.format_exc()))