Skip to content

Commit

Permalink
chore: migrate analytics_summary API to Xpert v2
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-sarfraz committed Mar 6, 2025
1 parent cccaf19 commit a533647
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions enterprise/api/v1/views/analytics_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions enterprise/api_client/xpert_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a533647

Please sign in to comment.