diff --git a/CHANGELOG.md b/CHANGELOG.md index c1e990d..3ab54f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- thread_id to track_llm_events + +### Changed +- assistant_id now optional in track_llm_events + ## [1.8.3] - 2025-02-26 ### Changed - Change logging level to debug for flushing events and adding event to queue diff --git a/README.md b/README.md index 077211a..33ba6c2 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,10 @@ client.track_llm( assistant_id="gpt-4", generation="The capital of France is Paris.", properties={ - "$thread_id": "your-thread-id", # special trubrics property to group an interaction by conversation thread - "model": "gpt-4" + "support_tier": "entreprise", }, - latency=1.5 # seconds + latency=1.5, # seconds + thread_id="user123_thread_id" ) ``` diff --git a/trubrics/main.py b/trubrics/main.py index e6ec2c2..dc3c58d 100644 --- a/trubrics/main.py +++ b/trubrics/main.py @@ -114,22 +114,24 @@ def track_llm( self, user_id: str, prompt: str, - assistant_id: str, generation: str, + assistant_id: str | None = None, properties: dict | None = None, timestamp: datetime | None = None, latency: float | None = None, + thread_id: str | None = None, ): """ Track an LLM prompt and generation. Args: user_id (str): The ID of the user. prompt (str): The prompt given to the LLM. - assistant_id (str): The ID of the assistant. generation (str): The generated response from the LLM. + assistant_id (str | None): The ID of the assistant. properties (dict | None): Additional properties to track. timestamp (datetime | None): The timestamp of the generation event. If None, the current time in UTC is used. latency (float | None): The latency in seconds between the prompt and the generation. Defaults to 1. + thread_id (str | None): The ID of the thread, used to link messages in a conversation. """ llm_event_dict = { @@ -145,6 +147,7 @@ def track_llm( ), "latency": latency, "event_type": EventTypes.llm_event, + "thread_id": str(thread_id) if thread_id else None, } with self._lock: