1. Fleshed out MetricsFrames and broke it into a proper set of types 2. Add model_name as a property to the AIService so that it can be automatically included in metrics and also remove that overhead from all the various services themselves Breaking change! Because of the types improvements, the MetricsFrame type has changed. Each frame will have a list of metrics simlilar to before except each item in the list will only contain one type of metric: "ttfb", "tokens", "characters", or "processing". Previously these fields would be in every entry but set to None if they didn't apply. While this changes internal handling of the MetricsFrame, it does NOT break the RTVI/daily messaging of metrics. That format remains the same. Also. Remember to use model_name for accessing a service's current model and set_model_name for setting it.
32 lines
592 B
Python
32 lines
592 B
Python
from typing import Optional
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class MetricsData(BaseModel):
|
|
processor: str
|
|
model: Optional[str] = None
|
|
|
|
|
|
class TTFBMetricsData(MetricsData):
|
|
value: float
|
|
|
|
|
|
class ProcessingMetricsData(MetricsData):
|
|
value: float
|
|
|
|
|
|
class LLMTokenUsage(BaseModel):
|
|
prompt_tokens: int
|
|
completion_tokens: int
|
|
total_tokens: int
|
|
cache_read_input_tokens: Optional[int] = None
|
|
cache_creation_input_tokens: Optional[int] = None
|
|
|
|
|
|
class LLMUsageMetricsData(MetricsData):
|
|
value: LLMTokenUsage
|
|
|
|
|
|
class TTSUsageMetricsData(MetricsData):
|
|
value: int
|