Accept validated thinking template options in chat compatibility layer
This commit is contained in:
1 parent
b451b52a57
commit
c9036201f7
2 files changed
+17
-1
No files matched your search
+8
-1
@@ -5,7 +5,7 @@ positive levels to the model template; it handles 'none' as thinking disabled.
|
||||
"""
|
||||
import math
|
||||
|
||||
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'})
|
||||
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','chat_template_kwargs'})
|
||||
LLAMA_EFFORTS=frozenset({'none','low','medium','high','xhigh'})
|
||||
# The installed llama.cpp server rejects minimal and max. Use nearest supported hints.
|
||||
EFFORT_ALIASES={'minimal':'low','max':'xhigh','ultra':'xhigh'}
|
||||
@@ -17,6 +17,13 @@ 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 'chat_template_kwargs' in body:
|
||||
kwargs=body['chat_template_kwargs']
|
||||
if not isinstance(kwargs,dict) or set(kwargs)-{'enable_thinking','preserve_thinking'}:
|
||||
raise CompatibilityError('chat_template_kwargs unterstützt enable_thinking und preserve_thinking.')
|
||||
if any(type(v) is not bool for v in kwargs.values()):
|
||||
raise CompatibilityError('Thinking-Template-Optionen müssen true oder false sein.')
|
||||
body['chat_template_kwargs']=dict(kwargs)
|
||||
for key,lo,hi in [('repeat_penalty',0,2),('presence_penalty',-2,2),('frequency_penalty',-2,2)]:
|
||||
if key in body:
|
||||
value=body[key]
|
||||
|
||||
Reference in new issue
Block a user