Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos committed Jun 19, 2024
1 parent db4be93 commit c92fac4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
8 changes: 8 additions & 0 deletions backend/app/api/assistants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions backend/app/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"],
Expand Down
6 changes: 3 additions & 3 deletions backend/tests/unit_tests/app/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit c92fac4

Please sign in to comment.