Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: track TimeToFirstToken in LdAiConfigTracker #67

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
name: Publish Docs
jobs:
build-publish:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: write
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
release-please:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

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

release-sdk-server:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
needs: release-please
permissions:
id-token: write
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

release-sdk-server-ai:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
needs: release-please
permissions:
id-token: write
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

release-telemetry:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
needs: release-please
permissions:
id-token: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-sdk-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:

# Signing DLLs is done on Ubuntu due to Digicert tooling compatibility
sign-dlls:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
needs: build
permissions:
id-token: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sdk-server-ai-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build-and-test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-22.04, windows-latest, macos-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sdk-server-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build-and-test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-22.04, windows-latest, macos-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/telemetry-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build-and-test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-22.04, windows-latest, macos-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
permissions:
Expand Down
6 changes: 6 additions & 0 deletions pkgs/sdk/server-ai/src/Interfaces/ILdAiConfigTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public interface ILdAiConfigTracker
/// <typeparam name="T">type of the task's result</typeparam>
/// <returns>the task</returns>
public Task<T> TrackDurationOfTask<T>(Task<T> task);

/// <summary>
/// Tracks the time it takes for the first token to be generated.
/// </summary>
moribellamy marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="timeToFirstTokenMs">the duration in milliseconds</param>
public void TrackTimeToFirstToken(float timeToFirstTokenMs);

/// <summary>
/// Tracks feedback (positive or negative) related to the output of the model.
Expand Down
5 changes: 5 additions & 0 deletions pkgs/sdk/server-ai/src/LdAiConfigTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class LdAiConfigTracker : ILdAiConfigTracker
private const string TokenTotal = "$ld:ai:tokens:total";
private const string TokenInput = "$ld:ai:tokens:input";
private const string TokenOutput = "$ld:ai:tokens:output";
private const string TimeToFirstToken = "$ld:ai:tokens:ttf";

/// <summary>
/// Constructs a new AI configuration tracker. The tracker is associated with a configuration,
Expand Down Expand Up @@ -69,6 +70,10 @@ public async Task<T> TrackDurationOfTask<T>(Task<T> task)
TrackDuration(sw.ElapsedMilliseconds);
}
}

/// <inheritdoc/>
public void TrackTimeToFirstToken(float timeToFirstTokenMs) =>
_client.Track(TimeToFirstToken, _context, _trackData, timeToFirstTokenMs);

/// <inheritdoc/>
public void TrackFeedback(Feedback feedback)
Expand Down
17 changes: 17 additions & 0 deletions pkgs/sdk/server-ai/test/LdAiConfigTrackerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ public void CanTrackDuration()
mockClient.Verify(x => x.Track("$ld:ai:duration:total", context, data, 1.0f), Times.Once);
}

[Fact]
public void CanTrackTimeToFirstToken()
{
var mockClient = new Mock<ILaunchDarklyClient>();
var context = Context.New("key");
const string flagKey = "key";
var config = LdAiConfig.Disabled;
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
{
{ "variationKey", LdValue.Of(config.VariationKey) },
{ "configKey", LdValue.Of(flagKey) }
});
var tracker = new LdAiConfigTracker(mockClient.Object, flagKey, config, context);

tracker.TrackTimeToFirstToken(1.0f);
mockClient.Verify(x => x.Track("$ld:ai:tokens:ttf", context, data, 1.0f), Times.Once);
}

[Fact]
public void CanTrackSuccess()
Expand Down
Loading