Skip to content

Commit dbeba8b

Browse files
committed
Fix final few type errors and add colang directory to pyright pre-commits
1 parent 7d235a6 commit dbeba8b

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

nemoguardrails/colang/v1_0/runtime/runtime.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -457,16 +457,18 @@ async def _run_input_rails_in_parallel(
457457
self, flows: List[str], events: List[dict]
458458
) -> ActionResult:
459459
"""Run the input rails in parallel."""
460+
460461
pre_events = [
461-
(await create_event({"_type": "StartInputRail", "flow_id": flow})).events[0]
462+
(await create_event({"_type": "StartInputRail", "flow_id": flow})).events
462463
for flow in flows
463464
]
465+
pre_events = [event[0] for event in pre_events if event]
466+
464467
post_events = [
465-
(
466-
await create_event({"_type": "InputRailFinished", "flow_id": flow})
467-
).events[0]
468+
(await create_event({"_type": "InputRailFinished", "flow_id": flow})).events
468469
for flow in flows
469470
]
471+
post_events = [event[0] for event in post_events if event]
470472

471473
return await self._run_flows_in_parallel(
472474
flows=flows, events=events, pre_events=pre_events, post_events=post_events
@@ -476,18 +478,20 @@ async def _run_output_rails_in_parallel(
476478
self, flows: List[str], events: List[dict]
477479
) -> ActionResult:
478480
"""Run the output rails in parallel."""
481+
479482
pre_events = [
480-
(await create_event({"_type": "StartOutputRail", "flow_id": flow})).events[
481-
0
482-
]
483+
(await create_event({"_type": "StartOutputRail", "flow_id": flow})).events
483484
for flow in flows
484485
]
486+
pre_events = [event[0] for event in pre_events if event]
487+
485488
post_events = [
486489
(
487490
await create_event({"_type": "OutputRailFinished", "flow_id": flow})
488-
).events[0]
491+
).events
489492
for flow in flows
490493
]
494+
post_events = [event[0] for event in post_events if event]
491495

492496
return await self._run_flows_in_parallel(
493497
flows=flows, events=events, pre_events=pre_events, post_events=post_events

nemoguardrails/colang/v2_x/runtime/runtime.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,10 @@ async def _process_start_action(
294294

295295
async def _get_action_resp(
296296
self, action_meta: Dict[str, Any], action_name: str, kwargs: Dict[str, Any]
297-
) -> Tuple[Union[str, Dict[str, Any]], str]:
297+
) -> Tuple[Union[Optional[str], Dict[str, Any]], str]:
298298
"""Interact with actions and get response from action-server and system actions."""
299299
# default response
300-
result: Union[str, Dict[str, Any]] = {}
300+
result: Union[Optional[str], Dict[str, Any]] = {}
301301
status: str = "failed"
302302
try:
303303
# Call the Actions Server if it is available.
@@ -309,6 +309,7 @@ async def _get_action_resp(
309309
result, status = await self.action_dispatcher.execute_action(
310310
action_name, kwargs
311311
)
312+
312313
else:
313314
url = urljoin(
314315
self.config.actions_server_url, "/v1/actions/run"

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pyright = "^1.1.405"
157157
include = [
158158
"nemoguardrails/rails/**",
159159
"nemoguardrails/actions/**",
160+
"nemoguardrails/colang/**",
160161
"nemoguardrails/cli/**",
161162
"nemoguardrails/kb/**",
162163
"nemoguardrails/logging/**",

0 commit comments

Comments
 (0)