| """ |
| Audio quality detector for transcription confidence. |
| """ |
|
|
| import logging |
| from typing import Dict, Any |
| from agentic_reliability_framework.runtime.agents.base import BaseAgent, AgentSpecialization |
| from ai_event import AIEvent |
|
|
| logger = logging.getLogger(__name__) |
|
|
| class AudioQualityDetector(BaseAgent): |
| """ |
| Detects low‑confidence transcriptions based on average log probability. |
| Expects `retrieval_scores[0]` to contain the average log probability. |
| """ |
|
|
| def __init__(self): |
| super().__init__(AgentSpecialization.DETECTIVE) |
| self._threshold = -5.0 |
|
|
| async def analyze(self, event: AIEvent) -> Dict[str, Any]: |
| """ |
| Analyze audio transcription event. |
| """ |
| avg_log_prob = event.retrieval_scores[0] if event.retrieval_scores else -10.0 |
| flags = [] |
| if avg_log_prob < self._threshold: |
| flags.append('low_confidence') |
|
|
| |
| confidence = max(0, min(1.0, 1.0 + avg_log_prob / 10.0)) |
|
|
| return { |
| 'specialization': 'audio_quality', |
| 'confidence': confidence, |
| 'findings': { |
| 'flags': flags, |
| 'avg_log_prob': avg_log_prob |
| }, |
| 'recommendations': [ |
| 'Use clearer audio', |
| 'Try a different model', |
| 'Check for background noise' |
| ] if flags else [] |
| } |