From 8bbd0aa96abe9d44d5988e6c4f988f2d7b0f855a Mon Sep 17 00:00:00 2001 From: guillaumefontan Date: Wed, 12 Mar 2025 11:03:00 +0100 Subject: [PATCH 1/3] add thread_id to llm_events --- CHANGELOG.md | 3 +++ README.md | 6 +++--- trubrics/main.py | 3 +++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1e990d..dc90501 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- thread_id to 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..1c6407e 100644 --- a/trubrics/main.py +++ b/trubrics/main.py @@ -119,6 +119,7 @@ def track_llm( properties: dict | None = None, timestamp: datetime | None = None, latency: float | None = None, + thread_id: str | None = None, ): """ Track an LLM prompt and generation. @@ -130,6 +131,7 @@ def track_llm( 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), } with self._lock: From 59ddb17e65648b5f54c89817a4f4579058d56efd Mon Sep 17 00:00:00 2001 From: guillaumefontan Date: Wed, 12 Mar 2025 11:09:38 +0100 Subject: [PATCH 2/3] assistant_id optional --- CHANGELOG.md | 3 +++ trubrics/main.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc90501..3ab54f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 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/trubrics/main.py b/trubrics/main.py index 1c6407e..63f260a 100644 --- a/trubrics/main.py +++ b/trubrics/main.py @@ -114,8 +114,8 @@ 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, @@ -126,8 +126,8 @@ def track_llm( 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. From e76fcd822f76a3c15737488c9f06a8156fdaeedf Mon Sep 17 00:00:00 2001 From: guillaumefontan Date: Wed, 12 Mar 2025 15:14:32 +0100 Subject: [PATCH 3/3] fix thread bug --- trubrics/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trubrics/main.py b/trubrics/main.py index 63f260a..dc3c58d 100644 --- a/trubrics/main.py +++ b/trubrics/main.py @@ -147,7 +147,7 @@ def track_llm( ), "latency": latency, "event_type": EventTypes.llm_event, - "thread_id": str(thread_id), + "thread_id": str(thread_id) if thread_id else None, } with self._lock: