Skip to content

Commit

Permalink
Feat: playground agent rename endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
manthanguptaa committed Sep 19, 2024
1 parent 68199aa commit 29031aa
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions phi/playground/playground.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import List, Optional, Generator, Any, Dict, cast

from fastapi import FastAPI, HTTPException
from fastapi import FastAPI, HTTPException, status
from fastapi.routing import APIRouter
from fastapi.responses import StreamingResponse
from fastapi.responses import StreamingResponse, JSONResponse

from pydantic import BaseModel
from phi.agent.agent import Agent, RunResponse, Tool, Toolkit, Function
Expand Down Expand Up @@ -35,6 +35,11 @@ class AgentRunRequest(BaseModel):
user_id: Optional[str] = None


class AgentRenameRequest(BaseModel):
name: str
agent_id: str


class Playground:
def __init__(
self,
Expand Down Expand Up @@ -131,6 +136,15 @@ def agent_chat(body: AgentRunRequest):
run_response = cast(RunResponse, agent.run(body.message, stream=False))
return run_response.model_dump_json()

@playground_routes.post("/agent/rename")
def agent_rename(body: AgentRenameRequest):
for agent in self.agents:
print(agent.session_name)
if agent.agent_id == body.agent_id:
agent.rename_session(body.name)
return JSONResponse(content={"message": f"successfully renamed agent {agent.name}"})
return JSONResponse(status_code=404, content=f"couldn't find agent with {body.agent_id}")

return playground_routes

def get_api_app(self) -> FastAPI:
Expand Down

0 comments on commit 29031aa

Please sign in to comment.