fix: cleanup error trace for no llm/embedding_config on POST (#2218)

This commit is contained in:
Charles Packer
2024-12-10 14:00:31 -08:00
committed by GitHub
parent 2dc47c6f22
commit 223b6bc0a9
2 changed files with 16 additions and 5 deletions

View File

@@ -6,7 +6,7 @@ from pathlib import Path
from typing import Optional
import uvicorn
from fastapi import FastAPI
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.middleware.cors import CORSMiddleware
@@ -136,17 +136,18 @@ def create_application() -> "FastAPI":
},
)
debug_mode = "--debug" in sys.argv
app = FastAPI(
swagger_ui_parameters={"docExpansion": "none"},
# openapi_tags=TAGS_METADATA,
title="Letta",
summary="Create LLM agents with long-term memory and custom tools 📚🦙",
version="1.0.0", # TODO wire this up to the version in the package
debug=True,
debug=debug_mode, # if True, the stack trace will be printed in the response
)
@app.exception_handler(Exception)
async def generic_error_handler(request, exc):
async def generic_error_handler(request: Request, exc: Exception):
# Log the actual error for debugging
log.error(f"Unhandled error: {exc}", exc_info=True)
@@ -166,12 +167,16 @@ def create_application() -> "FastAPI":
},
)
@app.exception_handler(ValueError)
async def value_error_handler(request: Request, exc: ValueError):
return JSONResponse(status_code=400, content={"detail": str(exc)})
@app.exception_handler(LettaAgentNotFoundError)
async def agent_not_found_handler(request, exc):
async def agent_not_found_handler(request: Request, exc: LettaAgentNotFoundError):
return JSONResponse(status_code=404, content={"detail": "Agent not found"})
@app.exception_handler(LettaUserNotFoundError)
async def user_not_found_handler(request, exc):
async def user_not_found_handler(request: Request, exc: LettaUserNotFoundError):
return JSONResponse(status_code=404, content={"detail": "User not found"})
settings.cors_origins.append("https://app.letta.com")

View File

@@ -826,6 +826,12 @@ class SyncServer(Server):
if not user:
raise ValueError(f"cannot find user with associated client id: {user_id}")
if request.llm_config is None:
raise ValueError("llm_config is required")
if request.embedding_config is None:
raise ValueError("embedding_config is required")
# created and persist the agent state in the DB
agent_state = PersistedAgentState(
name=request.name,