e4dcfc49aa
Tests / Import Check (Python 3.13) (push) Has been cancelled
Tests / Import Check (Python 3.14) (push) Has been cancelled
Tests / Python Tests (Python 3.11) (push) Has been cancelled
Tests / Python Tests (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.14) (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled
Tests / Lint and Format (push) Has been cancelled
Tests / Web Node Tests (push) Has been cancelled
Tests / Import Check (Python 3.11) (push) Has been cancelled
Tests / Import Check (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.13) (push) Has been cancelled
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
"""
|
|
LLM Telemetry
|
|
=============
|
|
|
|
Basic telemetry tracking for LLM calls.
|
|
"""
|
|
|
|
from collections.abc import Awaitable, Callable
|
|
import functools
|
|
import logging
|
|
from typing import TypeVar
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
def track_llm_call(
|
|
provider_name: str,
|
|
) -> Callable[[Callable[..., Awaitable[T]]], Callable[..., Awaitable[T]]]:
|
|
"""
|
|
Decorator to track LLM calls for telemetry.
|
|
|
|
Args:
|
|
provider_name: Name of the provider being called
|
|
|
|
Returns:
|
|
Decorator function
|
|
"""
|
|
|
|
def decorator(func: Callable[..., Awaitable[T]]) -> Callable[..., Awaitable[T]]:
|
|
@functools.wraps(func)
|
|
async def wrapper(*args, **kwargs):
|
|
logger.debug("LLM call to %s: %s", provider_name, func.__name__)
|
|
try:
|
|
result = await func(*args, **kwargs)
|
|
logger.debug("LLM call to %s completed successfully", provider_name)
|
|
return result
|
|
except Exception as e:
|
|
logger.warning("LLM call to %s failed: %s", provider_name, e)
|
|
raise
|
|
|
|
return wrapper
|
|
|
|
return decorator
|