@owndev v2.7.0 time_token_tracker.py
Python · 1,590 lines401 class Valves(BaseModel):402 priority: int = Field(403 default=0, description="Priority level for the filter operations."404 )405 CALCULATE_ALL_MESSAGES: bool = Field(406 default=True,407 description="If true, calculate tokens for all messages. If false, only use the last user and assistant messages.",408 )409 SHOW_AVERAGE_TOKENS: bool = Field(410 default=True,411 description="Show average tokens per message (only used if CALCULATE_ALL_MESSAGES is true).",412 ) Time Token Tracker
A filter for tracking the response time and token usage of a request.
Features
- Tracks the response time of a request.
- Tracks Token Usage.
- Calculates the average tokens per message.
- Calculates the tokens per second.
- Sends metrics to Azure Log Analytics in the background (10 s timeout), so responses do not wait for it: through the Azure Monitor Logs Ingestion API (data collection rule, Microsoft Entra ID token from a client secret, a managed identity on App Service / Functions / Container Apps / VMs, or AKS workload identity; tokens are cached and refreshed before they expire), or through the deprecated HTTP Data Collector API (shared key) as a fallback. LOG_ANALYTICS_INGESTION_API selects auto, logs_ingestion, data_collector or both.
- Falls back to a len(text) // 4 token estimate while no tiktoken encoding is loaded (e.g. offline), without holding up requests. Estimates are marked (tokensEstimated in the record and the log line, "~" in the status).
- Sends metrics to Azure Log Analytics.
GitHub
Note
For questions, problems, and feature requests, an issue must be created on GitHub.
License
0
0 
