Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate analytics_summary API to Xpert v2 #2348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
5 changes: 3 additions & 2 deletions enterprise/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,9 @@ def root(*args):
# disable indexing on history_date. Otherwise it will add new alter migrations.
SIMPLE_HISTORY_DATE_INDEX = False

CHAT_COMPLETION_API = 'https://example.com/chat/completion'
CHAT_COMPLETION_API_KEY = 'i am a key'
CHAT_COMPLETION_API_V2 = 'https://example.com/chat/completion'
ENTERPRISE_ANALYSIS_CLIENT_ID = 'test_client_id'
ENTERPRISE_ANALYSIS_SYSTEM_PROMPT = 'This is a test prompt'

LEARNER_ENGAGEMENT_PROMPT_FOR_ACTIVE_CONTRACT = 'Create learner engagement report for active contracts.'
LEARNER_ENGAGEMENT_PROMPT_FOR_NON_ACTIVE_CONTRACT = 'Create learner engagement report for non active contracts.'
Expand Down