| | | 1 | | using Intentum.AI.Embeddings; |
| | | 2 | | using Intentum.AI.Mock; |
| | | 3 | | using Intentum.AI.Models; |
| | | 4 | | using Intentum.AI.Similarity; |
| | | 5 | | using Intentum.Core.Behavior; |
| | | 6 | | using Intentum.Runtime.Policy; |
| | | 7 | | |
| | | 8 | | namespace Intentum.Testing; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Test helpers for creating common test objects. |
| | | 12 | | /// </summary> |
| | | 13 | | public static class TestHelpers |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Creates a default LlmIntentModel with MockEmbeddingProvider and SimpleAverageSimilarityEngine. |
| | | 17 | | /// </summary> |
| | | 18 | | public static LlmIntentModel CreateDefaultModel() |
| | 7 | 19 | | { |
| | 7 | 20 | | return new LlmIntentModel( |
| | 7 | 21 | | new MockEmbeddingProvider(), |
| | 7 | 22 | | new SimpleAverageSimilarityEngine()); |
| | 7 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Creates a LlmIntentModel with custom embedding provider and similarity engine. |
| | | 27 | | /// </summary> |
| | | 28 | | public static LlmIntentModel CreateModel( |
| | | 29 | | IIntentEmbeddingProvider embeddingProvider, |
| | | 30 | | IIntentSimilarityEngine similarityEngine) |
| | 1 | 31 | | { |
| | 1 | 32 | | return new LlmIntentModel(embeddingProvider, similarityEngine); |
| | 1 | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Creates a default IntentPolicy with common rules. |
| | | 37 | | /// </summary> |
| | | 38 | | public static IntentPolicy CreateDefaultPolicy() |
| | 5 | 39 | | { |
| | 5 | 40 | | return new IntentPolicyBuilder() |
| | 16 | 41 | | .Block("ExcessiveRetryBlock", i => i.Signals.Count(s => s.Description.Contains("retry", StringComparison.Ord |
| | 5 | 42 | | .Allow("HighConfidenceAllow", i => i.Confidence.Level is "High" or "Certain") |
| | 5 | 43 | | .Observe("MediumConfidenceObserve", i => i.Confidence.Level == "Medium") |
| | 0 | 44 | | .Warn("LowConfidenceWarn", i => i.Confidence.Level == "Low") |
| | 5 | 45 | | .Build(); |
| | 5 | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Creates a BehaviorSpaceBuilder for fluent test setup. |
| | | 50 | | /// </summary> |
| | | 51 | | public static BehaviorSpaceBuilder CreateSpaceBuilder() |
| | 1 | 52 | | { |
| | 1 | 53 | | return new BehaviorSpaceBuilder(); |
| | 1 | 54 | | } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Creates a simple behavior space with login and submit actions. |
| | | 58 | | /// </summary> |
| | | 59 | | public static BehaviorSpace CreateSimpleSpace() |
| | 28 | 60 | | { |
| | 28 | 61 | | return new BehaviorSpaceBuilder() |
| | 28 | 62 | | .WithActor("user") |
| | 28 | 63 | | .Action("login") |
| | 28 | 64 | | .Action("submit") |
| | 28 | 65 | | .Build(); |
| | 28 | 66 | | } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Creates a behavior space with retries. |
| | | 70 | | /// </summary> |
| | | 71 | | public static BehaviorSpace CreateSpaceWithRetries(int retryCount = 2) |
| | 2 | 72 | | { |
| | 2 | 73 | | var builder = new BehaviorSpaceBuilder() |
| | 2 | 74 | | .WithActor("user") |
| | 2 | 75 | | .Action("login"); |
| | | 76 | | |
| | 12 | 77 | | for (int i = 0; i < retryCount; i++) |
| | 4 | 78 | | { |
| | 4 | 79 | | builder.Action("retry"); |
| | 4 | 80 | | } |
| | | 81 | | |
| | 2 | 82 | | return builder |
| | 2 | 83 | | .Action("submit") |
| | 2 | 84 | | .Build(); |
| | 2 | 85 | | } |
| | | 86 | | } |