Expose model capability hints and configurable vision projector placement

This commit is contained in:
Mikei386
2026-09-28 22:03:39 +02:00
parent a36a151c94
commit 06c6292cf3
10 changed files with 112 additions and 21 deletions
+16 -2
View File
@@ -179,10 +179,24 @@ class APIHandler(BaseHTTPRequestHandler):
if data.get('n',1)!=1:raise APIError('Zunächst wird n=1 unterstützt.')
messages=data.get('messages')
if not isinstance(messages,list) or not messages or any(not isinstance(m,dict) for m in messages):raise APIError('messages muss eine nichtleere Liste sein.')
profile=ep.find_profile(data.get('model'),'chat')
images=0
for message in messages:
content=message.get('content')
if isinstance(content,list) and any(not isinstance(c,dict) or c.get('type')!='text' for c in content):raise APIError('Dieses Chatprofil unterstützt derzeit nur Text, keinen Vision-Projektor.')
profile=ep.find_profile(data.get('model'),'chat')
if isinstance(content,list):
for part in content:
if not isinstance(part,dict):raise APIError('Ungültiger Nachrichteninhalt.')
if part.get('type')=='text':continue
if part.get('type')!='image_url' or not profile['parameters'].get('vision_projector'):raise APIError('Für Bildeingaben einen Vision-Projektor im Profil aktivieren.')
value=part.get('image_url')
url=value.get('url') if isinstance(value,dict) else None
if not isinstance(url,str) or not url.startswith(('data:image/png;base64,','data:image/jpeg;base64,','data:image/webp;base64,')):raise APIError('Nur eingebettete PNG/JPEG/WebP-Bilder; keine externen URLs.')
import base64,binascii
try:raw=base64.b64decode(url.split(',',1)[1],validate=True)
except (ValueError,binascii.Error):raise APIError('Ungültige Bildkodierung.') from None
if not raw:raise APIError('Leeres Bild.')
images+=1
if images>1:raise APIError('Zunächst ein Bild pro Anfrage unterstützt.')
# Re-resolve after waiting so edits/disable cannot silently launch a stale profile.
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())