diff --git a/enterprise/api/v1/views/analytics_summary.py b/enterprise/api/v1/views/analytics_summary.py index c63f6d2c8..0665dea5e 100644 --- a/enterprise/api/v1/views/analytics_summary.py +++ b/enterprise/api/v1/views/analytics_summary.py @@ -20,7 +20,7 @@ class AnalyticsSummaryView(generics.GenericAPIView): """ - API to generate a signed token for an enterprise admin to use Plotly analytics. + API to retrieve analytics summary using Xpert AI """ authentication_classes = [JwtAuthentication, SessionAuthentication] permission_classes = (IsAuthenticated,) @@ -33,9 +33,9 @@ class AnalyticsSummaryView(generics.GenericAPIView): ) def post(self, request, enterprise_uuid): """ - Generate auth token for plotly. + Perform analysis on given data and return result from Xpert AI. """ - role = 'system' + role = 'user' enterprise_customer = get_object_or_404(EnterpriseCustomer, uuid=enterprise_uuid) # Validate payload data diff --git a/enterprise/api_client/xpert_ai.py b/enterprise/api_client/xpert_ai.py index 9686e004d..3b4fce93e 100644 --- a/enterprise/api_client/xpert_ai.py +++ b/enterprise/api_client/xpert_ai.py @@ -25,13 +25,16 @@ def chat_completion(prompt, role): """ headers = { 'Content-Type': 'application/json', - 'x-api-key': settings.CHAT_COMPLETION_API_KEY } - body = {'message_list': [{'role': role, 'content': prompt},]} + body = { + 'messages': [{'role': role, 'content': prompt},], + 'client_id': settings.ENTERPRISE_ANALYSIS_CLIENT_ID, + 'system_message': settings.ENTERPRISE_ANALYSIS_SYSTEM_PROMPT + } response = requests.post( - settings.CHAT_COMPLETION_API, + settings.CHAT_COMPLETION_API_V2, headers=headers, data=json.dumps(body), timeout=(CONNECT_TIMOUET_SECONDS, READ_TIMEOUT_SECONDS)