feat(voice): implement local S2S retained history and provider selection
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.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""Offline browser-path reproduction: real native handlers, fixture HTTP only."""
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from threading import Thread
|
||||
import httpx
|
||||
from services.local_s2s.components import ComponentServer
|
||||
import services.local_s2s.lifecycle as lifecycle
|
||||
from services.local_s2s.engine import main
|
||||
|
||||
async def upstream(request):
|
||||
if request.url.path.endswith('/transcriptions'):
|
||||
return httpx.Response(200,json={'text':'سلام'})
|
||||
if request.url.path.endswith('/speech'):
|
||||
from speech_to_speech.pipeline.language_detection import warm_language_detector
|
||||
print(json.dumps({'stage':'fixture_language_cache','cache':warm_language_detector.cache_info()._asdict()}),flush=True)
|
||||
return httpx.Response(200,headers={'content-type':'audio/pcm'},content=b'\x01\x00'*4800)
|
||||
data=json.loads(request.content)
|
||||
if not data.get('stream'):
|
||||
return httpx.Response(200,json={'id':'fixture','object':'chat.completion','created':0,'model':data['model'],'choices':[{'index':0,'message':{'role':'assistant','content':'سلام'},'finish_reason':'stop'}]})
|
||||
class Delayed(httpx.AsyncByteStream):
|
||||
async def __aiter__(self):
|
||||
for _ in range(12):
|
||||
yield b': heartbeat\n\n'
|
||||
await asyncio.sleep(1)
|
||||
for text,stop in (('سلام.',None),('', 'stop')):
|
||||
chunk={'id':'fixture','object':'chat.completion.chunk','created':0,'model':data['model'],'choices':[{'index':0,'delta':{'content':text},'finish_reason':stop}]}
|
||||
yield ('data: '+json.dumps(chunk)+'\n\n').encode()
|
||||
yield b'data: [DONE]\n\n'
|
||||
return httpx.Response(200,headers={'content-type':'text/event-stream'},stream=Delayed())
|
||||
|
||||
def gateway(key,timeout):
|
||||
server=ComponentServer('offline-fixture',transport=httpx.MockTransport(upstream),timeout=timeout)
|
||||
thread=Thread(target=server.serve_forever,daemon=True);thread.start()
|
||||
if not server.ready.wait(5):raise RuntimeError('Fixture gateway did not start')
|
||||
return server,thread
|
||||
|
||||
|
||||
lifecycle.start_components=gateway
|
||||
os.environ['OPENROUTER_API_KEY']='offline-fixture'
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user