From 806d3b21603938090a97609383ee63958d08c457 Mon Sep 17 00:00:00 2001 From: livdebus Date: Thu, 12 Nov 2026 20:04:19 +0100 Subject: [PATCH] Revert "fix(api_server): update voice STT patch for Onyx 5.0.3 image layout" This reverts commit f51a35732ca87594f8a453626024033e55fbd1bd. --- docker-compose.yml | 197 +++++++++++++++++++++++++++++++-------------- 1 file changed, 136 insertions(+), 61 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0b30200..0e402b3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,76 +1,153 @@ services: api_server: image: ${ONYX_BACKEND_IMAGE:-onyxdotapp/onyx-backend:${IMAGE_TAG:-latest}} - entrypoint: > + entrypoint: | sh -c " - set -e; + python3 << 'PYEOF' + import os, sys - # ── Resolve voice module paths via Python import ───────────── - VF=\$(python -c 'import onyx.voice.factory as m; print(m.__file__)' 2>/dev/null || true); - VO=\$(python -c 'import onyx.voice.providers.openai as m; print(m.__file__)' 2>/dev/null || true); + def read_file(path): + with open(path, \"r\") as f: + return f.read() - # Fallback: try known WORKDIR prefixes - if [ -z \"\$VF\" ] || [ -z \"\$VO\" ]; then - for p in /app /app/backend /srv/app /opt/onyx /usr/src/app; do - if [ -f \"\${p}/onyx/voice/factory.py\" ]; then - VF=\"\${p}/onyx/voice/factory.py\"; - VO=\"\${p}/onyx/voice/providers/openai.py\"; - break; - fi; - done; - fi; + def write_file(path, content): + with open(path, \"w\") as f: + f.write(content) - if [ -z \"\$VF\" ] || [ -z \"\$VO\" ]; then - echo '[patch] ERROR: voice files not found, skipping all patches'; - else - echo \"[patch] factory: \$VF\"; - echo \"[patch] openai : \$VO\"; + # --- 1. Clean up corrupted factory.py --- + factory_path = \"/app/onyx/voice/factory.py\" + if os.path.exists(factory_path): + src = read_file(factory_path) - # ── Config ───────────────────────────────────────────────── - # NOTE: no /v1 suffix. 5.0.3 code appends /v1/audio/... itself. - LB='https://aido-whisper-ch.livtec.cloud'; - SM='whisper-1'; - WL=\${WHISPER_LANGUAGE:-de}; + # 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\") - # ── 1. factory.py: fallback when admin UI has no provider ─ - sed -i \"s|api_base = provider.api_base$|api_base = provider.api_base or '$LB'|\" \"\$VF\"; - sed -i \"s|stt_model = provider.stt_model$|stt_model = provider.stt_model or '$SM'|\" \"\$VF\"; + # 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\") - # ── 2. openai.py: default base URL (no /v1!) ────────────── - sed -i \"s|DEFAULT_OPENAI_API_BASE = \\\"https://api.openai.com\\\"|DEFAULT_OPENAI_API_BASE = \\\"$LB\\\"|\" \"\$VO\"; + # 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\") - # ── 3. openai.py: neutralise WS realtime models ─────────── - sed -i \"s|OPENAI_REALTIME_SESSION_MODEL = \\\"gpt-realtime-1.5\\\"|OPENAI_REALTIME_SESSION_MODEL = \\\"$SM\\\"|\" \"\$VO\"; - sed -i \"s|OPENAI_REALTIME_STT_MODEL = \\\"gpt-realtime-whisper\\\"|OPENAI_REALTIME_STT_MODEL = \\\"$SM\\\"|\" \"\$VO\"; + # 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\") - # ── 4. Language injection for chunked STT ───────────────── - if grep -q 'def transcribe' \"\$VO\" \&\& ! grep -q 'WHISPER_LANGUAGE' \"\$VO\"; then - sed -i '1i import os' \"\$VO\"; - # Anchor: the line that sets the model in the form data. - # In 5.0.3 the transcribe method uses aiohttp FormData: - # form.add_field('model', self.stt_model) - # OR a dict: data = {\"model\": ..., \"file\": ...} - # Try both patterns. - if grep -q \"add_field.*model\" \"\$VO\"; then - sed -i \"/add_field('model'/a\\ form.add_field('language', os.environ.get('WHISPER_LANGUAGE', '$WL'))\" \"\$VO\"; - elif grep -q '\"model\"' \"\$VO\"; then - sed -i \"/['\\\"]model['\\\"]\s*:/a\\ 'language': os.environ.get('WHISPER_LANGUAGE', '$WL'),\" \"\$VO\"; - fi; - fi; + write_file(factory_path, src) + else: + print(\"[FATAL] factory.py not found\") + sys.exit(1) - echo '[patch] All voice patches applied.'; + # --- 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) - # ── Verify patches took effect ──────────────────────────── - echo '[patch] --- Verification ---'; - grep 'DEFAULT_OPENAI_API_BASE' \"\$VO\" | head -1; - grep 'OPENAI_REALTIME_SESSION_MODEL' \"\$VO\" | head -1; - grep 'api_base or' \"\$VF\" | head -1; - grep 'WHISPER_LANGUAGE' \"\$VO\" | head -1 || echo '[patch] WARN: language injection did not match'; - echo '[patch] --- End verification ---'; - fi; + src = read_file(openai_path) - # ── Migrations + server ────────────────────────────────────── - alembic upgrade head \&\& echo 'Starting Onyx Api Server' \&\& exec uvicorn onyx.main:app --host 0.0.0.0 --port 8080 + # 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\" && @@ -113,10 +190,8 @@ services: # Onyx Craft configuration (disabled by default, set ENABLE_CRAFT=true in .env to enable) # Use --include-craft with install script, or manually set in .env file - ENABLE_CRAFT=${ENABLE_CRAFT:-false} - # Voice / STT - - WHISPER_LANGUAGE=de - # Not read by 5.0.3 voice module. Kept for forward-compat. - VOICE_DISABLE_STREAMING_STT=true + - WHISPER_LANGUAGE=de # PRODUCTION: Uncomment the line below to use if IAM_AUTH is true and you are using iam auth for postgres # volumes: # - ./bundle.pem:/app/bundle.pem:ro