Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nemoguardrails/actions/llm/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def init(self):
self._init_flows_index(),
)

def _extract_user_message_example(self, flow: Flow):
def _extract_user_message_example(self, flow: Flow) -> None:
"""Heuristic to extract user message examples from a flow."""
elements = [
item
Expand Down
2 changes: 1 addition & 1 deletion nemoguardrails/tracing/interaction_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ def extract_interaction_log(
return InteractionLog(
id=interaction_output.id,
activated_rails=generation_log.activated_rails,
events=generation_log.internal_events,
events=generation_log.internal_events or [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why Pyright is complaining about this as events is default factory of List

trace=spans,
)
22 changes: 8 additions & 14 deletions nemoguardrails/tracing/span_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def extract_spans(
self, activated_rails: List[ActivatedRail]
) -> List[Union[SpanLegacy, SpanOpentelemetry]]:
"""Extract v1 spans from activated rails."""
spans: List[SpanLegacy] = []
spans: List[Union[SpanLegacy, SpanOpentelemetry]] = []
if not activated_rails:
return spans

Expand Down Expand Up @@ -165,9 +165,9 @@ def __init__(

def extract_spans(
self, activated_rails: List[ActivatedRail]
) -> List[Union[SpanLegacy, SpanOpentelemetry, TypedSpan]]:
) -> List[Union[SpanLegacy, SpanOpentelemetry]]:
"""Extract v2 spans from activated rails with OpenTelemetry attributes."""
spans: List[TypedSpan] = []
spans: List[Union[SpanLegacy, SpanOpentelemetry]] = []
ref_time = activated_rails[0].started_at or 0.0

interaction_span = InteractionSpan(
Expand Down Expand Up @@ -219,17 +219,11 @@ def extract_spans(
for k, v in (action.action_params or {}).items()
if isinstance(v, (str, int, float, bool))
},
error=True if hasattr(action, "error") and action.error else None,
error_type=(
type(action.error).__name__
if hasattr(action, "error") and action.error
else None
),
error_message=(
str(action.error)
if hasattr(action, "error") and action.error
else None
),
# TODO: There is no error field in ExecutedAction. The fields below are defined on BaseSpan but
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure here - maybe @Pouyanpi can provide some feedback quicker than me.

# will never be set if using an ActivatedRail object to populate an ActivatedRail object.
error=None,
error_type=None,
error_message=None,
)
spans.append(action_span)

Expand Down
4 changes: 4 additions & 0 deletions nemoguardrails/tracing/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def generate_interaction_log(
if generation_log is None:
generation_log = self._generation_log

# At this point generation_log should not be None since it comes from self._generation_log
if generation_log is None:
raise Exception("Can't generate interaction log without Generation log")

interaction_log = extract_interaction_log(
interaction_output,
generation_log,
Expand Down