Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/sentry/ai_monitoring/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"conversation.totalTokens": CONVERSATION_AGGREGATE_DEFINITIONS["totalTokens"],
}

# Documented sort fields, captured before the legacy spellings below are added.
AI_CONVERSATIONS_SORT_FIELDS = tuple(AI_CONVERSATIONS_FIELDS)

AI_CONVERSATIONS_LEGACY_ALIASES = {
"conversation.messages": "conversation.llmCalls",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rest_framework.response import Response
from sentry_sdk import traces

from sentry.ai_monitoring.constants import AI_CONVERSATIONS_FIELDS
from sentry.ai_monitoring.constants import AI_CONVERSATIONS_FIELDS, AI_CONVERSATIONS_SORT_FIELDS
from sentry.ai_monitoring.conversation_aggregates import (
CONVERSATION_AGGREGATE_COLUMNS,
AIConversationAggregates,
Expand Down Expand Up @@ -103,6 +103,18 @@ class AIConversationResponse(AIConversationData):
),
)

AI_CONVERSATIONS_SORT_PARAM = OpenApiParameter(
name="sort",
location="query",
required=False,
type=str,
enum=[sort for field in AI_CONVERSATIONS_SORT_FIELDS for sort in (field, f"-{field}")],
description=(
"The field to sort conversations by. Prefix it with `-` to sort in descending order. "
"Defaults to `-conversation.age`, most recent first."
),
)

AI_CONVERSATIONS_PER_PAGE_PARAM = OpenApiParameter(
name="per_page",
location="query",
Expand Down Expand Up @@ -154,6 +166,7 @@ class OrganizationAIConversationsEndpoint(OrganizationEventsEndpointBase):
GlobalParams.START,
GlobalParams.END,
AI_CONVERSATIONS_QUERY_PARAM,
AI_CONVERSATIONS_SORT_PARAM,
CursorQueryParam,
AI_CONVERSATIONS_PER_PAGE_PARAM,
],
Expand Down
Loading