Skip to content

Commit

Permalink
Standardize on eventy type concept
Browse files Browse the repository at this point in the history
  • Loading branch information
ciprianjichici committed Dec 23, 2024
1 parent 93fecc5 commit 275410b
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class AIModelResourceProviderService(
serviceProvider,
loggerFactory.CreateLogger<AIModelResourceProviderService>(),
[
EventTypes.FoundationaLLM_ResourceProvider_AIModel
EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand
],
useInternalReferencesStore: true)
{
Expand Down Expand Up @@ -199,7 +199,7 @@ protected override async Task HandleEvents(EventTypeEventArgs e)

switch (e.EventType)
{
case EventTypes.FoundationaLLM_ResourceProvider_AIModel:
case EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand:
foreach (var @event in e.Events)
await HandleAIModelResourceProviderEvent(@event);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public class AgentResourceProviderService(
resourceValidatorFactory,
serviceProvider,
loggerFactory.CreateLogger<AgentResourceProviderService>(),
eventNamespacesToSubscribe: [
EventTypes.FoundationaLLM_ResourceProvider_Agent
eventTypesToSubscribe: [
EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand
],
useInternalReferencesStore: true)
{
Expand Down Expand Up @@ -197,7 +197,7 @@ protected override async Task HandleEvents(EventTypeEventArgs e)

switch (e.EventType)
{
case EventTypes.FoundationaLLM_ResourceProvider_Agent:
case EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand:
foreach (var @event in e.Events)
await HandleAgentResourceProviderEvent(@event);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class AttachmentResourceProviderService(
serviceProvider,
loggerFactory.CreateLogger<AttachmentResourceProviderService>(),
[
EventTypes.FoundationaLLM_ResourceProvider_Attachment
EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand
],
useInternalReferencesStore: false)
{
Expand Down Expand Up @@ -241,7 +241,7 @@ protected override async Task HandleEvents(EventTypeEventArgs e)

switch (e.EventType)
{
case EventTypes.FoundationaLLM_ResourceProvider_Attachment:
case EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand:
foreach (var @event in e.Events)
await HandleAttachmentResourceProviderEvent(@event);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class AzureOpenAIResourceProviderService(
resourceValidatorFactory,
serviceProvider,
logger,
eventNamespacesToSubscribe: null,
eventTypesToSubscribe: null,
useInternalReferencesStore: false)
{
private readonly IAzureCosmosDBService _cosmosDBService = cosmosDBService;
Expand Down
48 changes: 6 additions & 42 deletions src/dotnet/Common/Constants/Events/EventTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,22 @@
public static class EventTypes
{
/// <summary>
/// The event type for FoundationaLLM.Agent events.
/// The resource provider cache reset command event type.
/// </summary>
public const string FoundationaLLM_ResourceProvider_Agent = "ResourceProvider.FoundationaLLM.Agent";
public const string FoundationaLLM_ResourceProvider_Cache_ResetCommand = "FoundationaLLM.ResourceProvider.Cache.ResetCommand";

/// <summary>
/// The event type for FoundationaLLM.Vectorization events.
/// The resource provider cache reset command confirmation event type.
/// </summary>
public const string FoundationaLLM_ResourceProvider_Vectorization = "ResourceProvider.FoundationaLLM.Vectorization";

/// <summary>
/// The event type for FoundationaLLM.Configuration events.
/// </summary>
public const string FoundationaLLM_ResourceProvider_Configuration = "ResourceProvider.FoundationaLLM.Configuration";

/// <summary>
/// The event type for FoundationaLLM.DataSource events.
/// </summary>
public const string FoundationaLLM_ResourceProvider_DataSource = "ResourceProvider.FoundationaLLM.DataSource";

/// <summary>
/// The event type for FoundationaLLM.Attachment events.
/// </summary>
public const string FoundationaLLM_ResourceProvider_Attachment = "ResourceProvider.FoundationaLLM.Attachment";

/// <summary>
/// The event type for FoundationaLLM.AIModel events.
/// </summary>
public const string FoundationaLLM_ResourceProvider_AIModel = "ResourceProvider.FoundationaLLM.AIModel";

/// <summary>
/// The event type for FoundationaLLM.AzureOpenAI events.
/// </summary>
public const string FoundationaLLM_ResourceProvider_AzureOpenAI = "ResourceProvider.FoundationaLLM.AzureOpenAI";

/// <summary>
/// The event type for FoundationaLLM.Conversation events.
/// </summary>
public const string FoundationaLLM_ResourceProvider_Conversation = "ResourceProvider.FoundationaLLM.Conversation";
public const string FoundationaLLM_ResourceProvider_Cache_ResetCommandConfirmation = "FoundationaLLM.ResourceProvider.Cache.ResetCommandConfirmation";

/// <summary>
/// All event types.
/// </summary>
public static List<string> All =>
[
FoundationaLLM_ResourceProvider_Agent,
FoundationaLLM_ResourceProvider_Vectorization,
FoundationaLLM_ResourceProvider_Configuration,
FoundationaLLM_ResourceProvider_DataSource,
FoundationaLLM_ResourceProvider_Attachment,
FoundationaLLM_ResourceProvider_AIModel,
FoundationaLLM_ResourceProvider_AzureOpenAI,
FoundationaLLM_ResourceProvider_Conversation
FoundationaLLM_ResourceProvider_Cache_ResetCommand,
FoundationaLLM_ResourceProvider_Cache_ResetCommandConfirmation
];
}
}
10 changes: 5 additions & 5 deletions src/dotnet/Common/Services/Events/LocalEventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public class LocalEventService(
private readonly ConcurrentQueue<EventTypeEventArgs> _eventsQueue = [];

/// <summary>
/// Subscribes this instance to a specified list of event namespaces supported by the <see cref="IEventService"/>.
/// Subscribes this instance to a specified list of event types supported by the <see cref="IEventService"/>.
/// </summary>
/// <param name="eventNamespaces">The list with the namespace to subscribe to.</param>
public void SubscribeToEventNamespaces(List<string> eventNamespaces)
/// <param name="eventTypes">The list with the event types to subscribe to.</param>
public void SubscribeToEventTypes(List<string> eventTypes)
{
foreach (var eventNamespace in eventNamespaces)
foreach (var eventType in eventTypes)
{
_eventService.SubscribeToEventTypeEvent(
eventNamespace,
eventType,
IngestEvents);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ResourceProviderServiceBase<TResourceReference> : IResourceProvider
private bool _isInitialized = false;

private LocalEventService? _localEventService;
private readonly List<string>? _eventNamespacesToSubscribe;
private readonly List<string>? _eventTypesToSubscribe;
private readonly ImmutableList<string> _allowedResourceProviders;
private readonly Dictionary<string, ResourceTypeDescriptor> _allowedResourceTypes;
private readonly Dictionary<string, IResourceProviderService> _resourceProviders = [];
Expand Down Expand Up @@ -123,7 +123,7 @@ public class ResourceProviderServiceBase<TResourceReference> : IResourceProvider
/// <param name="resourceValidatorFactory">The <see cref="IResourceValidatorFactory"/> providing services to instantiate resource validators.</param>
/// <param name="logger">The logger used for logging.</param>
/// <param name="serviceProvider">The <see cref="IServiceProvider"/> of the main dependency injection container.</param>
/// <param name="eventNamespacesToSubscribe">The list of Event Service event namespaces to subscribe to for local event processing.</param>
/// <param name="eventTypesToSubscribe">The list of Event Service event namespaces to subscribe to for local event processing.</param>
/// <param name="useInternalReferencesStore">Indicates whether the resource provider should use the internal resource references store or provide one of its own.</param>
public ResourceProviderServiceBase(
InstanceSettings instanceSettings,
Expand All @@ -133,7 +133,7 @@ public ResourceProviderServiceBase(
IResourceValidatorFactory resourceValidatorFactory,
IServiceProvider serviceProvider,
ILogger logger,
List<string>? eventNamespacesToSubscribe = default,
List<string>? eventTypesToSubscribe = default,
bool useInternalReferencesStore = false)
{
_authorizationServiceClient = authorizationServiceClient;
Expand All @@ -143,7 +143,7 @@ public ResourceProviderServiceBase(
_logger = logger;
_serviceProvider = serviceProvider;
_instanceSettings = instanceSettings;
_eventNamespacesToSubscribe = eventNamespacesToSubscribe;
_eventTypesToSubscribe = eventTypesToSubscribe;
_useInternalReferencesStore = useInternalReferencesStore;

if (_instanceSettings.EnableResourceProvidersCache)
Expand Down Expand Up @@ -179,14 +179,14 @@ public async Task Initialize()

await InitializeInternal();

if (_eventNamespacesToSubscribe != null
&& _eventNamespacesToSubscribe.Count > 0)
if (_eventTypesToSubscribe != null
&& _eventTypesToSubscribe.Count > 0)
{
_localEventService = new LocalEventService(
new LocalEventServiceSettings { EventProcessingCycleSeconds = 10 },
_eventService,
_logger);
_localEventService.SubscribeToEventNamespaces(_eventNamespacesToSubscribe);
_localEventService.SubscribeToEventTypes(_eventTypesToSubscribe);
_localEventService.StartLocalEventProcessing(HandleEvents);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ConfigurationResourceProviderService(
serviceProvider,
logger,
[
EventTypes.FoundationaLLM_ResourceProvider_Configuration
EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand
],
useInternalReferencesStore: true)
{
Expand Down Expand Up @@ -169,7 +169,7 @@ protected override async Task HandleEvents(EventTypeEventArgs e)

switch (e.EventType)
{
case EventTypes.FoundationaLLM_ResourceProvider_Configuration:
case EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand:
foreach (var @event in e.Events)
await HandleConfigurationResourceProviderEvent(@event);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ConversationResourceProviderService(
resourceValidatorFactory,
serviceProvider,
logger,
eventNamespacesToSubscribe: null,
eventTypesToSubscribe: null,
useInternalReferencesStore: false)
{
private readonly IAzureCosmosDBService _cosmosDBService = cosmosDBService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class DataSourceResourceProviderService(
serviceProvider,
loggerFactory.CreateLogger<DataSourceResourceProviderService>(),
[
EventTypes.FoundationaLLM_ResourceProvider_DataSource
EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand
],
useInternalReferencesStore: true)
{
Expand Down Expand Up @@ -172,7 +172,7 @@ protected override async Task HandleEvents(EventTypeEventArgs e)

switch (e.EventType)
{
case EventTypes.FoundationaLLM_ResourceProvider_DataSource:
case EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand:
foreach (var @event in e.Events)
await HandleDataSourceResourceProviderEvent(@event);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FoundationaLLM.Common.Constants.Configuration;
using FoundationaLLM.Common.Constants.Events;
using FoundationaLLM.Common.Constants.ResourceProviders;
using FoundationaLLM.Common.Exceptions;
using FoundationaLLM.Common.Interfaces;
Expand All @@ -13,6 +14,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Graph.Models;
using System.Collections.Concurrent;
using System.Text;
using System.Text.Json;
Expand Down Expand Up @@ -45,7 +47,9 @@ public class PromptResourceProviderService(
resourceValidatorFactory,
serviceProvider,
logger,
[],
[
EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand
],
useInternalReferencesStore: true)
{
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class VectorizationResourceProviderService(
serviceProvider,
loggerFactory.CreateLogger<VectorizationResourceProviderService>(),
[
EventTypes.FoundationaLLM_ResourceProvider_Vectorization
EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand
])
{
/// <inheritdoc/>
Expand Down Expand Up @@ -872,7 +872,7 @@ protected override async Task HandleEvents(EventTypeEventArgs e)

switch (e.EventType)
{
case EventTypes.FoundationaLLM_ResourceProvider_Vectorization:
case EventTypes.FoundationaLLM_ResourceProvider_Cache_ResetCommand:
foreach (var @event in e.Events)
await HandleVectorizationResourceProviderEvent(@event);
break;
Expand Down

0 comments on commit 275410b

Please sign in to comment.