Skip to content

Commit

Permalink
Merge pull request #1901 from openedx/saleem-latif/ENT-7363
Browse files Browse the repository at this point in the history
ENT-7363: Fixed ChatGPT prompt and a few model modifications for better readability for admins.
  • Loading branch information
saleem-latif authored Oct 6, 2023
2 parents d676fcd + 16f97de commit fb316b8
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Change Log
Unreleased
----------
[4.5.7]
-------
fix: Fixed ChatGPT prompt and a few model modifications for better readability for admins.

[4.5.6]
-------
feat: Added logs for learner completion data post request[moodle]
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.5.6"
__version__ = "4.5.7"
5 changes: 3 additions & 2 deletions enterprise/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,9 @@ class ChatGPTResponseAdmin(admin.ModelAdmin):
"""

model = models.ChatGPTResponse
list_display = ('uuid', 'enterprise_customer', 'prompt_hash', )
readonly_fields = ('prompt', 'response', 'prompt_hash', )
list_display = ('uuid', 'prompt_type', 'enterprise_customer', 'prompt_hash', 'created', )
readonly_fields = ('prompt_type', 'prompt', 'response', 'prompt_hash', 'created', 'modified', )
list_filter = ('prompt_type', )


@admin.register(models.EnterpriseCustomerSsoConfiguration)
Expand Down
2 changes: 1 addition & 1 deletion enterprise/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def generate_prompt_for_learner_engagement_summary(engagement_data):
'hours': engagement_data['hours'],
'hours_delta': delta_format(current=engagement_data['hours'], prior=engagement_data['hours_prior']),
'passed': engagement_data['passed'],
'passed_delta': delta_format(current=engagement_data['hours'], prior=engagement_data['passed_prior']),
'passed_delta': delta_format(current=engagement_data['passed'], prior=engagement_data['passed_prior']),
}

# If active contract (or unknown).
Expand Down
8 changes: 6 additions & 2 deletions enterprise/api/v1/views/analytics_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def post(self, request, enterprise_uuid):
learner_engagement_prompt = generate_prompt_for_learner_engagement_summary(prompt_data['learner_engagement'])

return Response(data={
'learner_progress': ChatGPTResponse.get_or_create(learner_progress_prompt, role, enterprise_customer),
'learner_engagement': ChatGPTResponse.get_or_create(learner_engagement_prompt, role, enterprise_customer),
'learner_progress': ChatGPTResponse.get_or_create(
learner_progress_prompt, role, enterprise_customer, ChatGPTResponse.LEARNER_PROGRESS,
),
'learner_engagement': ChatGPTResponse.get_or_create(
learner_engagement_prompt, role, enterprise_customer, ChatGPTResponse.LEARNER_ENGAGEMENT,
),
})
22 changes: 22 additions & 0 deletions enterprise/migrations/0191_auto_20231006_0948.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.21 on 2023-10-06 09:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('enterprise', '0190_auto_20231003_0719'),
]

operations = [
migrations.AlterModelOptions(
name='chatgptresponse',
options={'verbose_name': 'ChatGPT Response', 'verbose_name_plural': 'ChatGPT Responses'},
),
migrations.AddField(
model_name='chatgptresponse',
name='prompt_type',
field=models.CharField(choices=[('learner_progress', 'Learner progress'), ('learner_engagement', 'Learner engagement')], help_text='Prompt type.', max_length=32, null=True),
),
]
16 changes: 15 additions & 1 deletion enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3655,6 +3655,12 @@ class ChatGPTResponse(TimeStampedModel):
.. no_pii:
"""
LEARNER_PROGRESS = 'learner_progress'
LEARNER_ENGAGEMENT = 'learner_engagement'
PROMPT_TYPES = [
(LEARNER_PROGRESS, 'Learner progress'),
(LEARNER_ENGAGEMENT, 'Learner engagement'),
]
uuid = models.UUIDField(primary_key=True, default=uuid4, editable=False)

enterprise_customer = models.ForeignKey(
Expand All @@ -3671,6 +3677,12 @@ class ChatGPTResponse(TimeStampedModel):
prompt = models.TextField(help_text=_('ChatGPT prompt.'))
prompt_hash = models.CharField(max_length=32, editable=False)
response = models.TextField(help_text=_('ChatGPT response.'))
prompt_type = models.CharField(choices=PROMPT_TYPES, help_text=_('Prompt type.'), max_length=32, null=True)

class Meta:
app_label = 'enterprise'
verbose_name = _('ChatGPT Response')
verbose_name_plural = _('ChatGPT Responses')

def save(self, *args, **kwargs):
"""
Expand All @@ -3680,7 +3692,7 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)

@classmethod
def get_or_create(cls, prompt, role, enterprise_customer):
def get_or_create(cls, prompt, role, enterprise_customer, prompt_type):
"""
Get or create ChatGPT response against given prompt.
Expand All @@ -3691,6 +3703,7 @@ def get_or_create(cls, prompt, role, enterprise_customer):
prompt (str): OpenAI prompt.
role (str): ChatGPT role to assume for the prompt.
enterprise_customer (EnterpriseCustomer): Enterprise customer UUId making the request.
prompt_type (str): Prompt type, e.g. learner_progress or learner_engagement etc.
Returns:
(str): Response against the given prompt.
Expand All @@ -3702,6 +3715,7 @@ def get_or_create(cls, prompt, role, enterprise_customer):
enterprise_customer=enterprise_customer,
prompt=prompt,
response=response,
prompt_type=prompt_type,
)
return response
else:
Expand Down

0 comments on commit fb316b8

Please sign in to comment.