fern python sdk setup (#1938)

Co-authored-by: eden <eyw520@gmail.com>
This commit is contained in:
Shuchang Zheng
2025-03-21 09:21:24 -07:00
committed by GitHub
parent 71e5242970
commit 9ffcb00951
6 changed files with 15559 additions and 9800 deletions

View File

@@ -5,6 +5,7 @@ from typing import Awaitable, Callable
import structlog
from fastapi import FastAPI, Response, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi
from fastapi.responses import JSONResponse
from pydantic import ValidationError
from starlette.requests import HTTPConnection, Request
@@ -31,6 +32,20 @@ class ExecutionDatePlugin(Plugin):
return datetime.now()
def custom_openapi() -> dict:
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Skyvern API",
version="1.0.0",
description="API for Skyvern",
routes=app.routes,
)
openapi_schema["servers"] = [{"url": "https://api.skyvern.com", "x-fern-server-name": "Production"}]
app.openapi_schema = openapi_schema
return app.openapi_schema
def get_agent_app() -> FastAPI:
"""
Start the agent server.
@@ -51,6 +66,7 @@ def get_agent_app() -> FastAPI:
app.include_router(v2_router, prefix="/api/v2")
app.include_router(websocket_router, prefix="/api/v1/stream")
app.include_router(totp_router, prefix="/api/v1/totp")
app.openapi = custom_openapi
app.add_middleware(
RawContextMiddleware,
@@ -72,7 +88,10 @@ def get_agent_app() -> FastAPI:
@app.exception_handler(ValidationError)
async def handle_pydantic_validation_error(request: Request, exc: ValidationError) -> JSONResponse:
return JSONResponse(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, content={"detail": str(exc)})
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
content={"detail": str(exc)},
)
@app.exception_handler(Exception)
async def unexpected_exception(request: Request, exc: Exception) -> JSONResponse: