Expose model capability hints and configurable vision projector placement
This commit is contained in:
+16
-2
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user