diff --git a/.release-please-manifest.json b/.release-please-manifest.json index bcd0522..e7ca613 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.6.0" + ".": "0.7.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 6294c77..babe57b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to the LaunchDarkly Python AI package will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org). +## [0.7.0](https://github.com/launchdarkly/python-server-sdk-ai/compare/0.6.0...0.7.0) (2025-01-23) + + +### Features + +* Add ability to track time to first token for LDAIConfigTracker ([#37](https://github.com/launchdarkly/python-server-sdk-ai/issues/37)) ([b4a5757](https://github.com/launchdarkly/python-server-sdk-ai/commit/b4a5757ab7a1a8149891977cdfc25bdd4f7bba09)) + ## [0.6.0](https://github.com/launchdarkly/python-server-sdk-ai/compare/0.5.0...0.6.0) (2024-12-17) diff --git a/PROVENANCE.md b/PROVENANCE.md index 097c4ab..83049af 100644 --- a/PROVENANCE.md +++ b/PROVENANCE.md @@ -10,7 +10,7 @@ To verify SLSA provenance attestations, we recommend using [slsa-verifier](https ``` # Set the version of the library to verify -VERSION=0.6.0 +VERSION=0.7.0 ``` diff --git a/ldai/__init__.py b/ldai/__init__.py index 42c2d87..ebe38f1 100644 --- a/ldai/__init__.py +++ b/ldai/__init__.py @@ -1 +1 @@ -__version__ = "0.6.0" # x-release-please-version +__version__ = "0.7.0" # x-release-please-version diff --git a/ldai/testing/test_tracker.py b/ldai/testing/test_tracker.py index 3196bfb..14215a9 100644 --- a/ldai/testing/test_tracker.py +++ b/ldai/testing/test_tracker.py @@ -75,6 +75,21 @@ def test_tracks_duration_of(client: LDClient): assert calls[0].args[3] == pytest.approx(10, rel=10) +def test_tracks_time_to_first_token(client: LDClient): + context = Context.create('user-key') + tracker = LDAIConfigTracker(client, "variation-key", "config-key", context) + tracker.track_time_to_first_token(100) + + client.track.assert_called_with( # type: ignore + '$ld:ai:tokens:ttf', + context, + {'variationKey': 'variation-key', 'configKey': 'config-key'}, + 100 + ) + + assert tracker.get_summary().time_to_first_token == 100 + + def test_tracks_duration_of_with_exception(client: LDClient): context = Context.create('user-key') tracker = LDAIConfigTracker(client, "variation-key", "config-key", context) diff --git a/ldai/tracker.py b/ldai/tracker.py index 8f3c15c..b29ec6f 100644 --- a/ldai/tracker.py +++ b/ldai/tracker.py @@ -40,6 +40,7 @@ def __init__(self): self._success = None self._feedback = None self._usage = None + self._time_to_first_token = None @property def duration(self) -> Optional[int]: @@ -57,6 +58,10 @@ def feedback(self) -> Optional[Dict[str, FeedbackKind]]: def usage(self) -> Optional[TokenUsage]: return self._usage + @property + def time_to_first_token(self) -> Optional[int]: + return self._time_to_first_token + class LDAIConfigTracker: """ @@ -102,6 +107,17 @@ def track_duration(self, duration: int) -> None: '$ld:ai:duration:total', self._context, self.__get_track_data(), duration ) + def track_time_to_first_token(self, time_to_first_token: int) -> None: + """ + Manually track the time to first token of an AI operation. + + :param time_to_first_token: Time to first token in milliseconds. + """ + self._summary._time_to_first_token = time_to_first_token + self._ld_client.track( + '$ld:ai:tokens:ttf', self._context, self.__get_track_data(), time_to_first_token + ) + def track_duration_of(self, func): """ Automatically track the duration of an AI operation. diff --git a/pyproject.toml b/pyproject.toml index 4225b10..d462edf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "launchdarkly-server-sdk-ai" -version = "0.6.0" +version = "0.7.0" description = "LaunchDarkly SDK for AI" authors = ["LaunchDarkly "] license = "Apache-2.0" @@ -36,7 +36,7 @@ chevron = "=0.14.0" pytest = ">=2.8" pytest-cov = ">=2.4.0" pytest-mypy = "==0.10.3" -mypy = "==1.13.0" +mypy = "==1.14.1" pycodestyle = "^2.12.1" isort = "^5.13.2" @@ -53,7 +53,7 @@ pyrfc3339 = ">=1.0" jsonpickle = ">1.4.1" semver = ">=2.7.9" urllib3 = ">=1.26.0" -jinja2 = "3.1.4" +jinja2 = "3.1.5" [tool.mypy] python_version = "3.8"