mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-29 23:29:43 +00:00
pre-commit changes
This commit is contained in:
parent
965bab950c
commit
c87c5b568a
1 changed files with 22 additions and 55 deletions
|
@ -138,38 +138,24 @@ class MetaReferenceAgentsImpl(Agents):
|
||||||
async for event in agent.create_and_execute_turn(request):
|
async for event in agent.create_and_execute_turn(request):
|
||||||
yield event
|
yield event
|
||||||
|
|
||||||
async def get_agents_turn(self, agent_id: str, session_id: str, turn_id: str) -> Turn:
|
async def get_agents_turn(
|
||||||
turn = await self.persistence_store.get(f"session:{agent_id}:{session_id}:{turn_id}")
|
self, agent_id: str, session_id: str, turn_id: str
|
||||||
try:
|
) -> Turn:
|
||||||
turn = json.loads(turn)
|
turn = await self.persistence_store.get(
|
||||||
except json.JSONDecodeError as e:
|
f"session:{agent_id}:{session_id}:{turn_id}"
|
||||||
raise ValueError(
|
)
|
||||||
f"Could not JSON decode turn for {turn_id}"
|
turn = json.loads(turn)
|
||||||
) from e
|
turn = Turn(**turn)
|
||||||
try:
|
|
||||||
turn = Turn(**turn)
|
|
||||||
except Exception as e:
|
|
||||||
raise ValueError(
|
|
||||||
f"Could not validate(?) Turns for {turn_id}"
|
|
||||||
) from e
|
|
||||||
return turn
|
return turn
|
||||||
|
|
||||||
async def get_agents_step(
|
async def get_agents_step(
|
||||||
self, agent_id: str, session_id: str, turn_id: str, step_id: str
|
self, agent_id: str, session_id: str, turn_id: str, step_id: str
|
||||||
) -> AgentStepResponse:
|
) -> AgentStepResponse:
|
||||||
turn = await self.persistence_store.get(f"session:{agent_id}:{session_id}:{turn_id}")
|
turn = await self.persistence_store.get(
|
||||||
try:
|
f"session:{agent_id}:{session_id}:{turn_id}"
|
||||||
turn = json.loads(turn)
|
)
|
||||||
except json.JSONDecodeError as e:
|
turn = json.loads(turn)
|
||||||
raise ValueError(
|
turn = Turn(**turn)
|
||||||
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
|
|
||||||
steps = turn.steps
|
steps = turn.steps
|
||||||
for step in steps:
|
for step in steps:
|
||||||
if step.step_id == step_id:
|
if step.step_id == step_id:
|
||||||
|
@ -183,44 +169,25 @@ class MetaReferenceAgentsImpl(Agents):
|
||||||
turn_ids: Optional[List[str]] = None,
|
turn_ids: Optional[List[str]] = None,
|
||||||
) -> Session:
|
) -> Session:
|
||||||
session = await self.persistence_store.get(f"session:{agent_id}:{session_id}")
|
session = await self.persistence_store.get(f"session:{agent_id}:{session_id}")
|
||||||
try:
|
session = Session(**json.loads(session))
|
||||||
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
|
|
||||||
turns = []
|
turns = []
|
||||||
if turn_ids:
|
if turn_ids:
|
||||||
for turn_id in turn_ids:
|
for turn_id in turn_ids:
|
||||||
turn = await self.persistence_store.get(f"session:{agent_id}:{session_id}:{turn_id}")
|
turn = await self.persistence_store.get(
|
||||||
try:
|
f"session:{agent_id}:{session_id}:{turn_id}"
|
||||||
turn = json.loads(turn)
|
)
|
||||||
except json.JSONDecodeError as e:
|
turn = json.loads(turn)
|
||||||
raise ValueError(
|
turn = Turn(**turn)
|
||||||
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
|
|
||||||
turns.append(turn)
|
turns.append(turn)
|
||||||
return Session(
|
return Session(
|
||||||
session_name=session.session_name,
|
session_name=session.session_name,
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
turns=turns if turns else [],
|
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:
|
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}")
|
||||||
await self.persistence_store.delete(f"session:{agent_id}:{session_id}")
|
|
||||||
except:
|
|
||||||
raise ValueError("Session Key Not Found")
|
|
||||||
|
|
||||||
async def delete_agents(self, agent_id: str) -> None:
|
async def delete_agents(self, agent_id: str) -> None:
|
||||||
try:
|
await self.persistence_store.delete(f"agent:{agent_id}")
|
||||||
await self.persistence_store.delete(f"agent:{agent_id}")
|
|
||||||
except:
|
|
||||||
raise ValueError("Agent Key not found")
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue