import time from common.utils.business_event_context import current_event def tracked_transcribe(client, *args, **kwargs): start_time = time.time() # Extract the file and model from kwargs if present, otherwise use defaults file = kwargs.get('file') model = kwargs.get('model', 'whisper-1') duration = kwargs.pop('duration', 600) result = client.audio.transcriptions.create(*args, **kwargs) end_time = time.time() # Token usage for transcriptions is actually the duration in seconds we pass, as the whisper model is priced per second transcribed metrics = { 'total_tokens': duration, 'prompt_tokens': 0, # For transcriptions, all tokens are considered "completion" 'completion_tokens': duration, 'time_elapsed': end_time - start_time, 'interaction_type': 'ASR', } current_event.log_llm_metrics(metrics) return result