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:
@@ -6,7 +6,7 @@ Per ADR-004: LLM Provider Abstraction.
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
@@ -282,7 +282,9 @@ class CompletionRequest(BaseModel):
|
||||
model_override: str | None = Field(
|
||||
default=None, description="Specific model to use (bypasses routing)"
|
||||
)
|
||||
max_tokens: int = Field(default=4096, ge=1, le=32768, description="Max output tokens")
|
||||
max_tokens: int = Field(
|
||||
default=4096, ge=1, le=32768, description="Max output tokens"
|
||||
)
|
||||
temperature: float = Field(
|
||||
default=0.7, ge=0.0, le=2.0, description="Sampling temperature"
|
||||
)
|
||||
@@ -330,7 +332,7 @@ class CompletionResponse(BaseModel):
|
||||
)
|
||||
usage: UsageStats = Field(default_factory=UsageStats, description="Token usage")
|
||||
created_at: datetime = Field(
|
||||
default_factory=datetime.utcnow, description="Response timestamp"
|
||||
default_factory=lambda: datetime.now(UTC), description="Response timestamp"
|
||||
)
|
||||
metadata: dict[str, Any] = Field(
|
||||
default_factory=dict, description="Additional metadata"
|
||||
@@ -354,9 +356,7 @@ class EmbeddingRequest(BaseModel):
|
||||
project_id: str = Field(..., description="Project ID for cost attribution")
|
||||
agent_id: str = Field(..., description="Agent ID making the request")
|
||||
texts: list[str] = Field(..., min_length=1, description="Texts to embed")
|
||||
model: str = Field(
|
||||
default="text-embedding-3-large", description="Embedding model"
|
||||
)
|
||||
model: str = Field(default="text-embedding-3-large", description="Embedding model")
|
||||
|
||||
|
||||
class EmbeddingResponse(BaseModel):
|
||||
@@ -377,7 +377,7 @@ class CostRecord:
|
||||
prompt_tokens: int
|
||||
completion_tokens: int
|
||||
cost_usd: float
|
||||
timestamp: datetime = field(default_factory=datetime.utcnow)
|
||||
timestamp: datetime = field(default_factory=lambda: datetime.now(UTC))
|
||||
session_id: str | None = None
|
||||
request_id: str | None = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user