diff --git a/python/app/claude.py b/python/app/claude.py index 7c8ef93..c1d6f16 100644 --- a/python/app/claude.py +++ b/python/app/claude.py @@ -82,7 +82,10 @@ def _model_options(model: str, max_tokens: int) -> dict: """ if model.startswith(_NO_EFFORT_PREFIXES): 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( @@ -122,7 +125,11 @@ def ask_json( NotConfigured: no API key. 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: 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. 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) # 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) if text is None: 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) try: