Files
iishko-public/gateway/request_effort.py
T
reformandClaude Opus 5.5 0ee6fb843b
checks / pytest (push) Has been cancelled
checks / moderation (push) Has been cancelled
checks / node (push) Has been cancelled
IISHKO: Telegram bot, Mini App and gateway
Initial public release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 21:51:30 +03:00

28 lines
1.2 KiB
Python

"""Validate effort metadata without rewriting generation requests or claiming support."""
class InvalidEffort(ValueError):
"""Malformed effort fields, safe to report before dispatch."""
def read_effort(payload):
"""Return the explicit effort; capability checks remain provider-specific."""
if not isinstance(payload, dict):
return None
if payload.get("effort") is not None:
raise InvalidEffort("Use reasoning_effort for Chat Completions or reasoning.effort for Responses.")
values = []
if payload.get("reasoning_effort") is not None:
values.append(payload["reasoning_effort"])
for key in ("reasoning", "output_config"):
value = payload.get(key)
if isinstance(value, dict) and value.get("effort") is not None:
values.append(value["effort"])
if not values:
return None
if any(not isinstance(value, str) or not value.strip() or len(value) > 32 for value in values):
raise InvalidEffort("Specify one non-empty effort string in the request body.")
if len(set(values)) != 1:
raise InvalidEffort("Specify one consistent effort value in the request body.")
return values[0]