Skip to content

Commit

Permalink
Merge pull request #892 from openedx/iahmad/ENT-9281
Browse files Browse the repository at this point in the history
fix: Added guardrails and client fixes for transcript summary command
  • Loading branch information
irfanuddinahmad authored Jul 28, 2024
2 parents 5f53a30 + 90a62f0 commit 10d9db6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion enterprise_catalog/apps/ai_curation/openai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def chat_completions(
response_content = response.json().get('content')
if response_format == 'json':
return json.loads(response_content)
return json.loads(response_content)[0]
return response_content
except json.decoder.JSONDecodeError as ex:
LOGGER.error(
'[AI_CURATION] Invalid JSON response received: Prompt: [%s], Response: [%s]',
Expand Down
2 changes: 1 addition & 1 deletion enterprise_catalog/apps/api_client/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def get_video_skills(self, video_usage_key):
"""
page = 1
results = []
request_params = {'page': page, 'usage_key': video_usage_key, 'verified': 'true'}
request_params = {'page': page, 'usage_key': video_usage_key, 'verified': 'false'}
try:
response = self._retrieve_video_skills(request_params)
results += response.get('results', [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def handle(self, *args, **options):
processed_videos = VideoTranscriptSummary.objects.all().values_list('video_id', flat=True)
videos = Video.objects.exclude(edx_video_id__in=processed_videos)
for video in videos:
summary = generate_transcript_summary(video)
if summary:
VideoTranscriptSummary.objects.create(video=video, summary=summary)
try:
summary = generate_transcript_summary(video)
if summary:
VideoTranscriptSummary.objects.create(video=video, summary=summary)
except Exception as ex: # pylint: disable=broad-exception-caught
logger.error(
'[FETCH_VIDEO_TRANSCRIPT_SUMMARY] Failure in generating transcript \
summary for Video id: "%s". Ex: "%s".',
video.edx_video_id,
str(ex)
)
2 changes: 1 addition & 1 deletion enterprise_catalog/apps/video_catalog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_transcript_summary(transcript: str, max_length: int = 260) -> str:
'content': settings.SUMMARIZE_VIDEO_TRANSCRIPT_PROMPT.format(count=max_length, transcript=transcript)
}
]
return chat_completions(messages=messages, response_format='text', response_type=str)
return chat_completions(messages=messages, response_format='text')


def fetch_transcript(transcript_url: str, include_time_markings: bool = True) -> str:
Expand Down

0 comments on commit 10d9db6

Please sign in to comment.