Skip to content

Commit 18ae3ba

Browse files
authored
Add convertion goal (#352)
1 parent 6da439b commit 18ae3ba

File tree

55 files changed

+1746
-175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1746
-175
lines changed

src/Abstractions/CrestApps.OrchardCore.AI.Abstractions/Models/AIChatSessionEvent.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ public sealed class AIChatSessionEvent : Entity
8383
/// </summary>
8484
public bool? UserRating { get; set; }
8585

86+
/// <summary>
87+
/// Gets or sets the aggregate conversion score across all goals.
88+
/// Null if conversion metrics are not enabled.
89+
/// </summary>
90+
public int? ConversionScore { get; set; }
91+
92+
/// <summary>
93+
/// Gets or sets the maximum possible conversion score across all goals.
94+
/// Null if conversion metrics are not enabled.
95+
/// </summary>
96+
public int? ConversionMaxScore { get; set; }
97+
98+
/// <summary>
99+
/// Gets or sets the individual goal results from AI evaluation.
100+
/// </summary>
101+
public List<ConversionGoalResult> ConversionGoalResults { get; set; } = [];
102+
86103
/// <summary>
87104
/// Gets or sets the UTC timestamp when this event record was created.
88105
/// </summary>

src/Abstractions/CrestApps.OrchardCore.AI.Abstractions/Models/AIProfilePostSessionSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ public class AIProfilePostSessionSettings
1616
/// Gets or sets the list of post-session processing tasks to execute when a session closes.
1717
/// </summary>
1818
public List<PostSessionTask> PostSessionTasks { get; set; } = [];
19+
20+
/// <summary>
21+
/// Gets or sets the tool names to make available during post-session processing.
22+
/// When tools are configured, the AI model can invoke them during post-session analysis.
23+
/// </summary>
24+
public string[] ToolNames { get; set; } = [];
1925
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace CrestApps.OrchardCore.AI.Models;
2+
3+
/// <summary>
4+
/// Defines a single conversion goal used to measure chat session success.
5+
/// Each goal is evaluated by AI after session close and scored within the configured range.
6+
/// </summary>
7+
public sealed class ConversionGoal
8+
{
9+
/// <summary>
10+
/// Gets or sets the unique name for this goal.
11+
/// Must be alphanumeric with underscores only.
12+
/// </summary>
13+
public string Name { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets a human-readable description of what constitutes success for this goal.
17+
/// This is provided to the AI model as evaluation criteria.
18+
/// </summary>
19+
public string Description { get; set; }
20+
21+
/// <summary>
22+
/// Gets or sets the minimum score for this goal. Defaults to 0.
23+
/// </summary>
24+
public int MinScore { get; set; }
25+
26+
/// <summary>
27+
/// Gets or sets the maximum score for this goal. Defaults to 10.
28+
/// </summary>
29+
public int MaxScore { get; set; } = 10;
30+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace CrestApps.OrchardCore.AI.Models;
2+
3+
/// <summary>
4+
/// Stores the AI-evaluated result for a single conversion goal.
5+
/// </summary>
6+
public sealed class ConversionGoalResult
7+
{
8+
/// <summary>
9+
/// Gets or sets the name of the goal that was evaluated.
10+
/// </summary>
11+
public string Name { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets the AI-assigned score for this goal.
15+
/// </summary>
16+
public int Score { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets the maximum possible score for this goal.
20+
/// </summary>
21+
public int MaxScore { get; set; }
22+
23+
/// <summary>
24+
/// Gets or sets an optional AI-generated explanation for the assigned score.
25+
/// </summary>
26+
public string Reasoning { get; set; }
27+
}

src/Core/CrestApps.OrchardCore.AI.Core/AITemplateIds.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public static class AITemplateIds
1313

1414
public const string PostSessionAnalysis = "post-session-analysis";
1515

16+
public const string ResolutionAnalysis = "resolution-analysis";
17+
18+
public const string ConversionGoalEvaluation = "conversion-goal-evaluation";
19+
1620
public const string DataExtraction = "data-extraction";
1721

1822
public const string UseMarkdownSyntax = "use-markdown-syntax";

src/Core/CrestApps.OrchardCore.AI.Core/Handlers/DocumentOrchestrationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Task BuildingAsync(OrchestrationContextBuildingContext context)
3939
}
4040
else if (context.Resource is AIProfile profile)
4141
{
42-
var documentsMetadata = profile.As<AIProfileDocumentsMetadata>();
42+
var documentsMetadata = profile.As<DocumentsMetadata>();
4343

4444
if (documentsMetadata.Documents is { Count: > 0 })
4545
{

src/Core/CrestApps.OrchardCore.AI.Core/Indexes/AIChatSessionMetricsIndex.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,15 @@ public sealed class AIChatSessionMetricsIndex : MapIndex
4242

4343
public bool? UserRating { get; set; }
4444

45+
/// <summary>
46+
/// The aggregate conversion score across all evaluated goals. Null if not evaluated.
47+
/// </summary>
48+
public int? ConversionScore { get; set; }
49+
50+
/// <summary>
51+
/// The maximum possible conversion score. Null if not evaluated.
52+
/// </summary>
53+
public int? ConversionMaxScore { get; set; }
54+
4555
public DateTime CreatedUtc { get; set; }
4656
}

src/Core/CrestApps.OrchardCore.AI.Core/Models/AIProfileAnalyticsMetadata.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace CrestApps.OrchardCore.AI.Models;
2+
3+
/// <summary>
4+
/// Metadata stored on <see cref="AIProfile.Properties"/> to control
5+
/// whether session metrics are captured for analytics purposes.
6+
/// </summary>
7+
public sealed class AnalyticsMetadata
8+
{
9+
/// <summary>
10+
/// Gets or sets whether session metrics (usage, latency, feedback)
11+
/// are captured for chat sessions using this profile.
12+
/// </summary>
13+
public bool EnableSessionMetrics { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets whether AI-based resolution detection is enabled.
17+
/// When enabled, the system uses AI to semantically determine whether
18+
/// a conversation was resolved, instead of relying solely on timeout-based abandonment.
19+
/// Defaults to <see langword="true"/> when session metrics are enabled.
20+
/// </summary>
21+
public bool EnableAIResolutionDetection { get; set; } = true;
22+
23+
/// <summary>
24+
/// Gets or sets whether conversion metrics are enabled for this profile.
25+
/// When enabled, the system uses AI to evaluate each session against configured goals
26+
/// and assigns scores to measure session success.
27+
/// </summary>
28+
public bool EnableConversionMetrics { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the list of conversion goals to evaluate for each session.
32+
/// Each goal is scored by AI after the session closes.
33+
/// </summary>
34+
public List<ConversionGoal> ConversionGoals { get; set; } = [];
35+
}

src/Core/CrestApps.OrchardCore.AI.Core/Models/AIProfileDocumentsMetadata.cs renamed to src/Core/CrestApps.OrchardCore.AI.Core/Models/DocumentsMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace CrestApps.OrchardCore.AI.Models;
44
/// Metadata stored on <see cref="AIProfile.Properties"/> to track
55
/// documents attached to the profile for RAG functionality.
66
/// </summary>
7-
public sealed class AIProfileDocumentsMetadata
7+
public sealed class DocumentsMetadata
88
{
99
/// <summary>
1010
/// Gets or sets the collection of attached document metadata.

0 commit comments

Comments
 (0)