mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-01 00:31:51 +03:00
refactor(providers): define typed usage contract
This commit is contained in:
@@ -12,6 +12,7 @@ from nanobot.bus.runtime_events import (
|
||||
TurnRunStatusChanged,
|
||||
TurnRuntimeAdmitted,
|
||||
)
|
||||
from nanobot.providers.base import LLMUsage
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -99,7 +100,7 @@ async def test_runtime_event_publisher_consumes_turn_metadata_on_complete() -> N
|
||||
bus.subscribe(seen.append)
|
||||
publisher.record_turn_runtime("cli:direct", "runtime")
|
||||
publisher.record_turn_latency("cli:direct", 123)
|
||||
publisher.record_turn_usage("cli:direct", {"prompt_tokens": 40, "completion_tokens": 2})
|
||||
publisher.record_turn_usage("cli:direct", LLMUsage.reported(input_tokens=40, output_tokens=2))
|
||||
|
||||
await publisher.turn_completed(
|
||||
channel="cli",
|
||||
@@ -120,11 +121,11 @@ async def test_runtime_event_publisher_consumes_turn_metadata_on_complete() -> N
|
||||
assert first.context.metadata == {"source": "test"}
|
||||
assert first.latency_ms == 123
|
||||
assert first.runtime == "runtime"
|
||||
assert first.usage == {"prompt_tokens": 40, "completion_tokens": 2}
|
||||
assert first.usage == LLMUsage.reported(input_tokens=40, output_tokens=2)
|
||||
assert isinstance(second, TurnCompleted)
|
||||
assert second.latency_ms is None
|
||||
assert second.runtime is None
|
||||
assert second.usage == {}
|
||||
assert second.usage is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user