Skip to content
Merged
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: 6 additions & 0 deletions echo/server/dembrane/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@
DISABLE_CORS = os.environ.get("DISABLE_CORS", "false").lower() in ["true", "1"]
logger.debug(f"DISABLE_CORS: {DISABLE_CORS}")

ENABLE_ENGLISH_TRANSCRIPTION_WITH_LITELLM = os.environ.get(
"ENABLE_ENGLISH_TRANSCRIPTION_WITH_LITELLM", "false"
).lower() in ["true", "1"]
# ENABLE_ENGLISH_TRANSCRIPTION_WITH_LITELLM is optional and defaults to false
logger.debug("ENABLE_ENGLISH_TRANSCRIPTION_WITH_LITELLM: %s", ENABLE_ENGLISH_TRANSCRIPTION_WITH_LITELLM)

ENABLE_RUNPOD_WHISPER_TRANSCRIPTION = os.environ.get(
"ENABLE_RUNPOD_WHISPER_TRANSCRIPTION", "false"
).lower() in ["true", "1"]
Expand Down
78 changes: 58 additions & 20 deletions echo/server/dembrane/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +34,10 @@ class TranscriptionError(Exception):


def queue_transcribe_audio_runpod(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also maybe have a transcribe_audio_litellm fn to complement this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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

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(
Expand All @@ -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
)
Expand Down
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.
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.