| | | 1 | | using Microsoft.Extensions.AI; |
| | | 2 | | |
| | | 3 | | namespace NexusLabs.Needlr.AgentFramework.Evaluation; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Extension methods for opting in to <see cref="EvaluationCaptureChatClient"/> |
| | | 7 | | /// capture/replay behavior. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class EvaluationCaptureChatClientExtensions |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Wraps <paramref name="innerClient"/> with an |
| | | 13 | | /// <see cref="EvaluationCaptureChatClient"/> backed by |
| | | 14 | | /// <paramref name="store"/>. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="innerClient">The chat client to delegate cache-miss calls to.</param> |
| | | 17 | | /// <param name="store">Backing store for captured responses.</param> |
| | | 18 | | /// <returns>A new <see cref="IChatClient"/> that captures and replays responses.</returns> |
| | | 19 | | public static IChatClient WithEvaluationCapture( |
| | | 20 | | this IChatClient innerClient, |
| | | 21 | | IEvaluationCaptureStore store) |
| | | 22 | | { |
| | 3 | 23 | | ArgumentNullException.ThrowIfNull(innerClient); |
| | 2 | 24 | | ArgumentNullException.ThrowIfNull(store); |
| | 1 | 25 | | return new EvaluationCaptureChatClient(innerClient, store); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Wraps <paramref name="innerClient"/> with an |
| | | 30 | | /// <see cref="EvaluationCaptureChatClient"/> backed by a |
| | | 31 | | /// <see cref="FileEvaluationCaptureStore"/> rooted at |
| | | 32 | | /// <paramref name="cacheDirectory"/>. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <param name="innerClient">The chat client to delegate cache-miss calls to.</param> |
| | | 35 | | /// <param name="cacheDirectory">Directory used to persist captured responses.</param> |
| | | 36 | | /// <returns>A new <see cref="IChatClient"/> that captures and replays responses.</returns> |
| | | 37 | | public static IChatClient WithEvaluationCapture( |
| | | 38 | | this IChatClient innerClient, |
| | | 39 | | string cacheDirectory) |
| | | 40 | | { |
| | 5 | 41 | | ArgumentNullException.ThrowIfNull(innerClient); |
| | 4 | 42 | | ArgumentException.ThrowIfNullOrWhiteSpace(cacheDirectory); |
| | 1 | 43 | | return new EvaluationCaptureChatClient( |
| | 1 | 44 | | innerClient, |
| | 1 | 45 | | new FileEvaluationCaptureStore(cacheDirectory)); |
| | | 46 | | } |
| | | 47 | | } |