@@ -63,13 +63,15 @@ class TraceExplorerAIQuery(OrganizationEndpoint):
63
63
@staticmethod
64
64
def post (request : Request , organization : Organization ) -> Response :
65
65
"""
66
- Checks if we are able to run Autofix on the given group .
66
+ Request to translate a natural language query into a sentry EQS query .
67
67
"""
68
68
if not request .user .is_authenticated :
69
69
return Response (status = status .HTTP_400_BAD_REQUEST )
70
70
71
71
project_ids = [int (x ) for x in request .data .get ("project_ids" , [])]
72
72
natural_language_query = request .data .get ("natural_language_query" )
73
+ limit = request .data .get ("limit" , 1 )
74
+ use_flyout = request .data .get ("use_flyout" , True )
73
75
74
76
if len (project_ids ) == 0 or not natural_language_query :
75
77
return Response (
@@ -102,15 +104,50 @@ def post(request: Request, organization: Organization) -> Response:
102
104
)
103
105
data = send_translate_request (organization .id , project_ids , natural_language_query )
104
106
107
+ # XXX: This is a fallback to support the old response format until we fully support using multiple queries on the frontend
108
+ if "responses" in data and use_flyout :
109
+ if not data ["responses" ]:
110
+ logger .info ("No results found for query" )
111
+ return Response (
112
+ {"detail" : "No results found for query" },
113
+ status = status .HTTP_404_NOT_FOUND ,
114
+ )
115
+ data = data ["responses" ][0 ]
116
+ if "responses" not in data :
117
+ return Response (
118
+ {
119
+ "status" : "ok" ,
120
+ "query" : data ["query" ], # the sentry EQS query as a string
121
+ "stats_period" : data ["stats_period" ],
122
+ "group_by" : list (data .get ("group_by" , [])),
123
+ "visualization" : list (
124
+ data .get ("visualization" )
125
+ ), # [{chart_type: 1, y_axes: ["count_message"]}, ...]
126
+ "sort" : data ["sort" ],
127
+ }
128
+ )
129
+
130
+ data = data ["responses" ][:limit ]
131
+
132
+ if len (data ) == 0 :
133
+ logger .info ("No results found for query" )
134
+ return Response (
135
+ {"detail" : "No results found for query" },
136
+ status = status .HTTP_404_NOT_FOUND ,
137
+ )
138
+
105
139
return Response (
106
140
{
107
141
"status" : "ok" ,
108
- "query" : data ["query" ], # the sentry EQS query as a string
109
- "stats_period" : data ["stats_period" ],
110
- "group_by" : list (data .get ("group_by" , [])),
111
- "visualization" : list (
112
- data .get ("visualization" )
113
- ), # [{chart_type: 1, y_axes: ["count_message"]}, ...]
114
- "sort" : data ["sort" ],
142
+ "queries" : [
143
+ {
144
+ "query" : query ["query" ],
145
+ "stats_period" : query ["stats_period" ],
146
+ "group_by" : list (query .get ("group_by" , [])),
147
+ "visualization" : list (query .get ("visualization" )),
148
+ "sort" : query ["sort" ],
149
+ }
150
+ for query in data
151
+ ],
115
152
}
116
153
)
0 commit comments