Litellm dev 12 23 2024 p1 (#7383)

* feat(guardrails_endpoint.py): new `/guardrails/list` endpoint

Allow users to view what the available guardrails are

* docs: document new `/guardrails/list` endpoint

* docs(enterprise.md): update docs

* fix(openai/transcription/handler.py): support cost tracking on vtt + srt formats

* fix(openai/transcriptions/handler.py): default to 'verbose_json' response format if 'text' or 'json' response_format received. ensures 'duration' param is received for all audio transcription requests

* fix: fix linting errors

* fix: remove unused import
This commit is contained in:
Krish Dholakia 2024-12-23 16:33:31 -08:00 committed by GitHub
parent 82b298acac
commit a89b0d5c39
11 changed files with 169 additions and 51 deletions

View file

@ -6316,3 +6316,31 @@ def is_prompt_caching_valid_prompt(
except Exception as e:
verbose_logger.error(f"Error in is_prompt_caching_valid_prompt: {e}")
return False
def extract_duration_from_srt_or_vtt(srt_or_vtt_content: str) -> Optional[float]:
"""
Extracts the total duration (in seconds) from SRT or VTT content.
Args:
srt_or_vtt_content (str): The content of an SRT or VTT file as a string.
Returns:
Optional[float]: The total duration in seconds, or None if no timestamps are found.
"""
# Regular expression to match timestamps in the format "hh:mm:ss,ms" or "hh:mm:ss.ms"
timestamp_pattern = r"(\d{2}):(\d{2}):(\d{2})[.,](\d{3})"
timestamps = re.findall(timestamp_pattern, srt_or_vtt_content)
if not timestamps:
return None
# Convert timestamps to seconds and find the max (end time)
durations = []
for match in timestamps:
hours, minutes, seconds, milliseconds = map(int, match)
total_seconds = hours * 3600 + minutes * 60 + seconds + milliseconds / 1000.0
durations.append(total_seconds)
return max(durations) if durations else None