Build Basalt 0.3.3 candidate and integrate media and response controls

This commit is contained in:
Mikei386 committed 2026-11-13 12:53:49 +01:00
1 parent 584a884cc9
commit 34e711721a
44 files changed
+2290 -166

No files matched your search

+12 -2
View File
@@ -11,10 +11,12 @@ from copy import deepcopy
CHAT_FIELDS=frozenset({'model','messages','stream','stream_options','temperature','top_p','top_k','max_tokens','max_completion_tokens','stop','seed','tools','tool_choice','parallel_tool_calls','response_format','repeat_penalty','presence_penalty','frequency_penalty','logprobs','top_logprobs','user','n','reasoning_effort','reasoning_budget_tokens','chat_template_kwargs'})
LLAMA_FIELDS=frozenset({'min_p','typical_p','repeat_last_n','mirostat','mirostat_tau','mirostat_eta','dynatemp_range','dynatemp_exponent','cache_prompt','ignore_eos','reasoning_format','logit_bias'})
ADAPTER_FIELDS=frozenset({'functions','function_call','extra_body','metadata','store','service_tier','safety_identifier','prompt_cache_key'})
CHAT_FIELDS=CHAT_FIELDS|LLAMA_FIELDS|ADAPTER_FIELDS
CHAT_FIELDS=CHAT_FIELDS|LLAMA_FIELDS|ADAPTER_FIELDS|{'session_id'}
def capabilities():
return dict(version=1,chat_route='/v1/chat/completions',fields=sorted(CHAT_FIELDS),llama_extensions=sorted(LLAMA_FIELDS|{'chat_template_kwargs'}),template_options=['enable_thinking','preserve_thinking'],aliases={'max_completion_tokens':'max_tokens','functions':'tools','function_call':'tool_choice'},unsupported_routes=['/v1/responses','/v1/embeddings','/completion','/slots'],model_dependent=['tools','vision','reasoning','json_schema'],notes=['Only n=1; no stored completions or priority service tier.','Model capabilities and backend-version support are not guaranteed by this field list.'])
from chat_control import SESSION_HEADERS
from chat_media import LIMITS
return dict(version=1,chat_route='/v1/chat/completions',fields=sorted(CHAT_FIELDS),llama_extensions=sorted(LLAMA_FIELDS|{'chat_template_kwargs'}),template_options=['enable_thinking','preserve_thinking'],aliases={'max_completion_tokens':'max_tokens','functions':'tools','function_call':'tool_choice'},unsupported_routes=['/v1/responses','/v1/embeddings','/completion','/slots'],model_dependent=['tools','vision','reasoning','json_schema','logprobs','documents','video','answer_now','session_affinity'],model_properties_route='/props?model=API_ID',media_limits=dict(LIMITS),controls={'answer_now_route':'/v1/answer_now','scope':'same_principal','no_model_load':True,'request_id_header':'X-Request-Id','client_request_id_header':'X-Client-Request-Id','session_headers':list(SESSION_HEADERS)},notes=['Only n=1; no stored completions or priority service tier.','Model capabilities and backend-version support are not guaranteed by this field list.','Attachments are inline-only; no external URLs, file IDs or server paths.'])
LLAMA_EFFORTS=frozenset({'none','low','medium','high','xhigh'})
# The installed llama.cpp server rejects minimal and max. Use nearest supported hints.
@@ -35,6 +37,11 @@ def normalize_chat(data):
unknown=set(data)-CHAT_FIELDS
if unknown:raise CompatibilityError('Nicht unterstützte Chat-Felder: '+', '.join(sorted(unknown)))
body=dict(data)
if body.get('session_id') is None:body.pop('session_id',None)
elif 'session_id' in body:
from chat_control import identifier
try:identifier(body['session_id'],'Sitzungskennung')
except ValueError as exc:raise CompatibilityError(str(exc)) from None
ignored=[]
for key in ('metadata','safety_identifier','prompt_cache_key'):
if key in body:
@@ -51,6 +58,9 @@ def normalize_chat(data):
ignored.append('service_tier')
for key in ('stop','stream_options','logprobs','top_logprobs','tools','tool_choice','response_format','logit_bias'):
if body.get(key,'absent') is None:body.pop(key,None)
if 'logprobs' in body and type(body['logprobs']) is not bool:raise CompatibilityError('logprobs muss true oder false sein.')
if 'top_logprobs' in body and (type(body['top_logprobs']) is not int or not 0<=body['top_logprobs']<=20):raise CompatibilityError('top_logprobs muss eine ganze Zahl von 0 bis 20 sein.')
if 'top_logprobs' in body and body.get('logprobs') is not True:raise CompatibilityError('top_logprobs benötigt logprobs=true.')
if 'max_completion_tokens' in body:
value=body.pop('max_completion_tokens')
if value is not None: