Add pinned CPU engine dependencies, retained interrupted-response history, provider admission, offline evaluation and isolated browser tooling. Record Phase 2 acceptance and Phase 3/4 preparation, bounded paid-test accounting and interruption incident findings. Human interruption acceptance, paired OpenAI evaluation and rollback remain pending.
94 lines
4.0 KiB
Python
94 lines
4.0 KiB
Python
"""Actual asset-backed engine construction; only upstream provider HTTP is a fixture.
|
|
|
|
Run on stdin inside the isolated immutable image. Does not start native sessions.
|
|
"""
|
|
import json
|
|
import logging
|
|
import os
|
|
from queue import Empty
|
|
from threading import Event, Thread
|
|
|
|
import httpx
|
|
import nltk
|
|
from services.local_s2s.assets import validate_assets, configure_nltk
|
|
from services.local_s2s.components import ComponentServer
|
|
from services.local_s2s.engine import build_runtime
|
|
from app.modules.voice.configuration import VoiceSettings
|
|
|
|
logging.disable(logging.CRITICAL)
|
|
os.environ.update(LOCAL_S2S_SILERO_SOURCE='/vad/silero-vad',
|
|
LOCAL_S2S_STT_MODEL='fixture/stt', LOCAL_S2S_LLM_MODEL='fixture/llm',
|
|
LOCAL_S2S_TTS_MODEL='fixture/tts', LOCAL_S2S_TTS_VOICE='fixture',
|
|
LOCAL_S2S_REQUEST_TIMEOUT_SECONDS='7')
|
|
fingerprint = validate_assets('/assets/nltk', '/vad/silero-vad', '/assets/assets.json')
|
|
configure_nltk(nltk, '/assets/nltk')
|
|
calls = []
|
|
|
|
def upstream(request):
|
|
path = request.url.path
|
|
calls.append(path)
|
|
if path.endswith('/audio/transcriptions'):
|
|
return httpx.Response(200, json={'text': 'fixture'})
|
|
if path.endswith('/audio/speech'):
|
|
return httpx.Response(200, headers={'content-type': 'audio/pcm'}, content=bytes(4800))
|
|
assert path.endswith('/chat/completions')
|
|
payload = json.loads(request.content)
|
|
assert payload['max_tokens'] == 17
|
|
return httpx.Response(200, json={
|
|
'id': 'fixture', 'object': 'chat.completion', 'created': 0, 'model': 'fixture/llm',
|
|
'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': 'fixture'},
|
|
'finish_reason': 'stop'}]})
|
|
|
|
guard = ComponentServer('offline-fixture-key', port=8766,
|
|
transport=httpx.MockTransport(upstream), timeout=7)
|
|
thread = Thread(target=guard.serve_forever, daemon=True)
|
|
thread.start()
|
|
assert guard.ready.wait(3)
|
|
runtime = None
|
|
try:
|
|
config = VoiceSettings(_env_file=None, provider='local_s2s', local_s2s_enabled=True,
|
|
voice_transport_testing=True, local_s2s_stt_model='fixture/stt',
|
|
local_s2s_llm_model='fixture/llm', local_s2s_tts_model='fixture/tts',
|
|
local_s2s_tts_voice='fixture', local_s2s_request_timeout_seconds=7,
|
|
local_s2s_max_output_tokens=17)
|
|
config.require_voice()
|
|
stop = Event()
|
|
runtime = build_runtime(config, stop)
|
|
assert runtime.state == 'constructed' and len(runtime.server.pool) == 1
|
|
import speech_to_speech.s2s_pipeline as pipeline
|
|
queue = pipeline.Queue[int]()
|
|
assert queue.maxsize == 256 and not stop.is_set()
|
|
for index in range(256):
|
|
queue.put(index)
|
|
try:
|
|
queue.put(256)
|
|
except RuntimeError as error:
|
|
assert str(error) == 'LOCAL_ENGINE_QUEUE_CAPACITY'
|
|
else:
|
|
raise AssertionError('overflow must stop the candidate')
|
|
assert stop.is_set()
|
|
assert [queue.get_nowait() for _ in range(256)] == list(range(256))
|
|
try:
|
|
queue.get_nowait()
|
|
except Empty:
|
|
pass
|
|
else:
|
|
raise AssertionError('queue did not drain')
|
|
assert sorted(calls) == sorted(['/api/v1/audio/transcriptions',
|
|
'/api/v1/chat/completions', '/api/v1/audio/speech'])
|
|
print(json.dumps(dict(stage='construction', passed=True, manifest_sha256=fingerprint,
|
|
handlers=[type(h).__name__ for h in runtime.server.pool[0].handlers],
|
|
fixture_requests=calls, counts=dict(guard.counts), paid_calls=0,
|
|
queue_generic_and_capacity='passed', queue_capacity=256)), flush=True)
|
|
finally:
|
|
try:
|
|
if runtime is not None:
|
|
runtime.stop()
|
|
finally:
|
|
guard.shutdown()
|
|
guard.server_close()
|
|
thread.join(3)
|
|
assert not thread.is_alive()
|
|
print(json.dumps(dict(stage='construction_cleanup', passed=True,
|
|
runtime_state=runtime.state, counts=dict(guard.counts))), flush=True)
|