Resolve generic TTS from audio publication and preserve admitted work during drain

This commit is contained in:
Mikei386 committed 2026-10-27 12:16:39 +01:00
1 parent c60de7db2c
commit e83b30badc
4 files changed
+112 -5

No files matched your search

+13 -5
View File
@@ -369,7 +369,7 @@ class APIHandler(BaseHTTPRequestHandler):
def do_HEAD(self):self.route()
def do_OPTIONS(self):self.route()
def route(self):
ep=self.server.endpoint;admitted=False
ep=self.server.endpoint;admitted=False;self._admitted=False
try:
browser=bool(ep.video and ep.scheduler.gpu_mode=='video' and getattr(ep,'video_browser_auth',lambda h:False)(self.headers))
service_auth=bool(ep.video and callable(getattr(type(ep.video),'service_authenticated',None)) and ep.video.service_authenticated(self.headers.get('Authorization','')))
@@ -378,7 +378,7 @@ class APIHandler(BaseHTTPRequestHandler):
if origin and (not browser or origin not in ('http://'+self.headers.get('Host',''),'https://'+self.headers.get('Host',''))):raise APIError('Cross-Origin-API-Zugriff nicht erlaubt.',403)
with ep.lock:
if not ep.allowed():raise APIError('Endpunkt wird gestoppt.',503,'endpoint_stopping')
ep.inflight+=1;admitted=True
ep.inflight+=1;admitted=True;self._admitted=True
parsed=urlsplit(self.path)
if self.command=='GET' and parsed.path=='/v1/telemetry/speed':
provider=getattr(ep,'speed_telemetry',None)
@@ -507,7 +507,13 @@ class APIHandler(BaseHTTPRequestHandler):
started=time.monotonic()
if data.get('model')=='tts':
from profiles import voice_recipe
candidates=[p for p in ep.rows() if p['enabled'] and (p['kind']=='audio' or p.get('model') and voice_recipe(p['model']))]
rows=ep.rows()
# The TTS publication controls the generic speech alias. Voice-tool
# profiles may also synthesize text, but must not make a separately
# published TTS profile ambiguous. Preserve voice-only clients when
# no dedicated audio profile is published.
candidates=[p for p in rows if p['enabled'] and p['kind']=='audio']
if not candidates:candidates=[p for p in rows if p['enabled'] and p.get('model') and voice_recipe(p['model'])]
if len(candidates)!=1:raise APIError('Für model=tts genau ein TTS-Profil am Endpunkt freigeben.',409,'tts_default_ambiguous')
data=dict(data,model=candidates[0].get('api_id',candidates[0]['name']))
from humaneness_runtime import supported as humaneness_model
@@ -652,8 +658,10 @@ class APIHandler(BaseHTTPRequestHandler):
except (ValueError,binascii.Error):raise APIError('Ungültige Bildkodierung.') from None
if not raw:raise APIError('Leeres Bild.')
# Re-resolve after waiting so edits/disable cannot silently launch a stale profile.
# Drain preserves requests admitted before stop; route() still rejects
# all new requests while stopping.
key=('chat',profile['id'],profile['revision'])
def allowed():return ep.allowed() and any(p['id']==profile['id'] and p['revision']==profile['revision'] and p['enabled'] for p in ep.rows())
def allowed():return (ep.allowed() or self._admitted and ep.state=='stopping') and any(p['id']==profile['id'] and p['revision']==profile['revision'] and p['enabled'] for p in ep.rows())
with ep.scheduler.lease(key,profile['parameters']['slots'],lambda:ep.worker.ensure(profile),allowed=allowed):
body=dict(data)
for field,value in generation_parameters(profile['parameters']).items():body.setdefault(field,value)
@@ -701,7 +709,7 @@ class APIHandler(BaseHTTPRequestHandler):
size=data.get('size')
if size is not None and (not isinstance(size,str) or (size!='auto' and not re.fullmatch(r'[1-9][0-9]{1,4}x[1-9][0-9]{1,4}',size))):raise APIError('size muss auto oder eine Auflösung wie 1024x1024 sein.')
# The selected profile owns resource limits; client size is only a preference.
def allowed():return ep.allowed() and any(p['id']==profile['id'] and p['revision']==profile['revision'] and p['enabled'] for p in ep.rows())
def allowed():return (ep.allowed() or self._admitted and ep.state=='stopping') and any(p['id']==profile['id'] and p['revision']==profile['revision'] and p['enabled'] for p in ep.rows())
with ep.scheduler.lease(('image',),allowed=allowed):
return self.generate_image(ep,profile,data,reference_images or [])
def generate_image(self,ep,profile,data,reference_images=None):