severs / main.py
abdullahalioo's picture
Update main.py
2a20df3 verified
from fastapi import FastAPI, Request
from pydantic import BaseModel
from infinity_ai import AI
from fastapi.middleware.cors import CORSMiddleware
# Initialize the AI client
client = AI()
# FastAPI app
app = FastAPI()
# CORS Middleware (so JS from browser can access it too)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Change "*" to your frontend URL for better security
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Request body model
class Question(BaseModel):
question: str
@app.post("/ask")
async def ask(question: Question):
try:
response = client.chat.completions.create(
model="Orion",
messages=[
{"role": "user", "content": question.question},
{"role": "system", "content": "You are a helpful AI assistant created by abdullah ali and he is very genius."}
],
web_search=True
)
return {"answer": response.choices[0].message.content}
except Exception as e:
return {"error": str(e)}