Skip to content

Commit ab4dec0

Browse files
committed
remove superfluous comments and use the constants everywhere
1 parent e7bf105 commit ab4dec0

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

sentry_sdk/ai/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ class GEN_AI_ALLOWED_MESSAGE_ROLES:
1717
TOOL_CALL = "tool_call"
1818

1919

20-
# Gen AI message role reverse mapping showing allowed target roles and their source variants
2120
GEN_AI_MESSAGE_ROLE_REVERSE_MAPPING = {
2221
GEN_AI_ALLOWED_MESSAGE_ROLES.SYSTEM: ["system"],
2322
GEN_AI_ALLOWED_MESSAGE_ROLES.USER: ["user"],
2423
GEN_AI_ALLOWED_MESSAGE_ROLES.ASSISTANT: ["assistant", "ai"],
2524
GEN_AI_ALLOWED_MESSAGE_ROLES.TOOL_CALL: ["tool_call"],
2625
}
2726

28-
# Convert reverse mapping to actual mapping for efficient lookups
2927
GEN_AI_MESSAGE_ROLE_MAPPING = {}
3028
for target_role, source_roles in GEN_AI_MESSAGE_ROLE_REVERSE_MAPPING.items():
3129
for source_role in source_roles:

sentry_sdk/integrations/anthropic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def _set_input_data(span, kwargs, integration):
144144
else:
145145
normalized_messages.append(message)
146146

147-
# Further normalize message roles to standard gen_ai values
148147
role_normalized_messages = normalize_message_roles(normalized_messages)
149148
set_data_normalized(
150149
span,

sentry_sdk/integrations/langgraph.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ def new_invoke(self, *args, **kwargs):
180180
):
181181
input_messages = _parse_langgraph_messages(args[0])
182182
if input_messages:
183-
# Normalize message roles to standard gen_ai values
184183
normalized_input_messages = normalize_message_roles(input_messages)
185184
set_data_normalized(
186185
span,
@@ -232,7 +231,6 @@ async def new_ainvoke(self, *args, **kwargs):
232231
):
233232
input_messages = _parse_langgraph_messages(args[0])
234233
if input_messages:
235-
# Normalize message roles to standard gen_ai values
236234
normalized_input_messages = normalize_message_roles(input_messages)
237235
set_data_normalized(
238236
span,

sentry_sdk/integrations/openai.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ def _set_input_data(span, kwargs, operation, integration):
182182
and should_send_default_pii()
183183
and integration.include_prompts
184184
):
185-
# Normalize message roles to standard gen_ai values
186185
normalized_messages = normalize_message_roles(messages)
187186
set_data_normalized(
188187
span, SPANDATA.GEN_AI_REQUEST_MESSAGES, normalized_messages, unpack=False

sentry_sdk/integrations/openai_agents/spans/invoke_agent.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def invoke_agent_span(context, agent, kwargs):
6060
)
6161

6262
if len(messages) > 0:
63-
# Normalize message roles to standard gen_ai values
6463
normalized_messages = normalize_message_roles(messages)
6564
set_data_normalized(
6665
span,

sentry_sdk/integrations/openai_agents/utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sentry_sdk
22
from sentry_sdk.ai.utils import (
3+
GEN_AI_ALLOWED_MESSAGE_ROLES,
34
normalize_message_roles,
45
set_data_normalized,
56
normalize_message_role,
@@ -104,7 +105,7 @@ def _set_input_data(span, get_response_kwargs):
104105
if system_instructions:
105106
request_messages.append(
106107
{
107-
"role": "system",
108+
"role": GEN_AI_ALLOWED_MESSAGE_ROLES.SYSTEM,
108109
"content": [{"type": "text", "text": system_instructions}],
109110
}
110111
)
@@ -120,9 +121,19 @@ def _set_input_data(span, get_response_kwargs):
120121
)
121122
else:
122123
if message.get("type") == "function_call":
123-
request_messages.append({"role": "assistant", "content": [message]})
124+
request_messages.append(
125+
{
126+
"role": GEN_AI_ALLOWED_MESSAGE_ROLES.ASSISTANT,
127+
"content": [message],
128+
}
129+
)
124130
elif message.get("type") == "function_call_output":
125-
request_messages.append({"role": "tool", "content": [message]})
131+
request_messages.append(
132+
{
133+
"role": GEN_AI_ALLOWED_MESSAGE_ROLES.TOOL_CALL,
134+
"content": [message],
135+
}
136+
)
126137

127138
set_data_normalized(
128139
span,

0 commit comments

Comments
 (0)