Skip to content

Conversation

shyamnamboodiripad
Copy link
Contributor

@shyamnamboodiripad shyamnamboodiripad commented Apr 10, 2025

Introduce an IChatClient for Safety evaluators so that we can support response caching in the same way as we do for other LLM-based evaluators.

Also includes some changes to introduce a GetContents API on the EvaluationContext type. This aids with some of changes in this PR and should also help for #6033 in a subsequent PR.

Here's a screenshot that shows how this improves the run time of SafetyEvaluatorTests when cached responses are available.

image

TODO:

  • Include additional caching keys based on the service connection parameters so that the cache can be invalidated if something changes.

Fixes #6260

Microsoft Reviewers: Open in CodeFlow

@shyamnamboodiripad shyamnamboodiripad requested a review from a team as a code owner April 10, 2025 08:27
@github-actions github-actions bot added the area-ai-eval Microsoft.Extensions.AI.Evaluation and related label Apr 10, 2025
Copy link
Member

@peterwald peterwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Same instance of ContentSafetyService can now be used for any annotationTask and evaluator that use the same ContentSafetyServiceConfiguration.
…of messages

The evaluated model response, is now concatenated to the messages in the history.
And introduce a function on EvaluationContext to decompose its contents into constituent its AIContents.
Introduce an IChatClient for Safety evaluators to enable response caching.
Even though service urls do not include the annotation task, we only cache service urls after we check that the supplied annotation task is available in the service instance. Not considering the annotation task when caching service urls meant that if the first annotation task that we checked for happened to be available, we would skip availablity checks for all other annotations requested on the same service instance. However, not all annotations may be available on a give service instance (depending on region). Hence, we update the url caching code to also consider the annotation task.
We also embed the service configuration parameters into the provider name to ensure that the cached responses will no longer be used if the parameters change.
@shyamnamboodiripad shyamnamboodiripad merged commit 19f9c6c into dotnet:main Apr 11, 2025
6 checks passed
@shyamnamboodiripad shyamnamboodiripad deleted the caching branch April 11, 2025 03:57
@github-actions github-actions bot locked and limited conversation to collaborators May 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-ai-eval Microsoft.Extensions.AI.Evaluation and related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AI Evaluation] Support response caching for safety evaluators
2 participants