The Language Tasks component uses OpenAI’s GPT-4o-mini to analyze video transcriptions and intelligently select the most engaging 2-minute highlight segment.
Smart Segment Selection: Uses GPT-4o-mini to understand context and content quality
Complete Sentences: Ensures selected text doesn’t cut sentences mid-way
Structured Output: Uses function calling for reliable JSON responses
Validation: Checks for valid time ranges and positive durations
Error Recovery: Interactive retry option if segment selection fails
Detailed Logging: Prints selected segment details for verification
from Components.LanguageTasks import GetHighlight# Build timestamped transcriptiontranscription_text = """0.0 - 2.5: Hello and welcome to this video2.5 - 5.2: Today we'll be discussing AI5.2 - 8.4: and its applications in video processing8.4 - 120.0: [Rest of transcription...]"""# Get highlight segmentstart, end = GetHighlight(transcription_text)if start is not None and end is not None: print(f"Best highlight: {start}s to {end}s ({end-start}s duration)") # Output: Best highlight: 5s to 125s (120s duration)else: print("Failed to get highlight")
The AI returns a structured response using the JSONResponse Pydantic model:
class JSONResponse(BaseModel): start: float # Start time in seconds content: str # The transcribed text from the segment end: float # End time in seconds
# Checks for empty responseif not response: return None, None# Checks for required fieldsif not hasattr(response, 'start') or not hasattr(response, 'end'): return None, None
# Parse timesStart = int(response.start)End = int(response.end)# Check for negative valuesif Start < 0 or End < 0: print("ERROR: Negative time values") return None, None# Check for valid rangeif End <= Start: print("ERROR: Invalid time range (end must be > start)") return None, None
# Interactive retry for invalid segmentsif Start == End: Ask = input("Error - Get Highlights again (y/n) -> ").lower() if Ask == "y": Start, End = GetHighlight(Transcription) return Start, End
The input contains a timestamped transcription of a video.Select a 2-minute segment from the transcription that contains something interesting, useful, surprising, controversial, or thought-provoking.The selected text should contain only complete sentences.Do not cut the sentences in the middle.The selected text should form a complete thought.