INNER CODE UNIT · Python
create_endpoint
agentscope-ai/agentscope-runtime · src/agentscope_runtime/sandbox/manager/server/app.py:159
def create_endpoint(method):
async def endpoint(
request: Request,
token: HTTPAuthorizationCredentials = Depends(verify_token),
):
try:
data = await request.json()
logger.info(
f"Calling {method.__name__} with data: {data}",
)
# Check if the method is asynchronous
if inspect.iscoroutinefunction(method):
# If async, just await it
result = await method(**data)
else:
# If sync, run it in a thread to avoid blocking the event loop
result = await asyncio.to_thread(method, **data)