Skip to content

Commit

Permalink
Merge pull request #1511 from the-deep/feature/summarization-payload-…
Browse files Browse the repository at this point in the history
…update

Summarization Payload Update
  • Loading branch information
subinasr authored Jul 22, 2024
2 parents d8bd365 + 7f1d905 commit a9d342d
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 8 deletions.
32 changes: 32 additions & 0 deletions apps/analysis/migrations/0016_auto_20240716_0943.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.2.25 on 2024-07-16 09:43

from django.db import migrations, models


def delete_ids(apps, schema_editor):
AutomaticSummary = apps.get_model('analysis', 'AutomaticSummary')
AutomaticSummary.objects.all().delete()


class Migration(migrations.Migration):

dependencies = [
('analysis', '0015_auto_20240531_0504'),
]

operations = [
migrations.RunPython(
delete_ids,
reverse_code=migrations.RunPython.noop,
),
migrations.AddField(
model_name='automaticsummary',
name='analytical_statement',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='automaticsummary',
name='information_gap',
field=models.TextField(blank=True),
),
]
23 changes: 23 additions & 0 deletions apps/analysis/migrations/0017_auto_20240716_1050.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.25 on 2024-07-16 10:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('analysis', '0016_auto_20240716_0943'),
]

operations = [
migrations.AlterField(
model_name='automaticsummary',
name='analytical_statement',
field=models.TextField(),
),
migrations.AlterField(
model_name='automaticsummary',
name='information_gap',
field=models.TextField(),
),
]
2 changes: 2 additions & 0 deletions apps/analysis/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ def save(self, *args, **kwargs):

class AutomaticSummary(EntriesCollectionNlpTriggerBase):
summary = models.TextField()
analytical_statement = models.TextField()
information_gap = models.TextField()
widget_tags = ArrayField(models.CharField(max_length=100), default=list)


Expand Down
2 changes: 2 additions & 0 deletions apps/analysis/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ class Meta:
only_fields = (
'id',
'summary',
'analytical_statement',
'information_gap'
)

status = graphene.Field(AutomaticSummaryStatusEnum, required=True)
Expand Down
22 changes: 16 additions & 6 deletions apps/analysis/tests/test_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class TestAnalysisNlpMutationSchema(GraphQLTestCase):
id
status
summary
informationGap
analyticalStatement
}
}
}
Expand Down Expand Up @@ -514,14 +516,18 @@ def _query_check(_id):
]

# -- Callback test (Mocking NLP part)
SAMPLE_SUMMARY_TEXT = 'SAMPLE SUMMARY TEXT'
RequestHelperMock.return_value.get_text.return_value = SAMPLE_SUMMARY_TEXT
SAMPLE_SUMMARY_JSON = {
"summary": "Sample summary text",
"info_gaps": "Sample Info gaps",
"analytical_statement": "Sample Analytical Statement"
}
RequestHelperMock.return_value.json.return_value = SAMPLE_SUMMARY_JSON

callback_url = '/api/v1/callback/analysis-automatic-summary/'

data = {
'client_id': 'invalid-id',
'presigned_s3_url': 'https://random-domain.com/random-url.txt',
'presigned_s3_url': 'https://random-domain.com/random-url.json',
'status': DeeplServerBaseCallbackSerializer.Status.SUCCESS.value,
}
response = self.client.post(callback_url, data)
Expand All @@ -534,20 +540,24 @@ def _query_check(_id):

a_summary.refresh_from_db()
assert a_summary.status == AutomaticSummary.Status.SUCCESS.value
assert a_summary.summary == SAMPLE_SUMMARY_TEXT
assert a_summary.summary == SAMPLE_SUMMARY_JSON['summary']
assert a_summary.information_gap == SAMPLE_SUMMARY_JSON['info_gaps']
assert a_summary.analytical_statement == SAMPLE_SUMMARY_JSON['analytical_statement']

# -- Check existing instance if provided until threshold is over
response_result = _mutation_check(minput, okay=True)['data']['project']['triggerAnalysisAutomaticSummary']['result']
assert response_result['id'] == a_summary_id
assert response_result['summary'] == SAMPLE_SUMMARY_TEXT
assert response_result['summary'] == SAMPLE_SUMMARY_JSON['summary']
assert response_result['informationGap'] == SAMPLE_SUMMARY_JSON['info_gaps']
assert response_result['analyticalStatement'] == SAMPLE_SUMMARY_JSON['analytical_statement']

a_summary.created_at = self.PATCHER_NOW_VALUE -\
datetime.timedelta(hours=AutomaticSummary.CACHE_THRESHOLD_HOURS + 1)
a_summary.save()

response_result = _mutation_check(minput, okay=True)['data']['project']['triggerAnalysisAutomaticSummary']['result']
assert response_result['id'] != a_summary_id
assert response_result['summary'] != SAMPLE_SUMMARY_TEXT
assert response_result['summary'] != SAMPLE_SUMMARY_JSON['summary']

# With failed status
data['status'] = DeeplServerBaseCallbackSerializer.Status.FAILED.value
Expand Down
7 changes: 5 additions & 2 deletions apps/deepl_integration/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,12 @@ def save_data(
data: dict,
):
data_url = data['presigned_s3_url']
summary_text = RequestHelper(url=data_url, custom_error_handler=custom_error_handler).get_text()
summary_data = RequestHelper(url=data_url, custom_error_handler=custom_error_handler).json()
a_summary.status = AutomaticSummary.Status.SUCCESS
a_summary.summary = summary_text
a_summary.summary = summary_data.get('summary', '')
a_summary.analytical_statement = summary_data.get('analytical_statement', '')
a_summary.information_gap = summary_data.get('info_gaps', '')

a_summary.save()


Expand Down
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ input AnalysisAutomaticSummaryCreateInputType {
type AnalysisAutomaticSummaryType {
id: ID!
summary: String!
analyticalStatement: String!
informationGap: String!
createdAt: DateTime!
modifiedAt: DateTime!
createdBy: UserType
Expand Down

0 comments on commit a9d342d

Please sign in to comment.