Format claude.py
Test and deploy / deploy (push) Has been cancelled
Test and deploy / test (push) Has been cancelled

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-26 14:17:38 +00:00
co-authored by Claude Opus 5.5
parent 705804c503
commit d0ff2e125b
+16 -4
View File
@@ -82,7 +82,10 @@ def _model_options(model: str, max_tokens: int) -> dict:
""" """
if model.startswith(_NO_EFFORT_PREFIXES): if model.startswith(_NO_EFFORT_PREFIXES):
return {"max_tokens": max_tokens} return {"max_tokens": max_tokens}
return {"max_tokens": max_tokens + THINKING_HEADROOM, "output_config": {"effort": EFFORT}} return {
"max_tokens": max_tokens + THINKING_HEADROOM,
"output_config": {"effort": EFFORT},
}
def ask_json( def ask_json(
@@ -122,7 +125,11 @@ def ask_json(
NotConfigured: no API key. NotConfigured: no API key.
ReadError: with one of the three messages above. ReadError: with one of the three messages above.
""" """
request = {"model": MODEL, "messages": messages, **_model_options(MODEL, max_tokens)} request = {
"model": MODEL,
"messages": messages,
**_model_options(MODEL, max_tokens),
}
if system is not None: if system is not None:
request["system"] = system request["system"] = system
@@ -139,14 +146,19 @@ def ask_json(
# A refusal is a 200; log it as such rather than as an unparseable reply. # A refusal is a 200; log it as such rather than as an unparseable reply.
if getattr(message, "stop_reason", None) == "refusal": if getattr(message, "stop_reason", None) == "refusal":
log.warning("Claude declined the request: %s", getattr(message, "stop_details", None)) log.warning(
"Claude declined the request: %s", getattr(message, "stop_details", None)
)
raise ReadError(failed) raise ReadError(failed)
# By type: on a thinking model the first block may be a thinking block. # By type: on a thinking model the first block may be a thinking block.
text = next((block.text for block in message.content if block.type == "text"), None) text = next((block.text for block in message.content if block.type == "text"), None)
if text is None: if text is None:
if getattr(message, "stop_reason", None) == "max_tokens": if getattr(message, "stop_reason", None) == "max_tokens":
log.warning("Claude ran out of tokens before answering (max_tokens=%s)", request["max_tokens"]) log.warning(
"Claude ran out of tokens before answering (max_tokens=%s)",
request["max_tokens"],
)
raise ReadError(empty) raise ReadError(empty)
try: try: