MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / one_at_a_time

Method one_at_a_time

tests/test_open_telemetry.py:6537–6552  ·  view source on GitHub ↗
(attributes: dict[AttributeName, Any], limit: int)

Source from the content-addressed store, hash-verified

6535 return sum(utf8_size(to_json(value)) for value in values.values())
6536
6537 def one_at_a_time(attributes: dict[AttributeName, Any], limit: int) -> tuple[dict[str, str], bool]:
6538 values: dict[str, Any] = json.loads(json.dumps({k: v for k, v in attributes.items() if v is not None}))
6539 lists = [values[SYSTEM]] if SYSTEM in values else []
6540 lists += [message["parts"] for key in (INPUT, OUTPUT) for message in values.get(key, [])]
6541 truncated = False
6542 while size(values) > limit and sum(map(len, lists)) > 1:
6543 next(parts for parts in lists if parts).pop(0)
6544 truncated = True
6545 for parts in lists:
6546 if size(values) > limit and parts and parts[0]["type"] != "text":
6547 parts.pop(0)
6548 truncated = True
6549 while size(values) > limit and parts and parts[0]["content"]:
6550 parts[0]["content"] = parts[0]["content"][:-1]
6551 truncated = True
6552 return {key: to_json(value) for key, value in values.items()}, truncated
6553
6554 def some_of(parts: list[Part]) -> list[Part]:
6555 return parts[random.randrange(len(parts) + 1) :]

Callers

nothing calls this directly

Calls 2

to_jsonFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected