fix(llm-gateway): improve type safety and datetime consistency
- Add type annotations for mypy compliance - Use UTC-aware datetimes consistently (datetime.now(UTC)) - Add type: ignore comments for LiteLLM incomplete stubs - Fix import ordering and formatting - Update pyproject.toml mypy configuration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -63,11 +63,13 @@ class StreamAccumulator:
|
||||
def start(self) -> None:
|
||||
"""Mark stream start."""
|
||||
import time
|
||||
|
||||
self._started_at = time.time()
|
||||
|
||||
def finish(self) -> None:
|
||||
"""Mark stream finish."""
|
||||
import time
|
||||
|
||||
self._finished_at = time.time()
|
||||
|
||||
def add_chunk(
|
||||
@@ -193,7 +195,7 @@ def format_sse_chunk(chunk: StreamChunk) -> str:
|
||||
Returns:
|
||||
SSE-formatted string
|
||||
"""
|
||||
data = {
|
||||
data: dict[str, Any] = {
|
||||
"id": chunk.id,
|
||||
"delta": chunk.delta,
|
||||
}
|
||||
@@ -278,7 +280,9 @@ class StreamBuffer:
|
||||
yield chunk
|
||||
|
||||
|
||||
async def stream_to_string(stream: AsyncIterator[StreamChunk]) -> tuple[str, UsageStats | None]:
|
||||
async def stream_to_string(
|
||||
stream: AsyncIterator[StreamChunk],
|
||||
) -> tuple[str, UsageStats | None]:
|
||||
"""
|
||||
Consume a stream and return full content.
|
||||
|
||||
@@ -331,9 +335,7 @@ async def merge_streams(
|
||||
pending.add(task)
|
||||
|
||||
while pending:
|
||||
done, pending = await asyncio.wait(
|
||||
pending, return_when=asyncio.FIRST_COMPLETED
|
||||
)
|
||||
done, pending = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED)
|
||||
|
||||
for task in done:
|
||||
idx, chunk = task.result()
|
||||
|
||||
Reference in New Issue
Block a user