diff --git a/backend/app/api/assistants.py b/backend/app/api/assistants.py index 17ad02f3..b8ea7e53 100644 --- a/backend/app/api/assistants.py +++ b/backend/app/api/assistants.py @@ -51,6 +51,10 @@ async def create_assistant( payload: AssistantPayload, ) -> Assistant: """Create an assistant.""" + if not payload.config.get("configurable", {}).get("type"): + raise HTTPException( + status_code=400, detail="Assistant config must have configurable.type field" + ) return await storage.create_assistant( user["user_id"], name=payload.name, @@ -66,6 +70,10 @@ async def patch_assistant( payload: AssistantPayload, ) -> Assistant: """Create or update an assistant.""" + if payload.config and not payload.config.get("configurable", {}).get("type"): + raise HTTPException( + status_code=400, detail="Assistant config must have configurable.type field" + ) return await storage.patch_assistant( user["user_id"], aid, diff --git a/backend/app/storage.py b/backend/app/storage.py index f874aa5f..594b458a 100644 --- a/backend/app/storage.py +++ b/backend/app/storage.py @@ -85,7 +85,12 @@ async def create_assistant( async def patch_assistant( - user_id: str, assistant_id: str, *, name: str, config: dict, public: bool = False + user_id: str, + assistant_id: str, + *, + name: Optional[str], + config: Optional[dict], + public: Optional[bool], ) -> Assistant: """Patch an assistant. @@ -101,9 +106,11 @@ async def patch_assistant( """ assistant = await get_api_client().assistants.update( assistant_id, - graph_id=config["configurable"]["type"], + graph_id=config["configurable"]["type"] if config else None, config=config, - metadata={"user_id": user_id, "public": public, "name": name}, + metadata={"user_id": user_id, "public": public or False, "name": name} + if name or public + else None, ) return Assistant( assistant_id=assistant["assistant_id"], diff --git a/backend/tests/unit_tests/app/test_app.py b/backend/tests/unit_tests/app/test_app.py index 40e315fe..9830d511 100644 --- a/backend/tests/unit_tests/app/test_app.py +++ b/backend/tests/unit_tests/app/test_app.py @@ -57,14 +57,14 @@ async def test_list_and_create_assistants() -> None: response = await client.patch( f"/api/assistants/{aid}", - json={"name": "bobby", "config": {}, "public": False}, + json={"name": "hmmmm"}, headers=headers, ) assert _project(response.json(), exclude_keys=["updated_at", "user_id"]) == { "assistant_id": aid, - "config": {}, - "name": "bobby", + "config": {"configurable": {"type": "chatbot"}}, + "name": "hmmmm", "public": False, }