-
Notifications
You must be signed in to change notification settings - Fork 19
ECHO-261-route-english-transcription-through-litellm #171
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| ENABLE_RUNPOD_WHISPER_TRANSCRIPTION, | ||
| ENABLE_LITELLM_WHISPER_TRANSCRIPTION, | ||
| RUNPOD_WHISPER_MAX_REQUEST_THRESHOLD, | ||
| ENABLE_ENGLISH_TRANSCRIPTION_WITH_LITELLM, | ||
| ) | ||
|
|
||
| # from dembrane.openai import client | ||
|
|
@@ -33,7 +34,10 @@ class TranscriptionError(Exception): | |
|
|
||
|
|
||
| def queue_transcribe_audio_runpod( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seperation of concerns: this does more than "queue_transcribe_audio_runpod" please use the higher level "transcribe_audio" fn and switch the underlying implementation when necessary?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also maybe have a transcribe_audio_litellm fn to complement this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. queue_transcribe_audio_runpod: It just does that. It posts a request to runpod. Thats all.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. transcribe_audio_litellm: There already is a function which we are using in this case
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. server/dembrane/transcribe.py/transcribe_audio_litellm |
||
| audio_file_uri: str, language: Optional[str], whisper_prompt: Optional[str], is_priority: bool = False | ||
| audio_file_uri: str, | ||
| language: Optional[str], | ||
| whisper_prompt: Optional[str], | ||
| is_priority: bool = False, | ||
| ) -> str: | ||
| """Transcribe audio using RunPod""" | ||
| logger = logging.getLogger("transcribe.transcribe_audio_runpod") | ||
|
|
@@ -65,9 +69,7 @@ def queue_transcribe_audio_runpod( | |
| return job_id | ||
| except Exception as e: | ||
| logger.error(f"Failed to queue transcription job for RunPod: {e}") | ||
| raise TranscriptionError( | ||
| f"Failed to queue transcription job for RunPod: {e}" | ||
| ) from e | ||
| raise TranscriptionError(f"Failed to queue transcription job for RunPod: {e}") from e | ||
| except Exception as e: | ||
| logger.error(f"Failed to get signed url for {audio_file_uri}: {e}") | ||
| raise TranscriptionError(f"Failed to get signed url for {audio_file_uri}: {e}") from e | ||
|
|
@@ -190,8 +192,7 @@ def transcribe_conversation_chunk(conversation_chunk_id: str) -> str | None: | |
|
|
||
| if conversation["project_id"]["default_conversation_transcript_prompt"]: | ||
| prompt_parts.append( | ||
| ' ' + conversation["project_id"]["default_conversation_transcript_prompt"] | ||
| + "." | ||
| " " + conversation["project_id"]["default_conversation_transcript_prompt"] + "." | ||
| ) | ||
|
|
||
| # if previous_chunk_transcript: | ||
|
|
@@ -201,43 +202,79 @@ def transcribe_conversation_chunk(conversation_chunk_id: str) -> str | None: | |
|
|
||
| logger.debug(f"whisper_prompt: {whisper_prompt}") | ||
|
|
||
| if ENABLE_RUNPOD_WHISPER_TRANSCRIPTION: | ||
| if ENABLE_RUNPOD_WHISPER_TRANSCRIPTION and not ( | ||
| language == "en" and ENABLE_ENGLISH_TRANSCRIPTION_WITH_LITELLM | ||
| ): | ||
| logger.debug("Using RunPod for transcription") | ||
| try: | ||
| directus_response = directus.get_items( | ||
| "conversation_chunk", | ||
| { | ||
| "query": {"filter": {"id": {"_eq": conversation_chunk_id}}, | ||
| "fields": ["source","runpod_job_status_link","runpod_request_count"]}, | ||
| "query": { | ||
| "filter": {"id": {"_eq": conversation_chunk_id}}, | ||
| "fields": ["source", "runpod_job_status_link", "runpod_request_count"], | ||
| }, | ||
| }, | ||
| ) | ||
| except Exception as e: | ||
| logger.error(f"Failed to get conversation chunk for {conversation_chunk_id}: {e}") | ||
| raise ValueError(f"Failed to get conversation chunk for {conversation_chunk_id}: {e}") from e | ||
| raise ValueError( | ||
| f"Failed to get conversation chunk for {conversation_chunk_id}: {e}" | ||
| ) from e | ||
|
|
||
| runpod_request_count = (directus_response[0]["runpod_request_count"]) | ||
| source = (directus_response[0]["source"]) | ||
| runpod_job_status_link = (directus_response[0]["runpod_job_status_link"]) | ||
| runpod_request_count = directus_response[0]["runpod_request_count"] | ||
| source = directus_response[0]["source"] | ||
| runpod_job_status_link = directus_response[0]["runpod_job_status_link"] | ||
|
|
||
| headers = { | ||
| "Content-Type": "application/json", | ||
| "Authorization": f"Bearer {RUNPOD_WHISPER_API_KEY}", | ||
| } | ||
|
|
||
| if runpod_job_status_link: | ||
| response = requests.get(runpod_job_status_link, headers=headers) | ||
| job_status = response.json()['status'] | ||
| logger.debug(f"job_status: {job_status}") | ||
| if job_status == "IN_PROGRESS": | ||
| logger.info(f"RunPod job {runpod_job_status_link} is in progress") | ||
| return None | ||
| try: | ||
| response = requests.get(runpod_job_status_link, headers=headers, timeout=30) | ||
| response.raise_for_status() # Raise an exception for bad status codes | ||
|
|
||
| response_data = response.json() | ||
| logger.debug(f"RunPod status response: {response_data}") | ||
|
|
||
| job_status = response_data.get("status") | ||
| if job_status is None: | ||
| logger.warning( | ||
| f"No 'status' field in RunPod response for {runpod_job_status_link}: {response_data}" | ||
| ) | ||
| # If no status field, assume job is not in progress and continue | ||
| else: | ||
| logger.debug(f"job_status: {job_status}") | ||
| if job_status == "IN_PROGRESS": | ||
| logger.info(f"RunPod job {runpod_job_status_link} is in progress") | ||
| return None | ||
|
|
||
| except requests.RequestException as e: | ||
| logger.error(f"Failed to get RunPod job status from {runpod_job_status_link}: {e}") | ||
| # Continue with processing if status check fails | ||
| except ValueError as e: | ||
| logger.error( | ||
| f"Invalid JSON response from RunPod status endpoint {runpod_job_status_link}: {e}" | ||
| ) | ||
| # Continue with processing if JSON parsing fails | ||
| except Exception as e: | ||
| logger.error( | ||
| f"Unexpected error checking RunPod job status {runpod_job_status_link}: {e}" | ||
| ) | ||
| # Continue with processing if any other error occurs | ||
ArindamRoy23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if runpod_request_count < RUNPOD_WHISPER_MAX_REQUEST_THRESHOLD: | ||
| if source == "PORTAL_AUDIO": | ||
| is_priority = True | ||
| else: | ||
| is_priority = False | ||
| job_id = queue_transcribe_audio_runpod( | ||
| chunk["path"], language=language, whisper_prompt=whisper_prompt, is_priority=is_priority | ||
| chunk["path"], | ||
| language=language, | ||
| whisper_prompt=whisper_prompt, | ||
| is_priority=is_priority, | ||
| ) | ||
| # Update job_id on directus | ||
| directus.update_item( | ||
|
|
@@ -260,6 +297,7 @@ def transcribe_conversation_chunk(conversation_chunk_id: str) -> str | None: | |
| return None | ||
|
|
||
| elif ENABLE_LITELLM_WHISPER_TRANSCRIPTION: | ||
| logger.debug("Using LITELLM for transcription") | ||
| transcript = transcribe_audio_litellm( | ||
| chunk["path"], language=language, whisper_prompt=whisper_prompt | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| Hier is een transcriptie van een technische presentatie. De spreker gebruikt natuurlijk Nederlands met enkele Engelse technical terms zoals gebruikelijk. De presentator zegt: "In een vrij gemakkelijk network is het mogelijk om de requirements voor een change te evalueren. We gebruiken modern tooling voor ons system management. Het is quite possible dat een enkele wijziging impact heeft, maar we blijven altijd in het Nederlands praten over onze processes en workflows. De change management procedure helpt ons om disruptions te voorkomen en stability te behouden in ons environment. | ||
| Hallo, lasst uns beginnen. Zuerst ein paar Einführungen und dann können wir mit dem Thema des Tages beginnen. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| Here is a transcript from a business presentation about technology and change management. The speaker maintains English throughout while occasionally using technical terms. The presenter explains: "In our network environment, it's essential to carefully plan any changes. Our system administrators use modern tools for network management. The change management process helps us prevent disruptions and maintain system stability. We've implemented quality assurance procedures and risk assessment protocols. Even when discussing complex technical concepts, we continue speaking in English. | ||
| Hi, lets get started. First we'll have a round of introductions and then we can get into the topic for today. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| Aquí hay una transcripción de una presentación técnica. El orador usa naturalmente español con algunos términos técnicos en inglés como es habitual. El presentador explica: "En nuestro network environment, es esencial planificar cuidadosamente cualquier change. Nuestros administradores usan tools modernos para el management. El process de gestión nos ayuda a prevenir disruptions pero siempre seguimos hablando en español sobre nuestros procedures y workflows. Es quite importante mantener la stability de nuestro sistema. | ||
| Hola, comencemos. Primero, un round de introducción y luego podremos empezar con el tema de hoy. | ||
ArindamRoy23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| Voici une transcription d'une présentation technique. L'orateur utilise naturellement le français avec quelques termes anglais techniques comme c'est habituel. Le présentateur explique : "Dans notre network environment, il est essentiel de planifier soigneusement tout changement. Nos administrateurs utilisent des tools modernes pour le management. Le process de gestion nous aide à prévenir les disruptions mais nous continuons toujours à parler en français de nos procédures et workflows. C'est quite important de maintenir la stability de notre système. | ||
| Bonjour, commençons. D'abord un tour de table et ensuite nous pourrons aborder le sujet du jour. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| Hier is een transcriptie van een technische presentatie. De spreker gebruikt natuurlijk Nederlands met enkele Engelse technical terms zoals gebruikelijk. De presentator zegt: "In een vrij gemakkelijk network is het mogelijk om de requirements voor een change te evalueren. We gebruiken modern tooling voor ons system management. Het is quite possible dat een enkele wijziging impact heeft, maar we blijven altijd in het Nederlands praten over onze processes en workflows. De change management procedure helpt ons om disruptions te voorkomen en stability te behouden in ons environment. | ||
| Hallo, laten we beginnen. Eerst even een introductieronde en dan kunnen we aan de slag met de thema van vandaag. | ||
ArindamRoy23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.