crucible / engine /llm_compat.py
s-ttp's picture
Gate calibrated offline (reviewers' standard rubric; extended thinking; bounded retries; run deadline); triggers refuse sources that include a separated business
1cddb1f verified
Raw History Blame Contribute Delete
1.13 kB
"""SDK-drift shims for LLM calls.
anthropic 1.0.0 changed Messages.create()'s signature (temperature= rejected), which
silently broke every Claude call on the Space for a morning — PM synthesis fell back to a
dumb confidence blend while the rest of the run reported success. Route all Claude calls
through claude_create() so a kwarg the installed SDK no longer accepts is dropped and
retried instead of failing the step.
"""
from __future__ import annotations
_DROPPABLE = ("temperature", "top_p", "top_k", "metadata", "thinking") # an SDK without thinking degrades
def claude_create(client, **kw):
"""client.messages.create(**kw), retrying without any kwarg the SDK rejects."""
for _ in range(len(_DROPPABLE) + 1):
try:
return client.messages.create(**kw)
except TypeError as e:
msg = str(e)
dropped = False
for k in _DROPPABLE:
if k in kw and k in msg:
kw.pop(k)
dropped = True
break
if not dropped:
raise
return client.messages.create(**kw)