Extract the provider boundary while retaining OpenAI/Gemini contracts. Add an opt-in isolated Local S2S adapter, pinned engine extension, bounded component gateway and frozen effective configuration profiles. Enforce request token limits, zero retries, local asset validation, connection deadlines, disconnect ownership, bounded cleanup and signals. Include regression coverage, pinned source fixtures, operator guidance, asset fingerprints and guarded disposable PostgreSQL acceptance tooling. Preserve immutable fixture bytes across Git line-ending conversion. Validation recorded in the reports: - 74 repair, 107 combined and 242 preservation checks passed. - Fresh PostgreSQL local checks: 2 passed. - Expanded PostgreSQL: 57 passed, 6 documented baseline failures. - Compose configurations, staged whitespace and fixture hashes passed. Phase 1 live listening and Phase 2 complete engine/SDK/POSIX, real component audio and Persian browser acceptance remain pending. No operational switch, paid call, model download or Phase 3 implementation is included.
38 lines
2.1 KiB
Python
38 lines
2.1 KiB
Python
"""Selected voice transport construction shared by the API and operator smoke."""
|
|
import asyncio
|
|
from app.modules.voice.provider import VoiceProvider
|
|
from app.infrastructure.gemini_live import GeminiLiveAdapter, connect_gemini
|
|
from app.infrastructure.realtime import RealtimeAdapter, connect as connect_openai
|
|
|
|
|
|
async def create_adapter(config, limits) -> VoiceProvider:
|
|
config.require_voice()
|
|
if config.provider == 'local_s2s':
|
|
from app.infrastructure.local_s2s import LocalS2SAdapter, connect_local
|
|
if limits.output_capacity_profile != 'standard':
|
|
raise ValueError('OpenAI output capacity cannot be used for local S2S')
|
|
transport = await asyncio.wait_for(connect_local(config, limits), limits.connect_timeout_seconds)
|
|
try:
|
|
return LocalS2SAdapter(transport, config=config, settings=limits)
|
|
except BaseException:
|
|
await asyncio.wait_for(transport.close(), limits.send_timeout_seconds)
|
|
raise
|
|
if config.provider == 'gemini' and limits.output_capacity_profile != 'standard':
|
|
raise ValueError('OpenAI output capacity cannot be used for Gemini')
|
|
input_settings = None
|
|
if config.provider == 'openai':
|
|
from app.modules.voice.configuration import OpenAIInputSettings
|
|
input_settings = OpenAIInputSettings.model_validate({
|
|
key: getattr(config, key) for key in OpenAIInputSettings.model_fields})
|
|
input_settings.reasoning(config.selected_model)
|
|
connect = connect_gemini if config.provider == 'gemini' else connect_openai
|
|
transport = await asyncio.wait_for(connect(config.selected_key.get_secret_value(),
|
|
config.selected_model, config.selected_proxy, limits), limits.connect_timeout_seconds)
|
|
try:
|
|
adapter = GeminiLiveAdapter if config.provider == 'gemini' else RealtimeAdapter
|
|
return adapter(transport, model=config.selected_model, voice=config.selected_voice, settings=limits,
|
|
**({'input_settings': input_settings} if config.provider == 'openai' else {}))
|
|
except BaseException:
|
|
await asyncio.wait_for(transport.close(), limits.send_timeout_seconds)
|
|
raise
|