p
This commit is contained in:
Binary file not shown.
Binary file not shown.
76
ai_intelligence_layer/models/input_models.py
Normal file
76
ai_intelligence_layer/models/input_models.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""
|
||||
Input data models for the AI Intelligence Layer.
|
||||
Defines schemas for enriched telemetry, race context, and request payloads.
|
||||
"""
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List, Literal, Optional
|
||||
|
||||
|
||||
class EnrichedTelemetryWebhook(BaseModel):
|
||||
"""Single lap of enriched telemetry data from HPC enrichment module."""
|
||||
lap: int = Field(..., description="Lap number")
|
||||
aero_efficiency: float = Field(..., ge=0.0, le=1.0, description="Aerodynamic efficiency (0..1, higher is better)")
|
||||
tire_degradation_index: float = Field(..., ge=0.0, le=1.0, description="Tire wear (0..1, higher is worse)")
|
||||
ers_charge: float = Field(..., ge=0.0, le=1.0, description="Energy recovery system charge level")
|
||||
fuel_optimization_score: float = Field(..., ge=0.0, le=1.0, description="Fuel efficiency score")
|
||||
driver_consistency: float = Field(..., ge=0.0, le=1.0, description="Lap-to-lap consistency")
|
||||
weather_impact: Literal["low", "medium", "high"] = Field(..., description="Weather effect severity")
|
||||
|
||||
|
||||
class RaceInfo(BaseModel):
|
||||
"""Current race information."""
|
||||
track_name: str = Field(..., description="Name of the circuit")
|
||||
total_laps: int = Field(..., gt=0, description="Total race laps")
|
||||
current_lap: int = Field(..., ge=0, description="Current lap number")
|
||||
weather_condition: str = Field(..., description="Current weather (e.g., Dry, Wet, Mixed)")
|
||||
track_temp_celsius: float = Field(..., description="Track temperature in Celsius")
|
||||
|
||||
|
||||
class DriverState(BaseModel):
|
||||
"""Current driver state."""
|
||||
driver_name: str = Field(..., description="Driver name")
|
||||
current_position: int = Field(..., gt=0, description="Current race position")
|
||||
current_tire_compound: Literal["soft", "medium", "hard", "intermediate", "wet"] = Field(..., description="Current tire compound")
|
||||
tire_age_laps: int = Field(..., ge=0, description="Laps on current tires")
|
||||
fuel_remaining_percent: float = Field(..., ge=0.0, le=100.0, description="Remaining fuel percentage")
|
||||
|
||||
|
||||
class Competitor(BaseModel):
|
||||
"""Competitor information."""
|
||||
position: int = Field(..., gt=0, description="Race position")
|
||||
driver: str = Field(..., description="Driver name")
|
||||
tire_compound: Literal["soft", "medium", "hard", "intermediate", "wet"] = Field(..., description="Tire compound")
|
||||
tire_age_laps: int = Field(..., ge=0, description="Laps on current tires")
|
||||
gap_seconds: float = Field(..., description="Gap in seconds (negative if ahead)")
|
||||
|
||||
|
||||
class RaceContext(BaseModel):
|
||||
"""Complete race context."""
|
||||
race_info: RaceInfo
|
||||
driver_state: DriverState
|
||||
competitors: List[Competitor] = Field(default_factory=list)
|
||||
|
||||
|
||||
class Strategy(BaseModel):
|
||||
"""A single race strategy option."""
|
||||
strategy_id: int = Field(..., description="Unique strategy identifier (1-20)")
|
||||
strategy_name: str = Field(..., description="Short descriptive name")
|
||||
stop_count: int = Field(..., ge=1, le=3, description="Number of pit stops")
|
||||
pit_laps: List[int] = Field(..., description="Lap numbers for pit stops")
|
||||
tire_sequence: List[Literal["soft", "medium", "hard", "intermediate", "wet"]] = Field(..., description="Tire compounds in order")
|
||||
brief_description: str = Field(..., description="One sentence rationale")
|
||||
risk_level: Literal["low", "medium", "high", "critical"] = Field(..., description="Risk assessment")
|
||||
key_assumption: str = Field(..., description="Main assumption this strategy relies on")
|
||||
|
||||
|
||||
class BrainstormRequest(BaseModel):
|
||||
"""Request for strategy brainstorming."""
|
||||
enriched_telemetry: Optional[List[EnrichedTelemetryWebhook]] = Field(None, description="Enriched telemetry data")
|
||||
race_context: RaceContext = Field(..., description="Current race context")
|
||||
|
||||
|
||||
class AnalyzeRequest(BaseModel):
|
||||
"""Request for strategy analysis."""
|
||||
enriched_telemetry: Optional[List[EnrichedTelemetryWebhook]] = Field(None, description="Enriched telemetry data")
|
||||
race_context: RaceContext = Field(..., description="Current race context")
|
||||
strategies: List[Strategy] = Field(..., description="Strategies to analyze (typically 20)")
|
||||
14
ai_intelligence_layer/models/internal_models.py
Normal file
14
ai_intelligence_layer/models/internal_models.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
Internal data models for processing.
|
||||
"""
|
||||
from pydantic import BaseModel
|
||||
from typing import Dict, Any
|
||||
|
||||
|
||||
class TelemetryTrends(BaseModel):
|
||||
"""Calculated trends from enriched telemetry."""
|
||||
tire_deg_rate: float # Per lap rate of change
|
||||
aero_efficiency_avg: float # Moving average
|
||||
ers_pattern: str # "charging", "stable", "depleting"
|
||||
fuel_critical: bool # Whether fuel is a concern
|
||||
driver_form: str # "excellent", "good", "inconsistent"
|
||||
91
ai_intelligence_layer/models/output_models.py
Normal file
91
ai_intelligence_layer/models/output_models.py
Normal file
@@ -0,0 +1,91 @@
|
||||
"""
|
||||
Output data models for the AI Intelligence Layer.
|
||||
Defines schemas for strategy generation and analysis results.
|
||||
"""
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List, Literal
|
||||
from models.input_models import Strategy
|
||||
|
||||
|
||||
class BrainstormResponse(BaseModel):
|
||||
"""Response from strategy brainstorming."""
|
||||
strategies: List[Strategy] = Field(..., description="20 diverse strategy options")
|
||||
|
||||
|
||||
class PredictedOutcome(BaseModel):
|
||||
"""Predicted race outcome for a strategy."""
|
||||
finish_position_most_likely: int = Field(..., gt=0, description="Most likely finishing position")
|
||||
p1_probability: int = Field(..., ge=0, le=100, description="Probability of P1 (%)")
|
||||
p2_probability: int = Field(..., ge=0, le=100, description="Probability of P2 (%)")
|
||||
p3_probability: int = Field(..., ge=0, le=100, description="Probability of P3 (%)")
|
||||
p4_or_worse_probability: int = Field(..., ge=0, le=100, description="Probability of P4 or worse (%)")
|
||||
confidence_score: int = Field(..., ge=0, le=100, description="Overall confidence in prediction (%)")
|
||||
|
||||
|
||||
class RiskAssessment(BaseModel):
|
||||
"""Risk assessment for a strategy."""
|
||||
risk_level: Literal["low", "medium", "high", "critical"] = Field(..., description="Overall risk level")
|
||||
key_risks: List[str] = Field(..., description="Primary risks")
|
||||
success_factors: List[str] = Field(..., description="Factors that enable success")
|
||||
|
||||
|
||||
class TelemetryInsights(BaseModel):
|
||||
"""Insights derived from enriched telemetry."""
|
||||
tire_wear_projection: str = Field(..., description="Tire degradation projection")
|
||||
aero_status: str = Field(..., description="Aerodynamic performance status")
|
||||
fuel_margin: str = Field(..., description="Fuel situation assessment")
|
||||
driver_form: str = Field(..., description="Driver consistency assessment")
|
||||
|
||||
|
||||
class EngineerBrief(BaseModel):
|
||||
"""Detailed brief for race engineer."""
|
||||
title: str = Field(..., description="Brief title")
|
||||
summary: str = Field(..., description="Executive summary")
|
||||
key_points: List[str] = Field(..., description="Key decision points")
|
||||
execution_steps: List[str] = Field(..., description="Step-by-step execution plan")
|
||||
|
||||
|
||||
class ECUCommands(BaseModel):
|
||||
"""Electronic Control Unit commands for car setup."""
|
||||
fuel_mode: Literal["LEAN", "STANDARD", "RICH"] = Field(..., description="Fuel consumption mode")
|
||||
ers_strategy: Literal["CONSERVATIVE", "BALANCED", "AGGRESSIVE_DEPLOY"] = Field(..., description="ERS deployment strategy")
|
||||
engine_mode: Literal["SAVE", "STANDARD", "PUSH", "OVERTAKE"] = Field(..., description="Engine power mode")
|
||||
brake_balance_adjustment: int = Field(..., ge=-5, le=5, description="Brake balance adjustment")
|
||||
differential_setting: Literal["CONSERVATIVE", "BALANCED", "AGGRESSIVE"] = Field(..., description="Differential setting")
|
||||
|
||||
|
||||
class AnalyzedStrategy(BaseModel):
|
||||
"""A single analyzed strategy with full details."""
|
||||
rank: int = Field(..., ge=1, le=3, description="Strategy rank (1-3)")
|
||||
strategy_id: int = Field(..., description="Reference to original strategy")
|
||||
strategy_name: str = Field(..., description="Strategy name")
|
||||
classification: Literal["RECOMMENDED", "ALTERNATIVE", "CONSERVATIVE"] = Field(..., description="Strategy classification")
|
||||
predicted_outcome: PredictedOutcome
|
||||
risk_assessment: RiskAssessment
|
||||
telemetry_insights: TelemetryInsights
|
||||
engineer_brief: EngineerBrief
|
||||
driver_audio_script: str = Field(..., description="Radio message to driver")
|
||||
ecu_commands: ECUCommands
|
||||
|
||||
|
||||
class SituationalContext(BaseModel):
|
||||
"""Current situational context and alerts."""
|
||||
critical_decision_point: str = Field(..., description="Current critical decision point")
|
||||
telemetry_alert: str = Field(..., description="Important telemetry alerts")
|
||||
key_assumption: str = Field(..., description="Key assumption for analysis")
|
||||
time_sensitivity: str = Field(..., description="Time-sensitive factors")
|
||||
|
||||
|
||||
class AnalyzeResponse(BaseModel):
|
||||
"""Response from strategy analysis."""
|
||||
top_strategies: List[AnalyzedStrategy] = Field(..., min_length=3, max_length=3, description="Top 3 strategies")
|
||||
situational_context: SituationalContext
|
||||
|
||||
|
||||
class HealthResponse(BaseModel):
|
||||
"""Health check response."""
|
||||
status: str = Field(..., description="Service status")
|
||||
service: str = Field(..., description="Service name")
|
||||
version: str = Field(..., description="Service version")
|
||||
demo_mode: bool = Field(..., description="Whether demo mode is enabled")
|
||||
enrichment_service_url: str = Field(..., description="URL of enrichment service")
|
||||
Reference in New Issue
Block a user