fix(compose): repair STT after Onyx 5.0.3 upgrade and fix silent alembic skip

fix(compose): repair STT after Onyx 5.0.3 upgrade and fix silent alembic skip

- Replace fragile runtime `sed` patches with idempotent Python patching in
 api_server entrypoint. The old `sed` heuristics broke because Onyx 5.x
 refactored the voice provider to use the OpenAI SDK
 (`client.audio.transcriptions.create`) instead of raw HTTP payloads,
 causing the language parameter to never be injected and the model
 fallback to corrupt factory.py with chained `or` expressions.

- Add `WHISPER_MODEL` env override (defaults to `whisper-1`) so the
 transcription payload uses the exact model name exposed by the backend
 proxy. Fixes 404 "model not found" against self-hosted Whisper/LiteLLM.

- Fix critical Docker bug where `command` was passed as an argument to
 the custom `entrypoint` and silently ignored. `alembic upgrade head`
 now runs inside the entrypoint before Uvicorn starts.

- Merge upstream compose improvements:
 * Add json-file logging (50m/6 rotation) to web_server, relational_db,
   and code-interpreter
 * Add code-interpreter healthcheck
 * Include optional MCP server block (commented out)

- Preserve existing Livtec customizations:
 * Voice endpoint redirected to aido-whisper-ch.livtec.cloud
 * WHISPER_LANGUAGE=de injected into SDK transcribe() call
 * Custom livtec/aido-web:local branded image
 * Bind mounts for logs, caches, and file-system
This commit is contained in:
Jannic Debus 2026-11-08 11:37:02 +01:00
parent 9cedefa4fc
commit 8143cc123f

View file

