Skip to content

Commit cbc8eb4

Browse files
committed
Cleanup
1 parent ed7dac3 commit cbc8eb4

File tree

1 file changed

+12
-40
lines changed

1 file changed

+12
-40
lines changed

app/agents/voice/automatic/tools/juspay/analytics.py

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -199,57 +199,25 @@ async def _make_list_orders_api_request(
199199

200200
except Exception as e:
201201
logger.error(
202-
f"Tool Error: [list_orders_request] Error converting time for Juspay API: {e}"
202+
f"Tool Error: [list_orders_api_request] Error converting time for Juspay API: {e}"
203203
)
204204
return ApiFailure(
205205
error={
206-
"Tool Error": f" [list_orders_request] Invalid time format provided. Please use 'YYYY-MM-DD HH:MM:SS' in IST. Error: {e}"
206+
"Tool Error": f"[list_orders_api_request] Invalid time format provided. Please use 'YYYY-MM-DD HH:MM:SS' in IST. Error: {e}"
207207
}
208208
)
209209

210-
time_field = (
211-
"order_created_at"
212-
if payload_details.get("domain") == "ordersELS"
213-
else "date_created"
214-
)
215-
216210
end_time_str = end_time_utc.strftime("%Y-%m-%dT%H:%M:%SZ")
217211
start_time_str = start_time_utc.strftime("%Y-%m-%dT%H:%M:%SZ")
218212

219-
end_time_dt = end_time_utc.fromisoformat(end_time_str.replace("Z", "+00:00"))
220-
start_time_dt = start_time_utc.fromisoformat(start_time_str.replace("Z", "+00:00"))
221-
222-
if end_time_dt.tzinfo is None:
223-
end_time_dt = end_time_dt.replace(tzinfo=timezone.utc)
224-
if start_time_dt.tzinfo is None:
225-
start_time_dt = start_time_dt.replace(tzinfo=timezone.utc)
226-
227-
date_from_ts = int(start_time_dt.timestamp())
228-
date_to_ts = int(end_time_dt.timestamp())
229-
230-
qFilters = {
231-
"and": {
232-
"right": {
233-
"field": time_field,
234-
"condition": "LessThanEqual",
235-
"val": str(date_to_ts),
236-
},
237-
"left": {
238-
"field": time_field,
239-
"condition": "GreaterThanEqual",
240-
"val": str(date_from_ts),
241-
},
242-
}
243-
}
244-
245213
full_payload = {
246214
**payload_details,
247215
"filters": {"dateCreated": {"lte": end_time_str, "gte": start_time_str}},
248-
"qFilters": qFilters,
249216
}
250217
headers = {
251218
"Content-Type": "application/json",
252219
"x-web-logintoken": euler_token,
220+
"user-agent": "ClairvoyanceApp/1.0",
253221
}
254222

255223
logger.info(
@@ -280,7 +248,7 @@ async def _make_list_orders_api_request(
280248
)
281249
return ApiFailure(
282250
error={
283-
"Tool Error": f" [list_orders_api_request] Juspay API error: {e.response.status_code}",
251+
"Tool Error": f"[list_orders_api_request] Juspay API error: {e.response.status_code}",
284252
"details": e.response.text,
285253
}
286254
)
@@ -290,7 +258,7 @@ async def _make_list_orders_api_request(
290258
)
291259
return ApiFailure(
292260
error={
293-
"Tool Error": f" [list_orders_api_request] An unexpected error occurred: {e}"
261+
"Tool Error": f"[list_orders_api_request] An unexpected error occurred: {e}"
294262
}
295263
)
296264

@@ -571,11 +539,15 @@ def get_success_transactional_data_by_time(
571539
def get_last_n_orders(params: FunctionCallParams):
572540
logger.info(f"Fetching last placed order with params: {params.arguments}")
573541

542+
limit = params.arguments.get("limit", 1)
543+
if limit > 100:
544+
limit = 100
545+
574546
analytics_payload = {
575547
"domain": "txnsELS",
576548
"offset": 0,
577-
"sortDimension": "order_created_at",
578-
"limit": params.arguments.get("limit", 1),
549+
"sortDimension": "date_created",
550+
"limit": limit,
579551
}
580552

581553
return _make_list_orders_api_request(params, analytics_payload)
@@ -1822,7 +1794,7 @@ async def update_euler_offer(params: FunctionCallParams):
18221794

18231795
get_last_n_orders_function = FunctionSchema(
18241796
name="get_last_n_orders",
1825-
description="Retrieves the most recently placed orders within a specified time range, sorted by creation time in descending order.",
1797+
description="Retrieves the most recently placed orders within a specified time range, sorted by creation time in descending order. Maximum limit: 100",
18261798
properties={
18271799
**time_input_schema["properties"],
18281800
"limit": {

0 commit comments

Comments
 (0)