File size: 1,077 Bytes
2ae0d3b 4e4ca52 2ae0d3b 4e4ca52 f0cacfe 4e4ca52 f0cacfe 4e4ca52 2ae0d3b f0cacfe 4e4ca52 f0cacfe 4e4ca52 f0cacfe 2ae0d3b f0cacfe 9752c22 2ae0d3b f0cacfe 2ae0d3b f0cacfe 4e4ca52 | 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 | """
Main application entry point
"""
from fastapi import FastAPI, Request, Response
from fastapi.middleware.cors import CORSMiddleware
from app.core.config import settings
from app.api import openai, anthropic
# Create FastAPI app
app = FastAPI(
title="OpenAI Compatible API Server",
description="An OpenAI-compatible API server for Z.AI chat service",
version="1.0.0"
)
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allow_headers=["Content-Type", "Authorization"],
)
# Include API routers
app.include_router(openai.router)
app.include_router(anthropic.router)
@app.options("/")
async def handle_options():
"""Handle OPTIONS requests"""
return Response(status_code=200)
@app.get("/")
async def root():
"""Root endpoint"""
return {"message": "OpenAI Compatible API Server"}
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=settings.LISTEN_PORT, reload=True) |