@ -1,39 +1,157 @@
services:
api_server:
image: ${ONYX_BACKEND_IMAGE:-onyxdotapp/onyx-backend:${IMAGE_TAG:-latest}}
entrypoint: >
entrypoint: |
sh -c "
# 1. Fallback in factory.py (da UI api_base/stt_model nicht speichert)
sed -i 's|api_base = provider.api_base|api_base = provider.api_base or \"https://aido-whisper-ch.livtec.cloud/v1\"|' /app/onyx/voice/factory.py
sed -i 's|stt_model = provider.stt_model|stt_model = provider.stt_model or \"whisper-1\"|' /app/onyx/voice/factory.py
python3 << 'PYEOF'
import os, sys
# 2. Default API Base in openai.py (wirkt für TTS und interne Fallbacks)
sed -i 's|DEFAULT_OPENAI_API_BASE = \"https://api.openai.com\"|DEFAULT_OPENAI_API_BASE = \"https://aido-whisper-ch.livtec.cloud/v1\"|' /app/onyx/voice/providers/openai.py
def read_file(path):
with open(path, \"r\") as f:
return f.read()
# 3. Sicherheitshalber: Auch die hartkodierten Realtime-Modelle auf whisper-1 setzen
# (falls ein Code-Pfad doch noch Streaming versucht)
sed -i 's|OPENAI_REALTIME_SESSION_MODEL = \"gpt-realtime-1.5\"|OPENAI_REALTIME_SESSION_MODEL = \"whisper-1\"|' /app/onyx/voice/providers/openai.py
sed -i 's|OPENAI_REALTIME_STT_MODEL = \"gpt-realtime-whisper\"|OPENAI_REALTIME_STT_MODEL = \"whisper-1\"|' /app/onyx/voice/providers/openai.py
def write_file(path, content):
with open(path, \"w\") as f:
f.write(content)
# 4. Language-Patch für den Chunked-HTTP-Pfad
# (nur ausführen, wenn transcribe existiert und noch nicht gepatcht)
if grep -q 'def transcribe' /app/onyx/voice/providers/openai.py && ! grep -q 'WHISPER_LANGUAGE' /app/onyx/voice/providers/openai.py; then
sed -i '1i import os' /app/onyx/voice/providers/openai.py
# Heuristisch: Füge language zum Payload hinzu
if grep -q 'data={' /app/onyx/voice/providers/openai.py; then
sed -i '/data={/a\\ \"language\": os.environ.get(\"WHISPER_LANGUAGE\", \"de\"),' /app/onyx/voice/providers/openai.py
elif grep -q 'json={' /app/onyx/voice/providers/openai.py; then
sed -i '/json={/a\\ \"language\": os.environ.get(\"WHISPER_LANGUAGE\", \"de\"),' /app/onyx/voice/providers/openai.py
fi
fi
# --- 1. Clean up corrupted factory.py ---
factory_path = \"/app/onyx/voice/factory.py\"
if os.path.exists(factory_path):
src = read_file(factory_path)
# Run DB migrations and start the API server
alembic upgrade head && echo \"Starting Onyx Api Server\" && exec uvicorn onyx.main:app --host 0.0.0.0 --port 8080
# Fix corrupted api_base line (remove repeated or chains)
if 'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"' in src:
src = src.replace(
'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\" or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\" or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"',
'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"'
)
# Also handle case where it ran twice with different corruption levels
src = src.replace(
'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\" or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"',
'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"'
)
print(\"[OK] factory.py api_base cleaned up\")
# Ensure api_base fallback is present (idempotent)
if 'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"' not in src:
if 'api_base = provider.api_base' in src:
src = src.replace(
'api_base = provider.api_base',
'api_base = provider.api_base or \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"'
)
print(\"[OK] factory.py api_base fallback applied\")
else:
print(\"[WARN] factory.py: api_base pattern not found\")
else:
print(\"[OK] factory.py api_base already correct\")
# Fix corrupted stt_model line
if 'stt_model = provider.stt_model or \\\"whisper-1\\\" or \\\"whisper-1\\\"' in src:
src = src.replace(
'stt_model = provider.stt_model or \\\"whisper-1\\\" or \\\"whisper-1\\\"',
'stt_model = provider.stt_model or \\\"whisper-1\\\"'
)
print(\"[OK] factory.py stt_model cleaned up\")
# Ensure stt_model fallback is present (idempotent)
if 'stt_model = provider.stt_model or \\\"whisper-1\\\"' not in src:
if 'stt_model = provider.stt_model' in src:
src = src.replace(
'stt_model = provider.stt_model',
'stt_model = provider.stt_model or \\\"whisper-1\\\"'
)
print(\"[OK] factory.py stt_model fallback applied\")
else:
print(\"[WARN] factory.py: stt_model pattern not found\")
else:
print(\"[OK] factory.py stt_model already correct\")
write_file(factory_path, src)
else:
print(\"[FATAL] factory.py not found\")
sys.exit(1)
# --- 2. Patch openai.py ---
openai_path = \"/app/onyx/voice/providers/openai.py\"
if not os.path.exists(openai_path):
print(\"[FATAL] openai.py not found\")
sys.exit(1)
src = read_file(openai_path)
# 2a. Ensure DEFAULT_OPENAI_API_BASE points to your endpoint (idempotent)
if 'DEFAULT_OPENAI_API_BASE = \\\"https://api.openai.com\\\"' in src:
src = src.replace(
'DEFAULT_OPENAI_API_BASE = \\\"https://api.openai.com\\\"',
'DEFAULT_OPENAI_API_BASE = \\\"https://aido-whisper-ch.livtec.cloud/v1\\\"'
)
print(\"[OK] openai.py DEFAULT_OPENAI_API_BASE patched\")
else:
print(\"[OK] openai.py DEFAULT_OPENAI_API_BASE already correct or upstream changed\")
# 2b. Ensure realtime models are whisper-1 (idempotent)
if 'OPENAI_REALTIME_SESSION_MODEL = \\\"gpt-realtime-1.5\\\"' in src:
src = src.replace(
'OPENAI_REALTIME_SESSION_MODEL = \\\"gpt-realtime-1.5\\\"',
'OPENAI_REALTIME_SESSION_MODEL = \\\"whisper-1\\\"'
)
print(\"[OK] openai.py REALTIME_SESSION_MODEL patched\")
else:
print(\"[OK] openai.py REALTIME_SESSION_MODEL already correct or upstream changed\")
if 'OPENAI_REALTIME_STT_MODEL = \\\"gpt-realtime-whisper\\\"' in src:
src = src.replace(
'OPENAI_REALTIME_STT_MODEL = \\\"gpt-realtime-whisper\\\"',
'OPENAI_REALTIME_STT_MODEL = \\\"whisper-1\\\"'
)
print(\"[OK] openai.py REALTIME_STT_MODEL patched\")
else:
print(\"[OK] openai.py REALTIME_STT_MODEL already correct or upstream changed\")
# 2c. Inject language parameter into SDK transcribe call (THE CRITICAL FIX)
if \"WHISPER_LANGUAGE\" not in src:
# Add import os near top if missing
lines = src.split(\"\\n\")
import_idx = next((i for i, l in enumerate(lines) if l.startswith(\"import \") or l.startswith(\"from \")), 0)
if not any(\"import os\" in l for l in lines[:import_idx+5]):
lines.insert(import_idx, \"import os\")
print(\"[OK] openai.py added import os\")
# Rejoin and find the transcribe method's create() call
src = \"\\n\".join(lines)
# Pattern: the SDK call inside transcribe()
old_pattern = ''' response = await client.audio.transcriptions.create(
model=self.stt_model,
file=audio_file,
)'''
new_pattern = ''' response = await client.audio.transcriptions.create(
model=self.stt_model,
file=audio_file,
language=os.environ.get(\"WHISPER_LANGUAGE\", \"de\"),
)'''
if old_pattern in src:
src = src.replace(old_pattern, new_pattern)
print(\"[OK] openai.py language parameter injected into transcribe()\")
else:
print(\"[WARN] openai.py: could not find exact transcribe() SDK call pattern to inject language\")
print(\"[WARN] STT may default to English auto-detect instead of German\")
else:
print(\"[OK] openai.py language already present\")
write_file(openai_path, src)
print(\"[DONE] All patches applied successfully\")
PYEOF
# Run migrations and start server
alembic upgrade head && echo \"Starting Onyx Api Server\" && exec uvicorn onyx.main:app --host 0.0.0.0 --port 8080
"
command: >
/bin/sh -c "alembic upgrade head && echo \"Starting Onyx Api Server\" &&
uvicorn onyx.main:app --host 0.0.0.0 --port 8080"
#command: >
# /bin/sh -c "alembic upgrade head && echo \"Starting Onyx Api Server\" &&
# uvicorn onyx.main:app --host 0.0.0.0 --port 8080"
# Check env.template and copy to .env for env vars
env_file:
- path: .env