pre-commit changes

This commit is contained in:
Sarthak Deshpande 2024-10-22 18:24:03 +05:30
parent 965bab950c
commit c87c5b568a

View file

@ -138,38 +138,24 @@ class MetaReferenceAgentsImpl(Agents):
async for event in agent.create_and_execute_turn(request):
yield event
async def get_agents_turn(self, agent_id: str, session_id: str, turn_id: str) -> Turn:
turn = await self.persistence_store.get(f"session:{agent_id}:{session_id}:{turn_id}")
try:
turn = json.loads(turn)
except json.JSONDecodeError as e:
raise ValueError(
f"Could not JSON decode turn for {turn_id}"
) from e
try:
turn = Turn(**turn)
except Exception as e:
raise ValueError(
f"Could not validate(?) Turns for {turn_id}"
) from e
async def get_agents_turn(
self, agent_id: str, session_id: str, turn_id: str
) -> Turn:
turn = await self.persistence_store.get(
f"session:{agent_id}:{session_id}:{turn_id}"
)
turn = json.loads(turn)
turn = Turn(**turn)
return turn
async def get_agents_step(
self, agent_id: str, session_id: str, turn_id: str, step_id: str
) -> AgentStepResponse:
turn = await self.persistence_store.get(f"session:{agent_id}:{session_id}:{turn_id}")
try:
turn = json.loads(turn)
except json.JSONDecodeError as e:
raise ValueError(
f"Could not JSON decode turn for {turn_id}"
) from e
try:
turn = Turn(**turn)
except Exception as e:
raise ValueError(
f"Could not validate(?) Turns for {turn_id}"
) from e
turn = await self.persistence_store.get(
f"session:{agent_id}:{session_id}:{turn_id}"
)
turn = json.loads(turn)
turn = Turn(**turn)
steps = turn.steps
for step in steps:
if step.step_id == step_id:
@ -183,44 +169,25 @@ class MetaReferenceAgentsImpl(Agents):
turn_ids: Optional[List[str]] = None,
) -> Session:
session = await self.persistence_store.get(f"session:{agent_id}:{session_id}")
try:
session = Session(**json.loads(session))
except json.JSONDecodeError as e:
raise ValueError(
f"Could not JSON decode session for {agent_id} and {session_id}"
) from e
session = Session(**json.loads(session))
turns = []
if turn_ids:
for turn_id in turn_ids:
turn = await self.persistence_store.get(f"session:{agent_id}:{session_id}:{turn_id}")
try:
turn = json.loads(turn)
except json.JSONDecodeError as e:
raise ValueError(
f"Could not JSON decode session for {agent_id} and {session_id}"
) from e
try:
turn = Turn(**turn)
except Exception as e:
raise ValueError(
f"Could not validate(?) Turns for {turn_id}"
) from e
turn = await self.persistence_store.get(
f"session:{agent_id}:{session_id}:{turn_id}"
)
turn = json.loads(turn)
turn = Turn(**turn)
turns.append(turn)
return Session(
session_name=session.session_name,
session_id=session_id,
turns=turns if turns else [],
started_at=session.started_at
started_at=session.started_at,
)
async def delete_agents_session(self, agent_id: str, session_id: str) -> None:
try:
await self.persistence_store.delete(f"session:{agent_id}:{session_id}")
except:
raise ValueError("Session Key Not Found")
await self.persistence_store.delete(f"session:{agent_id}:{session_id}")
async def delete_agents(self, agent_id: str) -> None:
try:
await self.persistence_store.delete(f"agent:{agent_id}")
except:
raise ValueError("Agent Key not found")
await self.persistence_store.delete(f"agent:{agent_id}")