Files
Athena-Deck/integrations/openwebui/patch_tts_errors.py
T

32 lines
1.3 KiB
Python

"""Preserve provider error bodies before aiohttp releases an error response.
Run inside the OpenWebUI container; restart OpenWebUI after applying.
Reapply after recreating/updating the upstream container. No config/keys changed.
"""
from pathlib import Path
def patch(source):
start = source.index('async def _tts_openai(')
end = source.index('\nasync def ', start + 1)
section = source[start:end]
original = ' r.raise_for_status()\n'
fixed = ' if r.status >= 400:\n await r.read() # Athena: retain JSON detail before response release\n r.raise_for_status()\n'
if fixed in section:
return source
if section.count(original) != 1:
raise RuntimeError('OpenWebUI TTS implementation changed; manual review required.')
return source[:start] + section.replace(original, fixed) + source[end:]
if __name__ == '__main__':
path = Path('/app/backend/open_webui/routers/audio.py')
original = path.read_text()
updated = patch(original)
compile(updated, str(path), 'exec')
if updated != original:
backup = path.with_name('audio.py.athena-tts-errors.bak')
if not backup.exists():
backup.write_text(original)
path.write_text(updated)
print('OpenWebUI TTS error-detail preservation ready.')