Skip to content

Commit 875dba5

Browse files
moribellamykeelerm84tanderson-ld
authored
feat: track TimeToFirstToken in LdAiConfigTracker (#67)
Co-authored-by: Matthew M. Keeler <[email protected]> Co-authored-by: Todd Anderson <[email protected]>
1 parent 455e27d commit 875dba5

File tree

10 files changed

+38
-10
lines changed

10 files changed

+38
-10
lines changed

.github/workflows/publish-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
name: Publish Docs
1515
jobs:
1616
build-publish:
17-
runs-on: ubuntu-latest
17+
runs-on: ubuntu-22.04
1818
permissions:
1919
id-token: write
2020
contents: write

.github/workflows/release-please.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
release-please:
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-22.04
1111

1212
outputs:
1313
package-sdk-server-released: ${{ steps.release.outputs['pkgs/sdk/server--release_created'] }}
@@ -28,7 +28,7 @@ jobs:
2828
target-branch: ${{ github.ref_name }}
2929

3030
release-sdk-server:
31-
runs-on: ubuntu-latest
31+
runs-on: ubuntu-22.04
3232
needs: release-please
3333
permissions:
3434
id-token: write
@@ -57,7 +57,7 @@ jobs:
5757
token: ${{ secrets.GITHUB_TOKEN }}
5858

5959
release-sdk-server-ai:
60-
runs-on: ubuntu-latest
60+
runs-on: ubuntu-22.04
6161
needs: release-please
6262
permissions:
6363
id-token: write
@@ -86,7 +86,7 @@ jobs:
8686
token: ${{ secrets.GITHUB_TOKEN }}
8787

8888
release-telemetry:
89-
runs-on: ubuntu-latest
89+
runs-on: ubuntu-22.04
9090
needs: release-please
9191
permissions:
9292
id-token: write

.github/workflows/release-sdk-client.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373

7474
# Signing DLLs is done on Ubuntu due to Digicert tooling compatibility
7575
sign-dlls:
76-
runs-on: ubuntu-latest
76+
runs-on: ubuntu-22.04
7777
needs: build
7878
permissions:
7979
id-token: write

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ on:
2525

2626
jobs:
2727
build:
28-
runs-on: ubuntu-latest
28+
runs-on: ubuntu-22.04
2929
permissions:
3030
id-token: write
3131
contents: write

.github/workflows/sdk-server-ai-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
build-and-test:
1414
strategy:
1515
matrix:
16-
os: [ubuntu-latest, windows-latest, macos-latest]
16+
os: [ubuntu-22.04, windows-latest, macos-latest]
1717
fail-fast: false
1818
runs-on: ${{ matrix.os }}
1919
permissions:

.github/workflows/sdk-server-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
build-and-test:
1414
strategy:
1515
matrix:
16-
os: [ubuntu-latest, windows-latest, macos-latest]
16+
os: [ubuntu-22.04, windows-latest, macos-latest]
1717
fail-fast: false
1818
runs-on: ${{ matrix.os }}
1919
permissions:

.github/workflows/telemetry-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
build-and-test:
1414
strategy:
1515
matrix:
16-
os: [ubuntu-latest, windows-latest, macos-latest]
16+
os: [ubuntu-22.04, windows-latest, macos-latest]
1717
fail-fast: false
1818
runs-on: ${{ matrix.os }}
1919
permissions:

pkgs/sdk/server-ai/src/Interfaces/ILdAiConfigTracker.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public interface ILdAiConfigTracker
3636
/// <typeparam name="T">type of the task's result</typeparam>
3737
/// <returns>the task</returns>
3838
public Task<T> TrackDurationOfTask<T>(Task<T> task);
39+
40+
/// <summary>
41+
/// Tracks the time it takes for the first token to be generated.
42+
/// </summary>
43+
/// <param name="timeToFirstTokenMs">the duration in milliseconds</param>
44+
public void TrackTimeToFirstToken(float timeToFirstTokenMs);
3945

4046
/// <summary>
4147
/// Tracks feedback (positive or negative) related to the output of the model.

pkgs/sdk/server-ai/src/LdAiConfigTracker.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class LdAiConfigTracker : ILdAiConfigTracker
2727
private const string TokenTotal = "$ld:ai:tokens:total";
2828
private const string TokenInput = "$ld:ai:tokens:input";
2929
private const string TokenOutput = "$ld:ai:tokens:output";
30+
private const string TimeToFirstToken = "$ld:ai:tokens:ttf";
3031

3132
/// <summary>
3233
/// Constructs a new AI configuration tracker. The tracker is associated with a configuration,
@@ -69,6 +70,10 @@ public async Task<T> TrackDurationOfTask<T>(Task<T> task)
6970
TrackDuration(sw.ElapsedMilliseconds);
7071
}
7172
}
73+
74+
/// <inheritdoc/>
75+
public void TrackTimeToFirstToken(float timeToFirstTokenMs) =>
76+
_client.Track(TimeToFirstToken, _context, _trackData, timeToFirstTokenMs);
7277

7378
/// <inheritdoc/>
7479
public void TrackFeedback(Feedback feedback)

pkgs/sdk/server-ai/test/LdAiConfigTrackerTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ public void CanTrackDuration()
5151
mockClient.Verify(x => x.Track("$ld:ai:duration:total", context, data, 1.0f), Times.Once);
5252
}
5353

54+
[Fact]
55+
public void CanTrackTimeToFirstToken()
56+
{
57+
var mockClient = new Mock<ILaunchDarklyClient>();
58+
var context = Context.New("key");
59+
const string flagKey = "key";
60+
var config = LdAiConfig.Disabled;
61+
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
62+
{
63+
{ "variationKey", LdValue.Of(config.VariationKey) },
64+
{ "configKey", LdValue.Of(flagKey) }
65+
});
66+
var tracker = new LdAiConfigTracker(mockClient.Object, flagKey, config, context);
67+
68+
tracker.TrackTimeToFirstToken(1.0f);
69+
mockClient.Verify(x => x.Track("$ld:ai:tokens:ttf", context, data, 1.0f), Times.Once);
70+
}
5471

5572
[Fact]
5673
public void CanTrackSuccess()

0 commit comments

Comments
 (0)