| from fastapi import FastAPI, Depends |
| |
| from fastapi.middleware.cors import CORSMiddleware |
| |
| |
|
|
|
|
| |
| from auth import get_api_key |
| from credentials_manager import CredentialManager |
| from vertex_ai_init import init_vertex_ai |
|
|
| |
| from routes import models_api |
| from routes import chat_api |
|
|
| |
|
|
| app = FastAPI(title="OpenAI to Gemini Adapter") |
|
|
| app.add_middleware( |
| CORSMiddleware, |
| allow_origins=["*"], |
| allow_credentials=True, |
| allow_methods=["*"], |
| allow_headers=["*"], |
| ) |
|
|
| credential_manager = CredentialManager() |
| app.state.credential_manager = credential_manager |
|
|
| |
| app.include_router(models_api.router) |
| app.include_router(chat_api.router) |
|
|
| @app.on_event("startup") |
| async def startup_event(): |
| if await init_vertex_ai(credential_manager): |
| print("INFO: Vertex AI credential and model config initialization check completed successfully.") |
| else: |
| print("ERROR: Failed to initialize a fallback Vertex AI client. API will likely fail.") |
|
|
| @app.get("/") |
| async def root(): |
| return { |
| "status": "ok", |
| "message": "OpenAI to Gemini Adapter is running." |
| } |
|
|